Slashdot Mirror


Ask Slashdot: What Makes Some Code Particularly Good?

itwbennett writes: When developers talk about what makes some source code particularly 'good,' a handful of qualities tend to get mentioned frequently (functional, readable, testable). What would you add to this list?

174 of 298 comments (clear)

  1. Obviously by Anonymous Coward · · Score: 5, Funny

    When it's mine.

    1. Re:Obviously by Anonymous Coward · · Score: 2, Insightful

      What makes an article a click whoring waste of time? I don't know, I didn't read past the first for 9 impression generating lazily written dreck, but being posted on slashdot is becoming a good indication.

    2. Re:Obviously by Anonymous+Brave+Guy · · Score: 4, Funny

      Tell that to your six-months-ago self, who wrote the mess you've been debugging all week. :-)

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    3. Re:Obviously by nitehawk214 · · Score: 4, Funny

      I hate it when I have to debug some other asshole's code.

      I hate it more when the asshole is six-months-ago-me.

      --
      I'm a good cook. I'm a fantastic eater. - Steven Brust
    4. Re:Obviously by plopez · · Score: 2

      When it's mine and I am the only one who understands it and so therefore have a cash cow until retirement :)

      --
      putting the 'B' in LGBTQ+
    5. Re:Obviously by stjobe · · Score: 4, Insightful

      I am all over the place, I guess many programmers are.

      Being a programmer is a trade in some parts, and you can get by with good craftsmanship.
      In other parts it's a creative art, and you can't force creativity.

      To write really good code, you need to both have the craftsmanship and the creativity.

      --
      "Total destruction the only solution" - Bob Marley
    6. Re:Obviously by TeknoHog · · Score: 1

      Man, that's a big-ass hole.

      --
      Escher was the first MC and Giger invented the HR department.
    7. Re: Obviously by johnsnails · · Score: 1
    8. Re:Obviously by Jane+Q.+Public · · Score: 2

      There *IS* one problem here: efficiency is the last item, while "simple" and "pleasant to look at" are given higher priority on the list.

      Yes, that is a regrettable trend I've seen lately. Yes, code should be readable, and should be easy to maintain. But there is a huge amount -- maybe even majority -- of time when efficiency should be considered before readability or beauty.

    9. Re:Obviously by Jane+Q.+Public · · Score: 2

      I will elaborate just a little:

      I have personally seen code essential to execution time, which was neat and canonical, made literally more than 100 times more efficient in the sense of time and CPU cycles, by using methods that were a little less readable.

      And I mean via testing, not just subjective impression.

      TFA has its priorities skewed.

    10. Re:Obviously by Anonymous Coward · · Score: 1

      True story:
      I was debugging some code and ran across a section that appeared completely whack. Found myself thinking
      "What on earth were you smoking ... " when the comment a row below caught my eye saying:
      "I wasn't smoking anything! The above is correct because .. X Y and Z".

      Not only did I write that code, I had been there debugging / inspecting that bit before. And having no memory of either.

    11. Re:Obviously by nitehawk214 · · Score: 3, Insightful

      The door wings both ways though. Sometimes six-months-ago-me is a pretty cool guy.

      Like that time I was searching for an answer to a problem on Stack Overflow. At first I thought "Ha, what a coincidence, the top rated answerer has the same name as me." It was not a coincidence... it was me.

      --
      I'm a good cook. I'm a fantastic eater. - Steven Brust
    12. Re:Obviously by americanpossum · · Score: 1

      Last time I met myself, I kicked my own ass!

      --John Shepherd

      ;-)

    13. Re:Obviously by omfgnosis · · Score: 1

      For humans, simplicity and readability are generally prerequisites to efficiency. It's so obvious that the sentence reads like a tautology.

  2. Not being PHP by drakaan · · Score: 1, Funny

    Not being PHP would have to be in my top two list for what makes good code. Not being Visual Basic would be #1.

    --
    "Murphy was an optimist" - O'Toole's commentary on Murphy's Law
    1. Re:Not being PHP by orasio · · Score: 1

      PHP can be good or bad, like any other code. Lately it's getting better.
      As an example, do you think this looks bad? Looks pretty good to me.

        https://github.com/symfony/sym...

      I have some awful, unreadable examples I could share in Java, PHP, Javascript and even C, but chosen language no longer forces you to write bad code. Maybe Perl, but I haven't seen it lately.

    2. Re:Not being PHP by __aabppq7737 · · Score: 1

      From the very beginning, .NET was made for brownfield app development - never for speed. .NET has large dominance and is promoted by Microsoft because it wins over the windows platform.

    3. Re:Not being PHP by gmack · · Score: 1

      perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'

    4. Re:Not being PHP by MightyMartian · · Score: 1

      Dominance where exactly? A helluva lot of Windows development is still done in C/C++. Java still has massive penetration in the enterprise. I'll admit that .NET is a big player in the Windows world, but considering the Windows market appears to be at best static, and as a platform, compared to other computing devices (enterprise computing, mobile computing, etc.) is in absolute terms possibly even declining, I'd say .NET could hardly be described as dominant.

      --
      The world's burning. Moped Jesus spotted on I50. Details at 11.
    5. Re:Not being PHP by Anonymous Coward · · Score: 1

      Dominance where exactly? A helluva lot of Windows development is still done in C/C++. Java still has massive penetration in the enterprise. I'll admit that .NET is a big player in the Windows world, but considering the Windows market appears to be at best static, and as a platform, compared to other computing devices (enterprise computing, mobile computing, etc.) is in absolute terms possibly even declining, I'd say .NET could hardly be described as dominant.

      Windows programmers are not generally aware of platforms outside of the Windows world. I've known programmers who thought Microsoft invented ftp. That same programmer never logged to an operating system that different from Windows. You'll find the same it true for Windows shops. They don't know about anything else except Microsoft. So when someone makes a comment like, ".NET has large dominance..." They do it out of true ignorance and not malice.

    6. Re:Not being PHP by orasio · · Score: 1

      Does that manual encourage bad code ?

    7. Re:Not being PHP by Wootery · · Score: 1

      From the very beginning, .NET was made for brownfield app development - never for speed.

      Makes sense. Why would they try to make another C++?

      .NET is by no means slow though, as you seem to be implying.

    8. Re:Not being PHP by gmack · · Score: 1

      Any manual that encourages Perl encourages bad code.

    9. Re:Not being PHP by zarr · · Score: 1
      Reasons why hat code is crap:

      -Meaningless boilerplate comments. Comments on property getters and setters is pure noise.
      -Questionable OO design. Why are this class keeping references to serviceReferenceGraph and loggingFormatter which it doesn't use for anything?
      -Needless vertical scrolling. Given the triviality of this class, there is no reason for it not to be a one-pager.
      -It's in the DependencyInjection namespace, but... doesn't use dependency injection!
      -php pretending to be java. WTF is up with that?

    10. Re:Not being PHP by senatorpjt · · Score: 1

      It's pretty hard to fuck up a class that's just a collection of getters and setters. It was probably autogenerated anyway.

    11. Re:Not being PHP by Bill+Dog · · Score: 1

      .NET is dominant on the Windows platform. After over a decade doing C/C++ on Win32, I finally had to switch to it several years back. Except for specialized stuff where the extra speed actually matters, no one is developing applications on Windows at this low level anymore.

      --
      Attention zealots and haters: 00100 00100
  3. Because it's mine! by DickBreath · · Score: 3, Insightful

    Doesn't every self important developer think that their own code is the best?


    How many managers does it take to reach a decision to begin a study to determine whether a light bulb should be replaced?

    --

    I'll see your senator, and I'll raise you two judges.
    1. Re:Because it's mine! by mykepredko · · Score: 2

      Agreed for "self important developers".

      "Good" developers know that they probably missed things or could have done some parts of it better (and know that unless there is a functionality issue, to not go back and try to fix them).

      myke

    2. Re:Because it's mine! by Wootery · · Score: 1

      Depends. Have they just finished it, or are they coming back to it a month later?

    3. Re:Because it's mine! by Livius · · Score: 1

      Doesn't every self important developer think that their own code is the best?

      Isn't that the definition of 'self important'?

  4. Unencumbered by davidwr · · Score: 1

    Not encumbered by patents, NDAs, or licensing restictions the keep me from making good use of it.

    --
    Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
    1. Re:Unencumbered by DickBreath · · Score: 1

      Unfortunately, whether or not code is encumbered by patents is not up to the author of the code. That is one (of many) major FAIL of the patent system. Your code, yes yours, could be encumbered by some pending patent, that the 'inventor' is keeping from being issued until your code is suddenly making money. Poof! Patent is now granted and you are infringing.

      --

      I'll see your senator, and I'll raise you two judges.
    2. Re:Unencumbered by Anonymous Coward · · Score: 1

      Agreed, much better off pretending patents don't exist and paying bass damages instead.

  5. must fail by BytePusher · · Score: 3, Insightful

    Code needs to fail in an easy to understand and predictable way. If possible and practical provide descriptive and easy to follow details through logging or return values...

    1. Re:must fail by Anonymous Coward · · Score: 1

      Yeah I knew a guy once who when a configuration file lookup(environment variable) failed would default to the development environment. Of course he didn't bother to unit test the configuration lookup code which never worked in the first place. Lots of tears on deployment night!

      It's pretty simple stuff to test any likely to fail value and throw an exception saying something like "xyz configuration value is missing"
         

    2. Re:must fail by Rob+Y. · · Score: 1

      Yep. I've had C++ coders who were not building general purpose libraries, but still insisted on throwing exceptions in cases of fatal errors (because 'that's what you do'?). The caller would then catch the exception and then call a routine to log the error and core dump for later debugging. But dumping at the site of the caller discards all the detailed information and variables that would've been available in the core dump if the damn app just logged and dumped at the site of the error instead of throwing it back to the caller.

      --
      Posted from my Android phone. Oh, I can change this? There, that's better...
    3. Re:must fail by swilver · · Score: 2

      It is good practice to throw exceptions for even fatal errors. What they've missed however is to add information to the exception about the error (the stuff you propose they should log).

      Somewhere way up the call stack you have a catch all exception handler, which is responsible for logging the exception -- so it is not necesarilly the caller who logs this. If the caller cannot handle the exception, it should just leave it and let it bubble up.

      This way there's no need to duplicate logging code in every small little function that can't handle certain inputs.

    4. Re:must fail by Rob+Y. · · Score: 1

      My point is that in a fatal error of the sort "this should never happen, so I'm going to dump to let the programmer take a look", there's no way to format an exception to have the relevant information - you don't know what that info is. And for application (as opposed to library) code to throw exceptions that are never going to be handled other than to treat them as fatal and dump, throwing an exception is a waste of energy and discards possibly useful information. You're better off dumping at the site of the exception than where the caller catches it.

      --
      Posted from my Android phone. Oh, I can change this? There, that's better...
    5. Re:must fail by Rob+Y. · · Score: 1

      ...and 'logging code' is no more involved than 'exception code'. You format some kind of message and make a function call - how 'wasteful' is that?

      --
      Posted from my Android phone. Oh, I can change this? There, that's better...
    6. Re:must fail by xonen · · Score: 1

      I think the problem with most programmers (and techies) is they aren't big picture and very detail oriented

      Then, maybe, your using the wrong approach.

      Try "Don't document your code, but code you documentation"..

      This is as easy as creating all files you normally would, and just write down, in comments, the code you are planning to write. You catch several flies at once here: You design the entire code base, top-down, you bring structure to it, and you already documented it before you even started coding!

      All you have to do now is work out your comments. You start by prototyping your (OO) classes and methods or (non-OO) functions. Once you validated your information flow (as in: all methods take all parameters they need, objects have all variables and methods they need in a non-redundant way, etc etc)- the remaining task is trivial: work out any method.

      Then once you completed implementing the last method, you hit compile. And guess what: chances are your code _just works_ because you organized yourself and your activities in such a way that will avoid creating stupid mistakes and oversights, and 100% of your focus was with implementing well-defined functions or methods.

      Top-down just works. Especially when your projected project is large. Resist the temptation of coding (but of course, you can consider your approaches while designing). Don't feel stupid for spending 2 or more days designing without coding - you will earn this time back tenfold. And while designing without implementing, you will get a good feel of which potential libraries you need, and where the easy and tough bits of coding are. But eventually, it all comes down to avoiding errors while having oversight of the entire program flow.

      --
      A glitch a day keeps the bugs away.
  6. When you go back to it several months later by Z80a · · Score: 5, Insightful

    And say "thank you, my past self for making this so easy to understand and versatile!".

    1. Re:When you go back to it several months later by Z80a · · Score: 1

      Indeed there's no such thing as a "do what i mean" function , but generally within the context of the application, its good when you run into a function that is "future proof" enough to not need to heavily hack it or rewrite it whole to do something slightly different.

  7. Easy to change by Anonymous Coward · · Score: 2

    Code that you can change, and the change does what you expected and did'nt ruin something else in a seemingly unrelated place.

    Doesn't matter if the code is otherwise butt ugly, as long as you can do this, the code is good enough to be workable.

    1. Re:Easy to change by Xolotl · · Score: 2

      I was looking for a comment along these lines .. exactly. Over the years I've found that good code is that which can be opened up months or years after it was written and changed or repurposed easily. Good programmers seem to write this instinctively.

  8. a few heuristics by Sneftel · · Score: 3, Insightful

    Good code feels obvious and self-evident, as though its design springs directly from the problem, rather than from the cleverness of the developer.

    Good code is free of regret; regardless of how much it's been modified and refactored, it feels as though it was written in a single sitting, by a developer who somehow knew the right way to do it already.

    Good code is not just readable, but inviting. It feels as though there is no wrong place to start reading it.

    Good code doesn't have a single goddamn class named "Manager".

    --
    The opinions stated herein do not necessarily represent those of anybody at all. Deal with it.
    1. Re:a few heuristics by arth1 · · Score: 1

      I would say that good code is code that's as simple as possible for its task.

    2. Re:a few heuristics by __aabppq7737 · · Score: 1

      Good code doesn't have a single goddamn class named "Manager".

      ..but it does have main()

    3. Re:a few heuristics by avandesande · · Score: 3, Informative

      Good code is boring and bland, lacking excitement and surprises.... and mostly goes unnoticed.

      --
      love is just extroverted narcissism
    4. Re:a few heuristics by Scottingham · · Score: 1

      I'm not sure if it's just a semantics thing, but what's wrong with having a class called XManager that provides a set of safe functions to deal with a particular object or whatever it may be?

    5. Re:a few heuristics by carluva · · Score: 1

      About the only time a "Manager" is acceptable is if the code for the thing it manages is outside your control. Otherwise, "Manager" is almost always an instant sign of a functional design that's pretending to be object-oriented and failing miserably.

      Or, put another way: Classes called "Manager" almost always violate the single responsibility principle.

    6. Re:a few heuristics by dimeglio · · Score: 1

      It's a bit like watching a skilled performer. They are so good at it, they make it look easy. Then, when you try to do the same, everything ends up in main().

      --
      Views expressed do not necessarily reflect those of the author.
    7. Re:a few heuristics by Anonymous Coward · · Score: 1

      I can't tell if you're being insightful or if this is an actual outcry for human contact . . .

    8. Re:a few heuristics by Anonymous Coward · · Score: 1

      An important one is that good code stays good after many rounds of alterations.

    9. Re:a few heuristics by Anonymous Coward · · Score: 1

      Nothing

    10. Re:a few heuristics by Anonymous Coward · · Score: 1

      So if I have a DomainClassManager for every DomainClass to provide an uniform contract to manage those objects it is wrong. If I call the manager a DAO does it stays wrong. If I do it so I can scale my development team faster by providing an uniform approach accessible to average programmer, those who don't read about software and tech after work, is it still wrong?

    11. Re:a few heuristics by lgw · · Score: 1

      Funny, in my world, classes called "XManager" are expected to have the "single responsibility" of X, but in a way that needs it's own thread or something to do it right - more separation than the usual class boundary. If X is too broad, expect complaints in code review.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    12. Re:a few heuristics by Anonymous Coward · · Score: 1

      If I inherit code where the objects represent nouns and the methods represent verbs, I consider it a good day!

    13. Re:a few heuristics by bensch128 · · Score: 2

      I hate to burst your bubble, but every example of component based programming that I've seen uses managers to access and control the individual components. You cannot use components otherwise. (At least, not in a memory restricted environment like a video game)

      If you have ever worked on a large video games, then you know exactly what I am talking about.

  9. What would you add to this list? by QuietLagoon · · Score: 3, Insightful

    That it works.

    1. Re:What would you add to this list? by Oligonicella · · Score: 1

      Was reading through to see if I had to add that. Glad you did. It's really the most obvious and should have been first on the list.

    2. Re:What would you add to this list? by stjobe · · Score: 2

      To paraphrase Torvalds:

      If it compiles, it's good. If it runs, ship it.

      --
      "Total destruction the only solution" - Bob Marley
  10. GOTO by s.petry · · Score: 3, Funny

    Lots and lots of GOTO NNNN and I know it's good code!

    --

    -The wise argue that there are few absolutes, the fool argues that there are no probabilities.

  11. Re:Good code by __aabppq7737 · · Score: 1

    Mathematics and calculus have given us many tools (domain and range calling back) to know for a fact whether something will work or not. That being said, most errors occur from the human side of things, although, technically, we could prove that code worked w/out having to provide real world data.

  12. When it works. by Qbertino · · Score: 1

    When it works.

    No, seriously, that's the prime criteria. I'll take crap code over good code anytime, it it works and the "good" code needs some arcance and/or bizar setup procedure that I have to put up with to perhaps get it running.

    Point in case: WordPress, a PHP driven Web CMS that today runs about 20% of all websites, is a huge pile of typical PHP spagetti. And don't even get me started on the data model ... the WP crew probably doesn't even know what that is. Anyway, just the other day I spent two hours hacking the login template to coax it into not getting in the way of an auto-login feature built with Active X and JavaScript (...don't ask, the customer spends 150 Euros an hour, I'm sure as hell not gonna make stupid remarks on all this).

    I mean, just look at it! (Surgeon Generals Warning: Looking at WP code can cause instant heart problems and depression!)

    It was quite an adventure.

    However, it works. My grandma can setup WP in 10 minutes. Come around the corner with your flashy new Java whatnot, clean model and all, if I spend more than a week trying to get it runing on Debian or some other widespread Linux, I will ditch it, no matter how well the app itself is coded.

    Programms are for users, and they have to work. The rest is icing. End of story.

    --
    We suffer more in our imagination than in reality. - Seneca
    1. Re:When it works. by Jaime2 · · Score: 1

      Whether it works is orthogonal to quality. Good code can be fixed easily, so good code is always a short distance from "it works". Bad code can quickly go from "it works" to "it doesn't work and I don't know why" with just a simple change in requirements.

      One of my rules is that the customer is the judge of whether is works or not, but the team is the judge of whether it is good or not. If the only person to evaluate the product is the customer, then you are pretty much guaranteed to have bad code. Code quality management comes before testing in the form of design reviews, code reviews, standards, pair programming, etc...

    2. Re:When it works. by painandgreed · · Score: 1

      Whether it works is orthogonal to quality.

      I'd say that if it doesn't work, it's of pretty poor quality.

    3. Re:When it works. by ShanghaiBill · · Score: 1

      If it has gotten through "design reviews, code reviews, standards, pair programming, etc..." and doesn't work when it gets to test, you have a problem.

      ... and your problem is a completely broken development process. Code should be tested as it is written. You should never waste time reviewing code that has not passed unit tests, functional tests, regression tests, etc. Hallway usability testing should be done even before the design review.

      Testing is an integral part of every development step, not something you tack on the end.

    4. Re:When it works. by Jaime2 · · Score: 1

      I have to agree. If it has gotten through "design reviews, code reviews, standards, pair programming, etc..." and doesn't work when it gets to test, you have a problem.

      in these cases, "doesn't work" is a matter of interpretation. It's usually a defect or omission in the spec.

    5. Re:When it works. by Jaime2 · · Score: 1

      Testing is an integral part of every development step, not something you tack on the end.

      Good thing you know that we don't do unit testing... otherwise where we we learn that we were doing it wrong? Are you also going to assuming we don't do everything else I don't mention? I re-read my post and I can't find any part of it that could be used to infer that unit testing isn't part of our process.

      Also, if you leave code review until after the product has passed all testing phases, then you have two problems. First, if you change anything after the code review, then you're not done testing, so the only way to do code review last is to magically have code that always zooms through code review with no comments. Second, you'll never get approval to fix more than a trivial amount of code if the pointy-haired boss knows the customer has already signed off; that's the classic path to being forced support bad code.

  13. Personally? by nospam007 · · Score: 1

    Personally, I like speed. It must be fast, you can comment out a nice readable version, but the one to be compiled must be fast.

    1. Re:Personally? by Jaime2 · · Score: 1

      You can usually make good fast without much effort. It's often hard to make fast code good. Prioritizing speed above all else is a recipe for disaster.

    2. Re:Personally? by ckatko · · Score: 1

      I think programmers should focus on making code that "isn't slow" more than they should focus on "is fast." Focus on not making stupid mistakes like running higher-order algorithms than necessary (ala using a for loop to search for a key when you could have been using a dictionary).

      If you focus on fast, you should definitely do a profile-first-optimize-last approach so you're actually optimizing code that the computer spends most of it's time running.

      If you're optimizing fringe functions, then it better be for a pet project and "because I want to." Because otherwise you'll be sacrificing maintenance and introducing bugs for something that isn't even affecting the user.

  14. Testedness by carluva · · Score: 1

    Testability is critical, but it's pointless without actual tests. By tests, I do not mean a single test case verifying only the "normal" path where everything goes exactly as expected. I mean testing every boundary case, varying degrees of complexity where applicable, and failure modes, ensuring that it fails in the way that it is intended to fail and in every case where it is intended to fail.

  15. take it from a pro by nimbius · · Score: 4, Funny

    I think i can shed light on this subject, having several years experience in this field. New programmers and seasoned alike often make this mistake, either through carelessness or ignorance. When working to write good code, you must make sure to set good="yes" or good="veryyes." ive written code for 20 years now and this has only ever failed me in PHP. Apparently the language does not support "good" code.

    --
    Good people go to bed earlier.
    1. Re:take it from a pro by Qbertino · · Score: 1

      I think i can shed light on this subject, having several years experience in this field. New programmers and seasoned alike often make this mistake, either through carelessness or ignorance. When working to write good code, you must make sure to set good="yes" or good="veryyes." ive written code for 20 years now and this has only ever failed me in PHP. Apparently the language does not support "good" code.

      Don't forget to check $_GOOD correctly.
      You have to evaluate "veryyes" == $_GOOD like this:
      if (("veryyes" == $_GOOD) !== false) {...}
      otherwise
      $_GOOD = "kindaSoSo" and $_GOOD = "sortaOk" will both cause "veryyes" == $_GOOD to evaluate to true. ... Gotta know your PHP. :-P

      --
      We suffer more in our imagination than in reality. - Seneca
  16. Not being a metric ton of bit rot by fyngyrz · · Score: 1

    Fast; efficient; not bloated; not buggy; respectful of the user's privacy; hardened with regard to hacking if that's relevant; not encumbered by dependencies; adequately featured; well supported; well documented for the end user.

    As far as I'm concerned, if you can't hit those 00001000 or 00001001 targets, you should be looking for different line of work.

    Of course it is lovely if it's easily read code, well commented, well structured -- but if the former list is covered, I'll give the 00000011 latter a pass.

    --
    I've fallen off your lawn, and I can't get up.
    1. Re:Not being a metric ton of bit rot by Shompol · · Score: 1
      Pardon me, but your targets are off target: Fast Depends program objectives. Most of my code does not need to be fast, and some even works better if it is slow so it does not pig some resource efficient Usually the case, then again, see "Fast" not bloated maintenability not buggy BS. I just completed a complex project that integrates with pretty scary existing system. It is 95% bugs at this point, yet does not make it bad code. Most bugs will get weeded out over a few weeks, as long as code is easy to read and maintain. respectful of the user's privacy N/A hardened with regard to hacking yes not encumbered by dependencies maintenability adequately featured ? well supported It is if someone pays for it? well documented for the end user Users of a very complex iPhone never read a single page of documentation. I prefer things that just work as expected

      So IMHO it boils down to maintenability and security.

    2. Re:Not being a metric ton of bit rot by glenebob · · Score: 1

      Fast

      Depends program objectives. Most of my code does not need to be fast, and some even works better if it is slow so it does not pig some resource

      Sounds like a lame excuse for shitty code. Code should be fast/efficient, meaning it should get as much done as possible on as few cycles as possible. If efficient code hogs the CPU because it has a great deal of work to do, making the code slow is probably the wrong approach. Try lowering process or thread priority.

    3. Re:Not being a metric ton of bit rot by drkstr1 · · Score: 1

      So you write everything in assembler I take it?

      --
      Fanboy Status: Apache Flex, C#, Eclipse, KDE, Pirate Party, Ron Paul, Slackware, Windows 7
    4. Re:Not being a metric ton of bit rot by Shompol · · Score: 1

      I understand the CPU and other resource hogs are undesirable, but for simple things there is a trade off between keeping them simple or squeezing every drop of performance out, and for most practical tasks keeping things simple is more important.

      Imagine something that takes 0.001 ms on a cheap CPU and is used once a day. Is it worth making it faster for a day of work and a man-week of maintenance increase due to complexity?

    5. Re:Not being a metric ton of bit rot by Shompol · · Score: 1

      why are you making those errors?

      ...because it "integrates with a pretty scary existing system". Something written from scratch would have much much fewer. I guess it does speak of quality of the code but also depends on the quality of data it has to work with, external interfaces, changing user requirements, etc.

  17. Rhyming variable names by gurps_npc · · Score: 3, Funny
    Yes, that is the key measure of how good your code is.

    If you have no rhyming variable names, then your code sucks. 1 stars

    If you have one or two, it is barely acceptable. 2 stars

    Half rhyme, then 3 stars.

    If most, but not all, rhyme, 4 stars.

    If every single variable rhymes with at least one other variable, you have a great job, 5 stars.

    To get the coveted 6 stars, all the variable names have to rhyme with each other.

    --
    excitingthingstodo.blogspot.com
    1. Re:Rhyming variable names by ckatko · · Score: 1

      Rhymetime With Eminem - How do you rhyme with the word orange?

      https://www.youtube.com/watch?...

  18. Re:THE CORRECT LOOPING by __aabppq7737 · · Score: 1

    Assembly inlining is good if you're writing 'clever' (DO NOT WRITE CLEVER CODE) code.

  19. Re:Venn diagrams by __aabppq7737 · · Score: 1

    What is art? If I live by that principle, I'll never write a line.

  20. Why must it fail? Re: must fail by davidwr · · Score: 1

    Some code is small enough that it's feasible to prove that the code is correct, assuming that the underlying hardware, libraries, operating system, etc.. don't fail. For example, in most languages you really don't need to put error-checking in code as trivial as this pseudo-code:

    boolean isGreater(int a, int b)
    {return (a>b);}

    Sometimes, particularly when running in "small/tight" or real-time environments or when security is more important than debuggability, you may want a failure to be nothing more than something basic like "return -1" or "turn on aralm and halt the CPU" or even "flush caches, destoy security keys, and power off."

    But you are corrent, in most cases good souce code will have good, clear, easy-understand debugging code.

    --
    Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
  21. Define "Good" by mykepredko · · Score: 1, Informative

    This type of article comes up continuously on /. and without some concrete defining attribute asking what model/version/etc. of "X" is "Good" is going to turn into a poll.

    I would consider "Good" code to have the following attributes:
    1. Runs under all operating systems and platforms
    2. Source code is readable (note, this does not mean "Well Commented")
    3. Takes up the minimum amount of space
    4. Operations execute either apparently instantaneously or provides a progress bar for the user
    5. Installs quickly
    6. It's operation is intuitive
    7. Does not share user information
    8. Supports many/all user languages
    9. Does not have extreme licensing conditions
    10. Is free
    11. Source code available

    If I thought about it for another five minutes, I could probably double this list.

    And, it's *my* list of what I would look for in "Good" software, I suspect for anybody else here, YMMV.

    myke

    1. Re:Define "Good" by Zero__Kelvin · · Score: 1

      "1. Runs under all operating systems and platforms"

      Nothing like starting out of the gate with impossible to achieve goals.

      --
      Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
  22. diversity! by digsbo · · Score: 3, Funny

    When it's written by a gender and race balanced team, in a positive, multicultural environment, then it's good code!

  23. I like eligant code by Karmashock · · Score: 2

    That is... as brief as it can possibly be to accomplish the stated goal. Very simple.

    I also like it when the code is commented properly so that every operation is broken down and and annotated to explain what it is doing.

    This lets me go through the whole program and see what it is doing and the way it is doing it very quickly.

    The code that makes me crazy is the rube goldberg code that does some thing very simple in the most elaborate way possible, has no annotations so I have no idea what the actual point of the code is, and then to make things worse various parts of the code will randomly switch between doing different things for no reason.

    THAT code I hate. I see that shit and I delete it and write over myself.

    Part of the problem is that people don't know how to do somethings. They understand the language but they haven't memorized the really short code snippets that are the ideal way of getting from point A to point B. And that's just something a programmer should either have memorized or stored somewhere for recall.

    Using those code snippets tends make the code far more elegant and much more readable because you can see beyond the annotations what they're doing because you recognize that snippet.

    If they never use them, that is fine too... just so long as they don't make their code look like that breakfast making machine from Chitty Chitty bang bang. If they do that, I will murder them all. :-D

    --
    I've decided to stop wasting my time responding to AC trolls/sockpuppets... so if you want a response from me... login.
  24. I'd start with by GerryGilmore · · Score: 1

    ...not having your fucking article spread across 9 pages with about one paragraph per page. That would be a great start!

  25. Re:Good code by orasio · · Score: 4, Interesting

    For newly written code, things like readability, testability, and maintainability all can come in to whether it is "good" or not

    For legacy stuff, Good code is code that works. Who cares how easy it is to read or test as long as it works?

    The second one should also include "immutable". If it's hard to understand it will evolve easily to non working, and time spent on improvements can start to creep up very fast.

    I have worked in very clever, solid code, but not easy to read. It was then maintained and extended by average, but competent programmers down the road, and turned into a big mess, only because it was so hard to understand.

    In my experience, good code is easy to read, above all. That will make it easy to extend it coherently, find bugs and stuff. Also, if it doesn't work OK, it's easy to find out why. The single metric that saves time, money, and improves quality down the road is readability. Eveything else should be suject to that.

    And, about the last point in the "article", "efficient", it's nonsense. Premature optimization is the root of all evil. You should _always_ follow the second rule of optimization (see http://c2.com/cgi/wiki?RulesOfOptimization ).

  26. Re:Compactness and Readability by Yunzil · · Score: 5, Insightful

    It communicates clearly what it is trying to do.

    It doesn't, actually. Looking at that as someone who doesn't know what a CRC32 is I have no idea why it's doing what it's doing. Some actual useful comments might be nice.

  27. Time by El_Muerte_TDS · · Score: 3, Insightful

    After 5 years you can still read it and understand what it was supposed to accomplish, and it does so.

    1. Re:Time by istartedi · · Score: 1

      Scrolled down for this. I would add, "time and testing" and "testing" usually involves wide distribution. Yes, JPEG, PNG and Open Source compression libraries have had bugs, sometimes very serious ones. I still consider it some of the best code out there. I don't think being able to read the code matters. That's a red herring, unless you need to work on it. If everybody needs to work on it, it's too unfinished to be particularly good code. The only thing I've read in some of these libraries is the headers, and mostly the comments in there. It was literally self-documenting in comments the last time I looked at it. That's some good code.

      --
      For all intensive purposes, "whom" is no longer a word. That begs the question, "who cares"?
    2. Re:Time by phantomfive · · Score: 1

      I don't think being able to read the code matters.

      Then you're talking about the quality of the API, not the quality of the code. If for some reason you became a maintainer, then you would care quite a bit about being able to read the code.

      --
      "First they came for the slanderers and i said nothing."
  28. Impossible to answer by Murdoch5 · · Score: 1

    Good code starts with the right language for the job and the developer, then you have to follow the best practices for that language. How I program in C# and PHP is far different from how I program in C and ASM. The one thing that doesn't make code is abundant use of catch phrases.

  29. chocolate. dark chocolate. by swschrad · · Score: 2

    not to be confused with code that sorta looks like it, but surely doesn't smell like it...

    --
    if this is supposed to be a new economy, how come they still want my old fashioned money?
  30. Simple by Elixon · · Score: 3, Insightful

    I would definitely add "simple". Everybody can write complex code but it takes experience and great knowledge to be able to choose the best fit for the implementation. More experience and knowledge you have more options to choose from. Beginner will usually go with the first hunch that will get complex sooner or later as he will meet challenges he didn't expect...

    So yeah, simple, readable, documented, functional, consistent...

    --
    Well, I've got to get back to work. When I stop rowing, the slave ship just goes in circles.
  31. Cumbered by fyngyrz · · Score: 1

    And this is why closed source combined with black-box development is so much safer than open source. Sigh.

    I really don't mind -- actually, I think I'd be kind of of flattered -- if people were able to look at my code, go "hey, I can use that" and then proceed to use it. And in fact, I've written a fair bit of code I think would fall into that vein. I think I could write something book-length in the line of "cool coding stuff" and quite a few programmers would find it quite useful. I've been doing this since the early 70's. I write signal processing, and image processing (but I repeat myself, sorta) and AI code, with a strong background in embedded and special-purpose systems, a bunch more.

    But because a lawyer might look at my code, and use it to screw me, and through me, my family and employees quite harshly?

    Bang. Closed source. The opposite of furthering progress by virtue of passing along what I've learned. I give away some of my work product such as this, but you will never see my source code because of the legal environment.

    As far as I'm concerned, if I wrote it without referring to "other" source code, then no one else has any claim on my work. I don't have any idea how to fix copyright and patent and still retain the supposed commercial motivation to create, but fact is, as it stands, it's completely fucktarded.

    Pisses me off, it does. :/

    --
    I've fallen off your lawn, and I can't get up.
    1. Re:Cumbered by Bill+Dog · · Score: 1

      I would never even give away a program binary, let alone source, because even patents and copyrights aside, someone could use your code in their business and if something goes wrong, they could claim it's your fault and you cost them x thousands of dollars and then try to recover it from you in a lawsuit. I don't need patent reform, I need legal immunity; something like a good samaritan law for software.

      --
      Attention zealots and haters: 00100 00100
  32. Everybody's missing the most important stuff. by Anonymous Coward · · Score: 1

    No one's even mentioned the Bechdel test yet.

  33. Re:Compactness and Readability by BarbaraHudson · · Score: 1

    _When_ was the last time you actually needed a different CRC function from the standard 32-bit one?

    When trying to create unique crcs to use as hashes for 8 billion pieces of data daily so as to find them quickly. 32 bits isn't enough. 64 bits is way more than enough.

    --
    "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
  34. Vowels by rjstanford · · Score: 1

    Seriously. Good, readable names for everything make code far more self-documenting than otherwise, don't cost the compiler a single cycle, and make it far easier to understand when someone comes across it five years down the road.

    Other than that, I'd add methods that only perform one action, with no side effects, and that only work at one level of abstraction.

    Finally, code that matches its method name - don't say "if thing.checkValues()", say "if thing.isValid()" - and if isValid() does anything like trimming whitespace it should do it on its own transient copies of things, since its not obvious that the method would ever change state.

    And so on. It all boils down to code that doesn't surprise you.

    --
    You're special forces then? That's great! I just love your olympics!
  35. It's not that hard. by paavo512 · · Score: 3, Interesting

    Good code has documentation for knowing what it should do, and has unit tests to verify that it actually does that. If there are any problems good code can be modified to meet the (possibly changed) requirements better, while unit tests ensure the modifications do not make the code worse. Code which cannot be modified is not good code. It's that simple.

  36. no hungarian notation! by Virtucon · · Score: 1

    I don't care how bad or tangled the logic but as long as it's not using Hungarian notation, It's good.

    --
    Harrison's Postulate - "For every action there is an equal and opposite criticism"
    1. Re:no hungarian notation! by __aabppq7737 · · Score: 1

      Agreed. IDE's have fixed Hungarian notation - Simonyi lived before modern development environments came along.

    2. Re:no hungarian notation! by Livius · · Score: 1

      Hungarian notation was fabulous for its intended purpose: code that mixed C and assembly language.

      Sadly it escaped.

  37. Re:Compactness and Readability by __aabppq7737 · · Score: 1

    There needs to be a compiler (not language) that can convert mathematical proofs to an optimized assembly listing. How it would work, the files it would take in, and who would use it - I don't know.

  38. It's good if they don't code like 90s C++ devs by gestalt_n_pepper · · Score: 4, Interesting

    Their whole mindset still makes me want to puke.

    Obfuscated crap. Techno-machismo teens playing games trying to get their code into the least number of characters and the least amount of memory. I've had to fix or test so much of this junk and it's still just plain stupid.

    The *human* part of the system is what *matters* and that includes the code interface. First, I want comments not about *what* is happening. I can read that. I need to know *why* it was done, so I don't undo it, or I can do something different safely. Comments should be one liners, limited to "why" and sometimes "how".

    If adding a variable aids readability, add the fucking variable! Shove all the results into a meaningful, readable variable name and then shove *that* into your function argument, not some long series of nested function. It's not the 90s. You don't have to save memory! Memory is there to make your code readable. Use it!

    Ok, rant over. I'm going back to work now.

    --
    Please do not read this sig. Thank you.
    1. Re:It's good if they don't code like 90s C++ devs by Voyager529 · · Score: 2

      Techno-machismo teens playing games trying to get their code into the least number of characters and the least amount of memory.

      Given how many programs I've used over the past decade that have required unreasonably high amounts of RAM, and/or were subsequent releases of software that solved a particular problem in earlier iterations but required 1/10th the memory to do it, I wouldn't mind a handful of these guys getting their desks back. Adobe is a great place to start.

      I've had to fix or test so much of this junk and it's still just plain stupid.

      I'm by no means a programmer, but from the handful of times I've seen what you're talking about, I'll say this: if it's possible to save 10% of RAM by shifting the ease-of-use burden to the comments instead of the actual code, then as an end user, I'm 100% in favor of commenting the everloving hell out of difficult to read code that saves RAM when users are running it.

      You don't have to save memory! Memory is there to make your code readable. Use it!

      Wrong. Use as much as necessary, but no more. I might have 12GB of RAM in my laptop, but it's not all for you. It's for EVERYTHING I do, and when I start adding VMs or large After Effects projects to what I'm doing, 12GB starts to get pretty cramped. Some RAM usage will be inevitable, but wasteful RAM usage is wasteful.

      I most certainly have plenty of admiration for the Demoscene.

    2. Re:It's good if they don't code like 90s C++ devs by drinkypoo · · Score: 1

      If adding a variable aids readability, add the fucking variable! Shove all the results into a meaningful, readable variable name and then shove *that* into your function argument, not some long series of nested function. It's not the 90s. You don't have to save memory! Memory is there to make your code readable. Use it!

      If that's all the variable is used for, won't the compiler optimize it out of existence anyway? Or is that too fancy yet?

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
    3. Re:It's good if they don't code like 90s C++ devs by tapspace · · Score: 1

      I think a lot of people don't really understand how the compiler actually works. Not even at a basic level. If I make three different loop variables (int types) for three different loops which run at different times in a function (let's say this improves readability), any modern compiler worth its salt will only use the space of a single int for these three (because they are never used together). In my experience, many programmers, even mid-level, would not know that. And, this doesn't even require an understanding of how a compiler works. This is SUPER basic compiler understanding. This leads to poor attempts at "optimized" code which saves nothing (because they compiler will do the same thing to the machine code) and detracts from readability and maintainability.

    4. Re:It's good if they don't code like 90s C++ devs by drinkypoo · · Score: 1

      If that's all the variable is used for, won't the compiler optimize it out of existence anyway? Or is that too fancy yet?

      I think a lot of people don't really understand how the compiler actually works. Not even at a basic level.

      Well, no, I don't. That's why I asked. It sounds like the answer to my question is yes?

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
  39. Editable by mdfst13 · · Score: 1

    One of the most important criteria is that good code be easy to modify. Readability, testability, elegance, and simplicity all lead back to that. When you change code, you should be assured that it will do what you expect. Bad code produces surprising side effects when you change it. Good code warns you (possibly through unit tests attached to the code) when you are doing something questionable. If you have to run the code to determine what it does, then that's not good code.

    Needs evolve and change over time (or simply become clearer). Good code needs to be able to follow.

  40. Good? by PPH · · Score: 1

    Spaghetti code is good.

    With lots of meatballs.

    --
    Have gnu, will travel.
  41. Not a single answer by swan5566 · · Score: 1

    Coding a prototype of something that's rapidly changing in huge ways should be done differently than production code that's worked on by lots of different developers. One will not be optimal for the other.

    --
    In debates about Christianity, there are two groups: those looking for answers, and those looking to just ask questions.
  42. Re:Well commented. by Jamu · · Score: 5, Funny

    What if the comment is // this code sucks.?

    --
    Who ordered that?
  43. data structures first / control flow second by mspring · · Score: 1

    Code is good when the data structures clearly model the problem domain. The algorithmic code / control flow then follows naturally and is easier understandable.

  44. :( Can you help the world? Re:Cumbered by davidwr · · Score: 1

    Take all work you've written and entrust it with someone who will publish it a few years after you die and after your estate is settled or a few years after the last company that would have any claim to it ceases to exist, or after any copyrights or patents other than yours that apply can reasonably be presumed to have expired (probably 95 years after you wrote the code), whichever comes later.

    --
    Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
  45. Slashdot Friday brought to you by ... by plcurechax · · Score: 1

    The Wayback Machine...

    Or, see the Slashdot article, "Beautiful Code Interview" that discusses an entire book about the very topic.

  46. Short modules / Clear variable naming by blueshift_1 · · Score: 1

    I agree with most of the earlier posts, but the main thing I look for is conciseness and clear & consistent naming of variables. If your methods/procedures/classes/functions/subroutines are are obnoxiously long, it makes it less readable, harder to test, and just longer to debug. Modular design also lends itself to be more reusable. I've always been of the mindset to name your variables what they are. You shouldn't have to go to a comment or read the code to see what it does. It should speak for itself - even for someone who isn't super familiar with your code/project. Or at least that's what I think...

  47. Nobody likes range checking? by bughunter · · Score: 1

    Yanno, it's been years since I've coded (beyond looking thru code to tweak a definition here or there anyway). Decades, even.

    But I was taught on the job that range checking of inputs and boundary conditions was essential to reliable code.

    Obligatory XKCD reference.

    --
    I can see the fnords!
  48. Beautiful, optimized, and easy to maintain by maroual · · Score: 1

    When it is done by people, code can be art sometimes. I have no good example immediately available, but I mean there is a huge difference between generated code such as jquery-1.11.2.min.js and code that can be read by humans. By optimized, I mean the lowest time and space complexity during run time. And there are basic and obvious maintenance constraints that everybody should follow like avoiding hardcoded values (unless necessary), keeping it easy to read, avoiding +1000 lines routines if not necessary, ... Regarding debates on comments vs self explanatory variables, I have no opinion on this. Depends on how it's done.

  49. Re:Compactness and Readability by painandgreed · · Score: 1

    Good code does one thing well:

    It communicates clearly what it is trying to do.

    Personally, I'd say that good code does what it is trying to do. Great code will do that and communicate what it is doing clearly.

  50. MOST IMPORTANT by Celarent+Darii · · Score: 1

    Code has to be AVAILABLE - this is the most important. That means it must be OPEN SOURCE.

    If it is CRAPPY code, it can be MADE BETTER if it is open source.
    If it is INEFFICIENT code, it can be REWRITTEN if it is open source
    If it is HARD TO UNDERSTAND code, it can be COMMENTED if it is open source.

    So any code that is OPEN SOURCE, even if it is crappy, inefficient and hard to understand, can be improved.

    But any code that is CLOSED is absolutely useless in my opinion.

  51. Here's what good code is to me.... by purpledinoz · · Score: 1
    • Functions that span 1000 lines with heavily nested if and switch statements and behaves differently depending on global variables
    • Massive 10k line classes that are more mystifying than God himself
    • Everything is an interface because you may want to create a mock for it, and you get multiple inheritance!
    • No comments. Code essentially comments itself!
    • Functions should create side effects, otherwise life would be boring.
  52. Plan B by Krishnoid · · Score: 1

    ... functional, readable, testable ...

    From the maintenance perspective, when you can't make the code meet some standard, comments describing what you missed and why (time, spec conflicts, didn't care enough) are helpful. This hints to the next maintainer that modifying a piece of code that missed some good-practices target has additional considerations or hidden pitfalls, or that it can be fixed/extended/replaced with impunity.

  53. Re:You only coded what was needed, and its testabl by mr_mischief · · Score: 1

    You skipped the case in which it's not unique code but for which you don't have a library.

  54. Edge cases by Daniel+Hoffmann · · Score: 1

    Good code has comments for edge cases, I mean "why the fuck are you checking if foo is less than bar?" with "//checking if foo will not overflow because ..."

    Edge cases are by definition very unlikely, usually the code that handles them are bugfixes. Too many times I come across code that is full of bugfixes for those edge cases but no comments whatsoever, to me those kind of comments are more important than method comments (aka javadoc).

  55. Re:Compactness and Readability by itzly · · Score: 1

    If you need a 64 bit hash, write a special 64 bit hash function. It's only going to take a few lines, and removes dependencies on bizarre external code, like 64 bit CRC that nobody ever uses.

    Besides, CRC functions aren't very good for hashing, as CRC(x) XOR CRC(y) = CRC(x XOR y)

  56. Re:Compactness and Readability by Dr.+Evil · · Score: 1

    Over-commenting is a very real problem, and CRC32 is CS101. If I was reviewing code which described what CRC32 was, I would remove the comments.

  57. CS is only practical by accident, but that's okay by Tenebrousedge · · Score: 1

    Computer Science is [a] a misnomer, and [b] more properly a subset of mathematics. I might characterize it more as giving you tools to reason about code rather than teaching coding practices. It is not generally meant to be a practical education. There is always time to learn the practical stuff, and the practical stuff changes often enough that it's not necessarily worth teaching.

    I'm in the opposite camp: I'm self taught, and know a bunch about deployment and the intricacies of source control, and refactoring, but very little about, oh, algorithmic complexity or parser/compiler design. The theoretical stuff isn't quite as useful on the day-to-day as the practical knowledge, but it's much more useful when trying to learn new things. Similar to how you don't necessarily need music theory to play guitar but if you want to transpose a piece of music or pick up a new instrument, it would be pretty useful. Composing a piece of music might be more like writing a compiler. In both cases you'd be relying heavily on theory.

    If you thought you were signing up to learn how to be a programmer, you've made a mistake, but it's not so bad as you think. The stuff you're learning is useful, even if it doesn't seem like it. I feel like I could stand to know quite a bit more about it myself. And the lesson is, that you need both parts, and you'll miss whatever you don't have, but you miss the practical stuff all the time, and the theoretical stuff only when it's really, really important.

    --
    Those who advocate genocide deserve every protection afforded by law, and none afforded by common human decency.
  58. Re:BS by rHBa · · Score: 1

    Fair enough Windows has been dominant in the PC market for decades but you can hardly say it's been dominant on server platforms for decades (ever?). Maybe for intranet use but as far as internet facing, mission critical servers UNIX, BSD and since the late 90s Linux has been dominant.

  59. Do the job now and later by Ted+Stoner · · Score: 1

    The first thing is, most of us are coding as house painters rather than as Rembrandt. So it needs to do the industrial job. I tend to put as much effort into documentation and style for my personal code as for working code.

    If the code is for a micro-controller in C then the emphasis might be more on raw efficiency and preciseness. A command line utility run ad hoc with low resource usage can afford to be a little less efficient and more readable. Code for an online transaction system needs the efficiency, perhaps as a tradeoff to readability but in most cases hopefully not.

    I have written code and products and have had to go back to stuff I wrote 15 years ago. So I learned a long time ago to document as clearly as possible for the poor sod in the future (i.e. me) who will have to come back and make sense of everything. Mostly I succeed here but sometimes I fail.

    I also supported other people's assembler code for a few years. That provides lots of what not-to-do's.

    If you are coding examples for a book or website then the rules and aesthetics can be changed again. Maybe think more Rembrandt here.

    Functionally, document everything, use meaningful and consistent naming conventions, catch errors, log, provide trace capabilities where needed, be as generic as possible and think about reusability but don't obsess over it (depends on the context as always).

  60. Elegance. by DriveDog · · Score: 1

    Elegance.

  61. Re:Compactness and Readability by Kjella · · Score: 1

    Well in this case I'd say there's Google and Wikipedia, use them. The source code is not the right place to teach someone about what CRC32 is or when, where or why you might want to use it. It's almost as bad as comments that try to teach you the programming language you're in. If you're implementing something that's not in an RFC or standard of some sort, I'd agree with you.

    --
    Live today, because you never know what tomorrow brings
  62. Re:Well commented. by Anonymous Coward · · Score: 1

    I know this is a joke but my favorite comments are one like // this code sucks that unabashedly describe the merits and problems of the code. There's nothing worse than auditing convoluted code and wondering "is this code terrible or brilliant?" If the original author tells me that it's not brilliant then it saves me from exploring that avenue.

  63. Good Code Metircs by prefec2 · · Score: 1

    There are several metrics which can help you to identify code which is not bad. One is cyclomatic complexity. Another are connectivity metrics going over the graph your code spans. For cyclomatic complexity there are good boundaries available. However, it is a complexity metric. And complexity is not the only thing which affects code quality. Other elements are labeling operations, such as methods, functions, and procedures. There is plenty of lit. available in the area of code comprehension.

  64. Re:BS by MightyMartian · · Score: 1

    On PC platforms perhaps. Not on server platforms.

    --
    The world's burning. Moped Jesus spotted on I50. Details at 11.
  65. Re:Argue w/ the numbers by MightyMartian · · Score: 1

    A guy whose evidence is "I've seen stats", without linking to them shouldn't be lecturing about hard evidence.

    --
    The world's burning. Moped Jesus spotted on I50. Details at 11.
  66. Re:Compactness and Readability by goose-incarnated · · Score: 1

    CRC's were in my first year of CS, in 1996.

    --
    I'm a minority race. Save your vitriol for white people.
  67. Re:Compactness and Readability by phantomfive · · Score: 1

    If I was reviewing code which described what CRC32 was, I would remove the comments.

    Well, you are Doctor Evil.

    --
    "First they came for the slanderers and i said nothing."
  68. Ready to eat your words? by Anonymous Coward · · Score: 1

    You can see it on Netcraft's "what's that site running?" -> http://toolbar.netcraft.com/si... & for showing what academic institutions run what (that could also be done for the Fortune 100/500 & really *ANY* type of servers out there).

    I've used here a few years back to see for myself:

    http://news.slashdot.org/comme...

    & yes, to prove that very point WITH VALID DATA FROM A REPUTABLE SOURCE (2 of them, CNN list of Fortune 500 + NetCraft)...

    All that happened vs. it was downmods and ad hominem attacks (the last resort of "defeated trolls", lol, & invalid proving my points all the more).

    It works & since you demand it? Take a look for yourself there... get a list of the Fortune 100/500 & see what you see nowadays I suppose. That's only on servers though. There's millions of PC's out there vs. servers. What do PCs run the MOST (94++% of them worldwide as a KNOWN fact? Windows!)... you can't win on that note alone.

    Facts used that way work, & I've used that before here, to shut fools up on that very account + face it: The ONLY real reason say, Linux, gets used, is to keep per unit costs down (on servers AND smartphones)

    +

    Face this about that much: ALL THOSE YEARS OF "Windows != Secure, Linux = Secure" is falling apart around your ears here - ANDROID, yes a Linux, proves it for me (& I love it + hate lying bullshitters/deceivers - not because I hate Linux, I don't & ADMIRE it actually as a socio-technological phenomenon that proves folks CAN & DO work together globally doing nice things for free).

    You bullshitters don't realize 2 things: Your deceits shoot you in the foot, I make SURE it does (lol) & you can't EVER ever get the best of me - you don't HAVE what it'd take in truth & facts.

    APK

    P.S.=> However, the "noobies" inexperienced youthful stupid view here isn't aware of the fact C/C++ have been hugely successful on ALL platforms and have gained a gigantic following & momentum that other languages just do not have since time + success will do that for me (selling itself better than bs & "pr spin" that goes on around here like mad, lol, that's for sure ala my "Linux = Secure, Windows != Secure" b.s. that went on here for years)... apk

  69. Solving real problems without excessive complexity by iamacat · · Score: 1

    If the code has a useful function and exposes it with an interface that is no more complex than absolutely necessary, it doesn't matter how ugly it is inside. It will be used and, in time, there will be resources to clean it up. UNIX system calls, libraries and command line tools are a good example. There is not much in common between original code and various modern implementations, but code written on top of these over decades still works and both developers and users are able to leverage their experience.

    Also, even the best written code will have bugs. With simple interface, it's at least feasible to write good tests and find some.

  70. Compactness / infimum by TeknoHog · · Score: 2

    A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away.

    -- Antoine de Saint-Exupéry

    --
    Escher was the first MC and Giger invented the HR department.
  71. Re:It's not polite to talk with your mouth full by bbn · · Score: 3, Insightful

    FACT: The PC to Server ratio is MILLIONS to 1 alone

    This does not stand to even 5 ms of thinking. I am living in a country with 5 million people. You are claiming we have 5 servers or something like that.

    Or if you are an american: How many cities do you have with more than 5 million people? How many cities with more than 5 servers? ...

    Or ... there are about 7 billion people on the earth. Lets assume that each have a PC (many don't). You are claiming there are only 7000 servers on earth.

  72. Do not add anything to the list by olau · · Score: 1

    Code needs to be easy to understand, that's all. You can't keep a long list of priorities in your head, that simply doesn't work at all. Just keep one: easy to understand.

    Of course it needs to work, but that's obvious so not really worth stating - testable is part of this obviousness, if you need to test it, and you can't, well, then it doesn't work.

    Sometimes code needs to be performant, but often this is only the case for small parts of it, so it's better not to think about it or it will tend to compete with making the code easier to understand.

    I'm deliberately using the phrase "easy to understand" and not just talking about readability, because ease of understanding often doesn't not come from just superficial readability tweaks like spacing, consistent styling, self-explanatory naming, etc. Often it may require approaching the problem at hand from a different angle, modeling it slightly differently or otherwise shuffling things around a bit to reduce accidental complexity and avoidable dependencies.

  73. Re:Argue w/ the #'s & "eat your words" by bbn · · Score: 1

    You want me to prove there are 7 billion people on earth?! You are more stupid than a kid in first grade.

  74. This has been well discussed by Just+Some+Guy · · Score: 1

    R. Pirsig wrote a paper on the philosophical and mental challenges in defining "quality". I suggest reading it.

    --
    Dewey, what part of this looks like authorities should be involved?
  75. Re:Compactness and Readability by UnknownSoldier · · Score: 1

    > What the hell is this?

    The 8th entry is set to zero so that the test can verify the table was initialized properly.

    > 4))

    > Why is there a block comment at the beginning that does nothing.

    For alignment of CRC32_REVERSE, CRC32_VERIFY, CRC32_Table since /. fucks up formatting.

    > and what the hell does that trailing comment mean?

    The comments lists entries [0] and [1]. The first 8 entries are these :
    i.e. 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,

    Whenever you generate a table it is always helpful to list _expected_ values so someone can _verify_ them with _actual_ values.

  76. Re:Compactness and Readability by UnknownSoldier · · Score: 1

    Yeah, I forgot to include

    // Reference: http://www.ifp.illinois.edu/~sarwate/pubs/Sarwate88Computing.pdf

  77. Re:Compactness and Readability by BarbaraHudson · · Score: 1

    I wrote a 64-bit crc function, and it worked fine over billions of records of random-length text, was extremely fast (written in c), only required 8 bytes of storage, and was thread-safe.

    --
    "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
  78. I can't believe nobody's mentioned these. by Anonymous Coward · · Score: 1

    All this other shit is useless unless:

    * the way the problem under solution is broken into solvable, understandable pieces is well chosen. Make a bad choice here and your code blossoms in complexity and fragility.
    * naming and spelling is consistent. Don't show me code that has shit like "frobURI()", "tweakTheURI()" and "makeUriPretty()". Components of names must be consistent. 'do', 'get', 'put', 'fetch', etc. must always mean the same fucking thing.

  79. That magic by Xenna · · Score: 1

    When with a few tiny changes you open up whole avenues of functionality that hadn't been conceived before. Sometimes you get that and it gives me immense pleasure. It opens up potential your code didn't have earlier.

    Am I babbling or does that ring a bell for anyone?

  80. Re:Easy to refactor by ChrisMaple · · Score: 1

    It does everything in the simplest, most obvious way.

    So.......bubble sort.

    --
    Contribute to civilization: ari.aynrand.org/donate
  81. Re:Eat your words on MULTIPLE grounds vs fact by rHBa · · Score: 1

    Hi APK, I knew you were a hosts file fanboi, I didn't know you were a Microsoft astroturfer as well!

    FYI, I didn't intend to put words in your mouth, hence why I put "ever?" in brackets (context APK, context...).

    Also, if you want people to take you seriously then you need to learn how to summarise your thoughts and present them in a non-td;dr way.

    // Note to self, don't feed the trolls

  82. Re:Well commented. by infolation · · Score: 1

    Well, just comment out the code section that sucks. Job done.

  83. Contributions by manu0601 · · Score: 1

    There are many axis for rating software. One of them is how easily a newcomer can contribute. It measures simultaneously code clarity, architecture choices, software usefulness (who wants to contribute to something useless?), maintainers mindset...

  84. Re:You're offtopic illogical & non-sequitur by rHBa · · Score: 1

    Take your meds APK

  85. MY favorite code by Ryanrule · · Score: 1

    The best code is code that when you have to go in to make a change, was built in such a way that new features just slot in nicely, with little rework or fuckery. I LOVE when code I built previously means what someone thinks will take me 3 weeks takes me 1 hour (billed at 2 weeks)

  86. Holy Sheep Testicles Batman! by LostMyBeaver · · Score: 1

    Can you honestly expect to get a worthwhile answer to this question on Slashdot?

    Wouldn't it have been better to ask people to link Git repositories with examples of good, clean code instead? Better yet, make a site which allows people to link a repository instead and explain why that code is either good or bad. Let people vote as well.

    I can show you massive portions of the Linux kernel tree which is both good and bad. Good because it's functional, tested and works well. Bad because it was ransacked by the spaghetti monster. Want a great example?

    https://github.com/torvalds/linux/blob/master/lib/glob.c

    This code is fantastic because it is rock solid and has been tested to death. It's even relatively clean, but while some people can actually use it, maintaining it would be nightmarish due to lack of documentation. It's documentation isn't entirely awful, and I really wouldn't say "replace it because it's not pretty", but it's code is simply not pretty.

    It also has to be handled with care. It makes assumptions that the parameters passed are proper. Used improperly, it can cause overflows. There's no real error handling or bounds checking. It's not what I would personally call "secure code".

    But it's great code all the same.... if called from a function which ensures what is passed is valid.

  87. Depends on the requirements by TMB · · Score: 2

    The best piece of code I ever wrote in my life was nearly 100x faster than the next best algorithm ever written to do that problem. That took the expected run time down from a few days to an hour.

    It was not a particularly well-commented piece of code. If it were, it would have been even better.

    It was not a particularly obvious algorithm for solving the problem. If it were more obvious why one would choose to do it this way, it would have been even better.

    If the primary concern is runtime (because it normally takes days to run), and you literally make it orders of magnitude faster, that's good code. It could be better if it were also better commented and easier to maintain, but those aren't *always* the primary concern (yes, sometimes they are. That's the point -- criteria differ!)

    [TMB]

  88. Re:Compactness and Readability by CBravo · · Score: 1

    What is missing is the word 'design'. You may comment why you made a design (or write a paper on it). You may understand the design by reading the code. If you don't it is either too complex (because there is a possibility to write the same functionality with the same complexity with easier-to-read code) or you need to explain the design for it.

    --
    nosig today
  89. What Makes Some Code Particularly Good? by Rudisaurus · · Score: 1

    How about: it's bug-free?

    --
    licet differant, aequabitur
  90. Re:It's not polite to talk with your mouth full by Hognoxious · · Score: 1

    Perhaps he's been listening the that IBM guy from 1968.

    --
    Confucius say, "Find worm in apple - bad. Find half a worm - worse."
  91. Reusable by MichaelMacDonald · · Score: 1

    I think re-usability and properly formed and conceived libraries and classes if it's object oriented should be in there. I've seen plenty of people meet all 8 of those requirements, but have all their code in one giant file that really should be divided up into separate logical pieces that could be used again in other projects.

  92. Re:Where to begin... by MichaelMacDonald · · Score: 1

    Code headers are nice, but if code is properly written and structured they can be overkill and clutter, so I don't see them as mandatory in all cases. Otherwise, I like this :D. Divide your code into separate source files using logical divisions that make sense. Then create libraries if one of the divisions gets big enough. Try to emphasize reuse.

  93. Zorro-friendly: get in, make your 'Z' and get out by TheRealHocusLocus · · Score: 1

    I offer Sendmail in its mid-1990s form as an example. We had several dialup customers with Microsoft Exchange servers. They'd connect and Exchange would issue an ETRN to dequeue waiting messages. The problem was that Sendmail by default, would send a "Warning: could not deliver mail for 4 hours" reply back to sender after the email had languished in the queue that long, and they dialed in sporadically and not at all on weekends so folks who emailed them would get these messages. It was bad. I wanted to disable this warning specifically for ETRN domains but not for everyone.

    Does this feature exist? Sendmail documentation defined 'queuewarn' as a global setting but did not address this "deferred delivery by design" problem. Could there be a presently-undocumented or undiscovered workaround? Delving into the source it was visually apparent the answer was no, the warning was unconditional. The only workaround would have been to run a completely separate SMTP server on another IP address with the queuewarn off, and MX 'em to that. What a bother. Are domain-specific attributes available? Yes, these had a mailer flag of HOLD. Can it be addressed with a one-liner? Yes. So the _FFR_NODELAYDSN_ON_HOLD compile/config flag was born, off by default because we don't want to break things.

    Just a couple of hours to discover, patch and test. another hour to render it into a contrib patch where it made its way into Sendmail. Open source is cool and when you see your own contribution being proposed as a solution to solve someone else's problem years later... that is quite satisfying.

    Sendmail had the right balance of code-to-comment. What comments were there would not make sense until you understood the underlying process, and tag names were explicit enough that comments were seldom necessary.

    --
    <blink>down the rabbit hole</blink>
  94. Re:Compactness and Readability by Dr.+Evil · · Score: 1

    crc32 is the name of the algorithm. If you dont know what it is, what it is for or why it exists, comments aren't the place to describe it. Incorrect, misleading or unnecessary comments are worse than no comments at all.

  95. Re:Well commented. by DMUTPeregrine · · Score: 1

    Hope it's controlling a vacuum pump.

    --
    Not a sentence!
  96. Re:Compactness and Readability by hcs_$reboot · · Score: 2

    Some actual useful comments might be nice.

    Well, when the function is named calculate_crc32()...

    --
    Slashdot, fix the reply notifications... You won't get away with it...
  97. Re:Compactness and Readability by UnknownSoldier · · Score: 1

    It will come up in your Comp. Sci. education.

    If it doesn't you have really bad teachers, or a really bad school.

    All good programmers should understand the basics of one-way-hashes.

  98. Re: Argue w/ the #'s & "eat your words" by bbn · · Score: 1

    There is no lose or win - is this the kindergarten?

    I replied to one claim and one claim only: that the PC to server ratio is in excess of a million to one. That claim is so absurd that anyone not laughing their ass off is an idiot that has trouble with big numbers.