The Big Programming Thread - Page 812
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
Acrofales
Spain17833 Posts
| ||
Yurie
11680 Posts
On December 07 2016 23:41 Acrofales wrote: Oh wait. When copying to run my own tests, I just saw that in your main method, pb is not a phonebook, it is a TreeMap<String, String>. That is, of course, only going to have <a, 3> in there after your 3 puts... Right you are. I made a big mistake there. :/ On December 07 2016 23:40 Blitzkrieg0 wrote: Sets are the smarter way to do it. A Set is just a List that can't have duplicate values. Having a duplicate phone number does not make sense. I was under the impression that you had to use a List for the assignment, but if you can choose then do use a Set instead of an ArrayList. Seems to work in a short test code. Thanks for the idea. Now to get the actual thing to work, easier when I get the logic. ![]() public class Testphoneb { Output is now correct in the short test code on how it works:
| ||
Yurie
11680 Posts
Referring to findNumbers that is a bit longer than it needs to be since I've been tinkering with it to try to solve it. public Set<String> findNumbers(String name) { phoneBook is already set as private, which I thought might be the problem even though it shouldn't be.
| ||
Nesserev
Belgium2760 Posts
| ||
3FFA
United States3931 Posts
With this in mind, I'd love to know of what resources you guys might recommend for learning C# and Unity, specifically focusing on game programming, not the art at all. So far I'm going to be using Unity's own free tutorials and this book on C#. http://www.introprogramming.info/wp-content/uploads/2013/07/Books/CSharpEn/Fundamentals-of-Computer-Programming-with-CSharp-Nakov-eBook-v2013.pdf | ||
Acrofales
Spain17833 Posts
On December 08 2016 00:39 Yurie wrote: Got stuck on one last test case of the 26 groups of them and I can't see why it acts that way. Could somebody explain the logic so I can solve the problem? (It is still Java.) Fill() adds 1,2,3 to a, so three values in size. The numbers.add("4"); somehow adds to the main phonebook as well and I don't understand why.
Referring to findNumbers that is a bit longer than it needs to be since I've been tinkering with it to try to solve it. public Set<String> findNumbers(String name) { phoneBook is already set as private, which I thought might be the problem even though it shouldn't be.
This. But to make your life easier, you can use a copy constructor. | ||
BluzMan
Russian Federation4235 Posts
| ||
Acrofales
Spain17833 Posts
That said, I am pretty terrible at documenting my code and am off the belief that a method should do 1 thing and be named appropriately. If it does lots of other stuff it means that either the other stuff is necessary to do it's main purpose and otherwise unimportant (and only needs to be done if doing the method's stuff), or it was written by an idiot (that idiot may y have been me 2 weeks ago). I only document when something will need to be fiddled with and is rather complicated and/or non-obvious. Other than that I use comments like post-its: todos, ideas for cleaning up, or refactoring, etc. | ||
spinesheath
Germany8679 Posts
On December 08 2016 04:07 BluzMan wrote: Quick question to those already in the industry: do you really (the truth now!) write comments in your code? All the open source libraries have these docstrings and fancy annotations, but does your actual production code not meant for public eyes have any? It is fairly easy to enforce comments in a good IDE. Plus code reviews. Comments are important. You have a team you work with, and you have to understand your own code 6 months from now. Be careful though: pointless comments are bad, and overly verbose comments are bad too. Try to stick with the stuff that actually adds information. | ||
![]()
tofucake
Hyrule18968 Posts
On December 08 2016 04:07 BluzMan wrote: Quick question to those already in the industry: do you really (the truth now!) write comments in your code? All the open source libraries have these docstrings and fancy annotations, but does your actual production code not meant for public eyes have any? all the time. a few examples I've personally written: try {
$rule = $this->getRepository('SharedBundle:ProgramRule')->findActiveRule($dates, $program, $group->getId()); edit: one that was extremely confusing if (!is_array($contract->_contract_participant_fees)) { | ||
RoomOfMush
1296 Posts
On December 08 2016 04:07 BluzMan wrote: Quick question to those already in the industry: do you really (the truth now!) write comments in your code? All the open source libraries have these docstrings and fancy annotations, but does your actual production code not meant for public eyes have any? Most code is simple boilerplate code. If the method and variable names are well chosen and descriptive, and the code itself is straight forward and simple, I dont commentate. Once I use more complicated algorithms to calculate something, or when the code has a strange structure, I write comments explaining what is happening. Whenever I catch myself doubting code I had written (having to think it over or test it out once more) I comment it just in case I might ever get into this situation again where I am not quite sure what that particular part does. For example when I am more "clever" then usual and come up with some funny data structure at 3 in the morning. | ||
![]()
tofucake
Hyrule18968 Posts
//$data contains all the changes to the row. | ||
spinesheath
Germany8679 Posts
Still, always consider how hard a piece of code will be to understand for your colleague or you in 6 months. Heck, consider it for yourself, 6 months ago (or whatever time you were significantly less skilled). If someone might think a minute about, spend those 10 seconds and write a comment (after you verified that the code is already as clear as you can reasonably write it). | ||
mantequilla
Turkey775 Posts
On December 08 2016 05:02 tofucake wrote: oh and one I didn't write but is all over because the people we outsourced the project to in the beginning suck: //$data contains all the changes to the row. validation is one of the most problematic topics in writing good code imo. Add multilingual support in error messages plus different clients and it gets huge. | ||
![]()
tofucake
Hyrule18968 Posts
| ||
BluzMan
Russian Federation4235 Posts
Whenever I read code, everything is structured, all the tokens are color-coded and it takes me but a small glance to understand what's going on. Furthermore, should something get changed, I've got a massive type system behind my back to halt my compiler if anything is forgotten. Comments are nothing like that. In an IDE, they are a structure-less gray blob that doesn't have any compile-time guarantees to even make sense, let alone tell the truth and be useful. And they make simple code look complicated because they pollute so much space. Just look at this! This wall of text takes up so much visual space it's actually hard to see that this function just returns true for all input. On December 08 2016 05:47 mantequilla wrote: validation is one of the most problematic topics in writing good code imo. Add multilingual support in error messages plus different clients and it gets huge. Plus, I've yet to see good auto-generated documentation. I guess C++ kinda skews my vision since I have the luxury of figuring out all the types just from reading the headers (python people must be pretty upset - documentation is needed to know what types functions expect), but all the good documentation I've read was obviously handwritten and went way beyond what typically comes out of a javadoc-like system. | ||
Blitzkrieg0
United States13132 Posts
On December 08 2016 06:26 BluzMan wrote: And they make simple code look complicated because they pollute so much space. Just look at this! This wall of text takes up so much visual space it's actually hard to see that this function just returns true for all input. To me the comment makes it clear that it is a bug and needs to be changed. Anytime you do something that looks stupid it should be commented anyway like a validation always returning true. There should be an explanation for why that is needed if it was intentional. It's nice to have a high level design of what you're working on including why and who made certain decisions so people can have a discussion beyond this is how it currently works. | ||
Chocolate
United States2350 Posts
But like what do you do in a day? How much coding (both in terms of time and amount of code written, not lines but functionality) actually gets done? This past summer I was more of a glorified sysadmin (and it was in a research setting too...) than anything so I didn't really get to write very much. | ||
![]()
tofucake
Hyrule18968 Posts
| ||
spinesheath
Germany8679 Posts
Looking at it from the the other side: I have a 15 minute standup a day, I guess 30-60 minutes of scheduled meetings (some of these with customers) per day on average. And then maybe 1-2 hours of discussing stuff with colleages? Rough estimate. So I guess I'm at about 5 hours of coding (including necessary "research") too. Though this can range from 7.5 hours to less than an hour each single day. | ||
| ||