Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
Programming Linux

Programming Things I Wish I Knew Earlier 590

theodp writes "Raw intellect ain't always all it's cracked up to be, advises Ted Dziuba in his introduction to Programming Things I Wish I Knew Earlier, so don't be too stubborn to learn the things that can save you from the headaches of over-engineering. Here's some sample how-to-avoid-over-complicating-things advice: 'If Linux can do it, you shouldn't. Don't use Hadoop MapReduce until you have a solid reason why xargs won't solve your problem. Don't implement your own lockservice when Linux's advisory file locking works just fine. Don't do image processing work with PIL unless you have proven that command-line ImageMagick won't do the job. Modern Linux distributions are capable of a lot, and most hard problems are already solved for you. You just need to know where to look.' Any cautionary tips you'd like to share from your own experience?"
This discussion has been archived. No new comments can be posted.

Programming Things I Wish I Knew Earlier

Comments Filter:
  • Comment your code (Score:5, Insightful)

    by Nkwe ( 604125 ) on Monday September 06, 2010 @02:22PM (#33490276)
    Put enough comments in your code so that five years from now you (and others) can remember what you indented the code to do. Remember that comments are not for describing what the code technically does (that is what the code is for), comments are for what the code is intended to do. Try and comment the decisions you made when developing the code, specifically why you took the approach you did and why you didn't use other options.
    • by Anonymous Coward on Monday September 06, 2010 @02:25PM (#33490306)

      Put enough comments in your code so that five years from now you (and others) can remember what you indented the code to do

      I indented the code to make it readable. That's so obvious I don't need a comment to remind me.

      • by Korin43 ( 881732 ) on Monday September 06, 2010 @04:01PM (#33491388) Homepage

        I don't know. I prefer to comment, just in case:

        while 1:
                # Indentation
                dosomething()

      • by TeknoHog ( 164938 ) on Monday September 06, 2010 @04:19PM (#33491612) Homepage Journal

        Put enough comments in your code so that five years from now you (and others) can remember what you indented the code to do

        I indented the code to make it readable. That's so obvious I don't need a comment to remind me.

        (pun indented)

      • Re: (Score:3, Funny)

        by rhyder128k ( 1051042 )
        The road to hell is paved with good indentions.
    • Re: (Score:2, Funny)

      by Anonymous Coward

      "indented the code to do"

      So the real question is tabs or spaces?

    • Re: (Score:2, Funny)

      by Anonymous Coward

      > Remember that comments are not for describing what the code technically does (that is what the code is for), comments are for what the code is intended to do.

      Corollary: Never debug comments, only code.

    • by kantos ( 1314519 ) on Monday September 06, 2010 @02:30PM (#33490352) Journal
      Commenting is not enough... you need to make sure you clean up the comments in a file before resubmitting it... dead comments can be more dangerous than dead code... as dead code at least doesn't run... dead comments mislead the person following later into believing a lie a lie that could potentially have major impacts on the software. Lastly... write meaningful test cases... if your tests only prove the happy path, that's OK... but if they prove that the happy path is the only path.. that is better.
      • by nacturation ( 646836 ) * <nacturation AT gmail DOT com> on Monday September 06, 2010 @04:42PM (#33491824) Journal

        dead comments mislead the person following later into believing a lie a lie that could potentially have major impacts on the software.

        // the following code delivers cake to the subject

      • Re: (Score:3, Funny)

        by Greyfox ( 87712 )
        /* Don't touch this function unless you REALLY know what you're doing */ Funnily enough the only guy who ever touched it didn't know what he was doing. In the short time he worked there, he did enough damage to the code base that it took 6 months to fix it. Too bad the version control system we were using at the time didn't allow you to simply mass-revert a user. That would have actually saved us a lot of time.
        • Re: (Score:3, Interesting)

          by kbielefe ( 606566 )

          That's because people who don't know what they are doing don't know that they don't know what they're doing. Those types of comments should be accompanied by a clear competence or acceptance test. For example, the last such comment I wrote went something like: /* This might look like an unnecessary delay, but the timing has been carefully calibrated against a wide range of marginal real world conditions. If you touch this function, you must ensure it does not time out under these configurations... */

          In

          • Re: (Score:3, Interesting)

            by Greyfox ( 87712 )
            That's true. The function in question was actually quite well commented, and that last one was really more of a warning that all the comments should be read before messing with it. A set of unit tests would actually have been pretty nice and would have saved us a lot of trouble over the 5 years we worked on it, but it would have been a tough sell to management.
    • Well, yes commenting on your intent is a good idea, but it's not really enough. You also ought to be commenting on _why_ you're doing something rather than an alternative it makes it a lot easier later on when you're debugging and wondering why you picked that solution. Makes it a lot less likely that you fix the code and reintroduce whatever it was that you were trying to avoid in the first place. But when it comes to the what, if you have to put a what comment into your code, then you've done something ho
      • by Anonymous Coward on Monday September 06, 2010 @02:36PM (#33490436)

        Commenting code isn't enough, it's just a small part of the design and documentation process. Comments are there to tie the code to the relevant part in your design document, which really is a part of programming people should put more effort into.

        • Re:Comment your code (Score:5, Interesting)

          by russotto ( 537200 ) on Monday September 06, 2010 @03:02PM (#33490730) Journal

          Commenting code isn't enough, it's just a small part of the design and documentation process. Comments are there to tie the code to the relevant part in your design document, which really is a part of programming people should put more effort into.

          It's been said for years, but it is almost never done. When it is done, it's most often (IME) done _after the fact_ because of some requirement to produce the paperwork. Perhaps it's time to give up on it. Is there a real reason for insisting on a design document, or is it just some sort of self-flagellation on the part of programmers?

          • Re:Comment your code (Score:4, Interesting)

            by Hooya ( 518216 ) on Monday September 06, 2010 @09:40PM (#33493954) Homepage

            I have tried implementing a 'design document' process for the better part of 10 years that I've been with this group. It's never gotten done. We came close about a year ago. Here's why it's I still try (while knowing that it'll never get done):

            There's a reason architects use blueprints.

          • Re: (Score:3, Interesting)

            by jgrahn ( 181062 )

            Commenting code isn't enough, it's just a small part of the design and documentation process. Comments are there to tie the code to the relevant part in your design document, which really is a part of programming people should put more effort into.

            It's been said for years, but it is almost never done. When it is done, it's most often (IME) done _after the fact_ because of some requirement to produce the paperwork. Perhaps it's time to give up on it. Is there a real reason for insisting on a design document

      • Re:Comment your code (Score:5, Informative)

        by TheLink ( 130905 ) on Monday September 06, 2010 @02:41PM (#33490496) Journal
        > As for the indents that people are talking about, tabs are more reasonable now than they used to be, but you're giving up screen space for them

        Why would you be giving up screen space with tabs? On most text editors for programming people can adjust the tabs to display as whatever indentation they want. So if someone wants to view tabs as 2 spaces and another prefers 4 and another prefers 8, they don't have to change anything in the code if their editors are already set up for that.

        The disadvantage of tabs is where you have some stuff that requires you to use spaces in (text string etc) and for some reason you want certain parts of it to align with your indents. Or you are mixing your indentation - spaces and tabs (try not to do that OK? ).
    • by Xtifr ( 1323 ) on Monday September 06, 2010 @02:39PM (#33490470) Homepage

      Put enough comments in your code so that five years from now you (and others) can remember what you indented [sic] the code to do.

      But not so many that you (or others) will find it more work than it's worth to change the comments when the code changes.

      I prefer code with no comments to code with actively misleading comments, and I hate code with no comments! :)

      • Re:Comment your code (Score:5, Interesting)

        by Coryoth ( 254751 ) on Monday September 06, 2010 @09:16PM (#33493830) Homepage Journal

        But not so many that you (or others) will find it more work than it's worth to change the comments when the code changes.

        I prefer code with no comments to code with actively misleading comments, and I hate code with no comments! :)

        The trick is that if you are writing comments describing what the code is intended to do, you can write those comments in something like JML [ucf.edu] or Frama-C [frama-c.com]'s ACSL. That was you can use ESC/Java2 and Junit, or Frama-C, to do your checking that the code does what you intended. You get two benefits: more rigorous checks on your code (including use of theorem provers from ESC/Java and Frama-C); if your documentation ever falls out of date with the code, you'll immediately get errors flagged.

    • Re: (Score:2, Insightful)

      This is the best, IMHO. I, too, have looked code and gone, "WTF was this idiot thinking???? ...Oh wait... that's my code."

      And agreed - dead comments have to be updated. I didn't always do it perfectly, but I pretty much got in the habit a few years ago of commenting as I go, right by the code in question. One of those times when it's good to be a bit verbose.

    • by Manip ( 656104 ) on Monday September 06, 2010 @02:41PM (#33490488)
      I could never find the correct degree of commenting. Didn't help that in school they made us comment in an idiotically verbose way to the point of "this is a for loop to find needle in haystack" and we lost marks if we failed to. My reaction to that level of stupidity was to lose interest in comments entirely which obviously later bit me in the butt.

      I really need to find some kind of "idiots guide to when to comment and when NOT to comment."
      • by sourcerror ( 1718066 ) on Monday September 06, 2010 @03:21PM (#33490948)

        Think of comments as an API documentation*. If something complicated is going on, I usually include several usage example as well. Just look at the documantation 3rd party libraries, and try to follow that granularity and style.

    • The problem is that it's easy to follow this rule and forget another important one: If the code you are writing needs a lot of comments, chances are you need to try a different solution, because you are trying one that has the complexity in the wrong places.

      The best code has enough comments to be understandable, but it also doesn't have anywhere near as many comments as there is code.

    • by DMiax ( 915735 ) on Monday September 06, 2010 @02:58PM (#33490688)

      Put enough comments in your code so that five years from now you (and others) can remember what you indented the code to do.

      I know, Python right?

      • Re: (Score:3, Insightful)

        by gringer ( 252588 )

        My current annoyance with python:

        1. Copy code from one section
        2. Paste code to another section
        3. Different indentation changes code function
        4. ...
        5. Bash head on keyboard
        • by Lotana ( 842533 ) on Monday September 06, 2010 @11:04PM (#33494398)

          Solution: Stop mindlessly copying and pasting.

          I lost track of the amount of code I've seen that is a straight duplicate from some area that does vaguely the same thing. Then all the variable names don't match the new context, comments are not applicable and assumptions are not necessarily correct. Doesn't matter what language it is written in.

          Of course the person that does it never bothered to look through it and only relied on compiler error messages to detect the obvious "not declared" errors. What ends up is a mess that is nearly guaranteed to have bugs.

          If tabbing the new pasted code into place forces you to actually read it and think about what you just did: then it is well worth it!

    • Re: (Score:3, Interesting)

      by SL Baur ( 19540 )

      Put enough comments in your code so that five years from now you (and others) can remember what you indented the code to do.

      /* This is hairy. We need to compute where the XEmacs binary was invoked
      from because temacs initialization requires it to find the lisp
      directories. The code that recomputes the path is guarded by the
      restarted flag. There are three possible paths I've found so far
      through this:

      temacs -- When running temacs for basic build stuff,

    • Re:Comment your code (Score:5, Interesting)

      by Thangodin ( 177516 ) <elentar AT sympatico DOT ca> on Monday September 06, 2010 @06:17PM (#33492622) Homepage

      If you are new to coding, don't be a bedroom programmer. You are no longer writing a 10,000 line app alone in your bedroom. You may be working on a million line app with a team. Change your habits accordingly. Learn to work with other people.

      Programming is one of those things that humans are not quite smart enough to do. This means you. Check your ego at the door. In the early 90's, IBM estimated that 80% of large projects in the industry (one million lines or more) were "abandoned in disgust". This should give you some idea of what you are up against.

      Come to work knowing what you are doing. This may mean cramming in your off hours. Don't say that you don't know how to do something. Say that you do and then learn it!

      Put in comments where they are needed, and maintain them. You will forget what you were doing within three months. The harder it was to code, the more you need the comments.

      Use descriptive variable names. Try to organize your data into conceptually simple variables where possible.

      If you have to complicate a mathematical formula by breaking it into sections appropriate for inner and outer loops, put the formula in the comments. It may even be worth putting in an ASCII diagram if you are working with geometry.

      If you can't see the bug, it's because you have become blind to the code. Get someone else to take a look. The mistake may be embarrassingly obvious to a new set of eyes.

      If speed is a factor, preprocess the data. Offload runtime cycles to preprocessing.

      Maintain an up to date user manual for all tools and apps. Add to it as you add features, update it as you update the features.

      Avoid magic numbers where possible, and put any magic numbers you do use into defines, again with descriptive names.

      If you can, avoid virtual methods and pointers in streamed objects. This way you can bulk load them and bulk write them. Indices often fast enough, or can be converted to pointers if need be after loading.

      If you have lots of booleans, consider a bit array.

      Try to write reusable code. Code for the general case when possible, but...

      Normalize your data and objects. Don't waste memory and time maintaining variables you don't need. Don't repeat yourself.

      Your key indexes should be integers, never strings. Yes, I have seen databases keyed on memo fields--they were tragically slow.

      If updating an existing project, get the client to sign off on what is not to be changed or fixed, and make certain that the QA department gets this list. Otherwise bugs will creep onto the list that you are not actually required to fix, expanding the scope of the project.

      Build test harnesses whenever you can which can be turned on with a simple switch. This will make regression testing a lot easier.

      • by erixm ( 1882824 ) on Tuesday September 07, 2010 @04:07AM (#33495898)

        Come to work knowing what you are doing. This may mean cramming in your off hours. Don't say that you don't know how to do something. Say that you do and then learn it!

        Please ignore that. Honesty is always better - and if your team doesn't welcome honesty, try to change the team's attitude. If you trust each other your results will be better. If you don't know how to do something, say you don't and THEN learn it.

    • Re: (Score:3, Informative)

      Actually, what will have happened in 5 years is that the code will have changed, but the original comment remains, so that the code now does something slightly different. And it will be hours of debugging fun to find out which is right, if any.
  • by msobkow ( 48369 ) on Monday September 06, 2010 @02:23PM (#33490298) Homepage Journal

    The truth is that the "hard" way of doing things is often more fun, because you have the challenge of learning a new tool or API. Plus sometimes it's actually easier in the long run because you've engineered a solution for the outer bounds conditions of scalability, so if your application takes off, it can handle the load.

    I guess the real issue is that you have to engineer a "good enough" solution rather than a "worst case" solution.

    • I'd like to add to this that one of classic reasons why someone writes an appllication is because they need program to do something, on the other hand, if you always find and use existing solutions, you end up not writing any but short bash scripts. (I speak from personal experience)
    • by amaupin ( 721551 )

      Also, doing something the "hard way" the first time often leads to a greater understanding and appreciation of the "easy way."

      Reading the article, I fail to see why I should avoid PIL for ImageMagick. In neither case is Linux going to just "do it" for me. And in either case I have to tell PIL or ImageMagick how to process my images, right?

      • Re: (Score:3, Insightful)

        by jellomizer ( 103300 )

        Well if you are coding professionally. You are wasting time going the hard route unless there is a real good reason to do such. Newbees want to show off that they can do all these things. Mature programmers know they can but if there is an easier way then go for it as it gets your project done faster and you look better to your boss who can give a rats ass on how you did it. Just as long as there isn't any consequences in the future.

    • by hedwards ( 940851 ) on Monday September 06, 2010 @02:35PM (#33490424)
      Eh, isn't that the basic difference between a programmer and an engineer? When I took my programming courses, there was a distinct focus on writing code with the smallest amount of new code possible, using preexisting libraries whenever possible and if there was any suspicion that the code might be useful later to split it off into a subroutine or method of some sort as done in the particular language. Sure it's a good idea to be able to write your own libraries and solutions, but it's a waste of time once you get to the point where you know how to do it. And generally using a library that's shared by other projects is much less likely that you're going to stumble on an undiscovered bugs with your program.
    • You might learn something from doing things the hard way, but all you'll achieve is a version #1. As we all know (or will learn) version #1 of pretty much everything should be thrown away and should NEVER see the light of a production server. However, timescales being what they are as soon as an application gets close to functional it gets snatched away and put live - no matter how ugly it is. After that, all you ever have time for is to patch the worst parts. Doing a complete rewrite from the ground up, to
    • by Morth ( 322218 )

      The problem is that you're far more likely to end up with crappy code. If you want to ask your user for a password, it's insanely much easier to do a system("stty -echo"); instead of learning the ioctls to accomplish the same thing, plus you get portability for free.

      I recently replaced a SMTP protocol implementation with a pipe to /usr/sbin/sendmail. Guess what? It worked much better.

  • Lesson #8 (Score:5, Insightful)

    by pedantic bore ( 740196 ) on Monday September 06, 2010 @02:25PM (#33490304)

    Don't ask for advice about programming on slashdot unless you have a pile of salt grains ready.

    • Re:Lesson #8 (Score:5, Insightful)

      by thoughtsatthemoment ( 1687848 ) on Monday September 06, 2010 @02:54PM (#33490636) Journal
      That applies to other sites as well. So many people are trying to preach than genuinely teach. The internet is great for seeking specifics, but for insight on programming, it has to come from within yourself.
      • by danieltdp ( 1287734 ) on Monday September 06, 2010 @05:12PM (#33492092)

        The reason are two fold:

        1) The amount of morons *always* exceeds the amount of experienced and reasonable people

        2) Usually, morons don't have a clue that they... well... are morons!

        I for one can assure you that I'm NOT a moron :-)

  • by Anonymous Coward on Monday September 06, 2010 @02:27PM (#33490324)

    Sometimes it's easier and faster to code from scratch than it is to use off-the shelf software - especially in the age of "frameworks".

    In that train of thought, its often better to toss and rewrite (or write new programs) than it is to extend existing programs.

    It's easier to implement a whole new framework than it is to convince your boss that writing anew is actually faster.

    • by Trepidity ( 597 ) <delirium-slashdot@@@hackish...org> on Monday September 06, 2010 @04:19PM (#33491610)

      Sometimes it's easier and faster to code from scratch than it is to use off-the shelf software - especially in the age of "frameworks".

      I like this take on it [yosefk.com]: redundancy is bad, but the primary way of avoiding redundancy, factoring things out into libraries or frameworks, introduces dependencies, which are also bad. Which is worse? Depends, but I think dependencies are worse in more cases than people believe. I personally like to depend on something only when it's a big enough chunk of code to be worth adding a dependency for, has a clean API, and has an active and interested maintainer.

  • by sphealey ( 2855 ) on Monday September 06, 2010 @02:33PM (#33490398)

    A database is not a bitbucket. Re-building basic database functionality in an external app is not a good idea. Applications, frameworks, languages come and go; data remains forever [1]. Business logic is part of the database. If you find yourself adding more and more "application servers" to get performance than you have a fundamental problem with your architecture (and probably a fundamental misunderstanding of how databases work). While it is not impossible to learn and implement good data management/database development practices using Microsoft tools, such a result is seldom seen in the wild.

    sPh

    [1] Per Tom Kyte of Oracle, whose first database job at the Department of Agriculture involved working with datasets stretching back to 1790.

    • by WarwickRyan ( 780794 ) on Monday September 06, 2010 @03:57PM (#33491346)

      > Business logic is part of the database.

      I used to think the same thing, but that was before I ever had to solve a no-trivial problem.

      What do I think now? Basically that business logic belongs in a domain layer, but that shouldn't mean that the database is treated like a black box. You should make use of constraints within the database server to ensure a base level of data consistancy. Default values (especially on auditing columns), correct datatypes, relationships, versioning and not-null constraints all belong within the database. Basically anything which can be supported without resorting to triggers or stored procedures.

      Databases are excellent at sorting and filtering data. A massive amount of engineering talent has been invested in shaving miliseconds off of their algorithms. So let your database handle that. Don't filter in the application layer and then start complaining about performance. Need more capacity? Cluster. Throw more databases at the problem. Not more application servers. Make sure they're running on properly specified physical hardware, built to best match the actual usage pattern of the database.

  • unless tcl/tk wont do the job

  • If you are writing a program that touches more than two persistent data stores, it is too complicated.

    I disagree. Is a program too complicated if it has 1. input, 2. output, and 3. logging? Is a program to prepare images for an online store too complicated if it reads 1. raw source images and 2. an overlay image and writes 3. finished images?

    If Linux can do it, you shouldn't.

    That'd be fine if we all ran Linux. But in an organization that already has to run Microsoft Access for other reasons, we have to take Windows into consideration. And I don't think Ted Dziuba was talking about just using Windows as a shell to run Linux in VirtualBox OSE either.

    Don't do image processing work with PIL unless you have proven that command-line ImageMagick won't do the job.

    Our programmer is far more experienced in Python than in bash, and if I felt like it, I could benchmark PIL against subprocess.Popen(['convert', ...]).

    if the physical machine is not the bottleneck, do not split the work to multiple physical machines.

    Yet PC game developers split a 4-player game across four PCs when one could do, and increasingly, PS3 and Xbox 360 game developers are following the same path.

    It is far more efficient to buy your way out of a performance problem than it is to rewrite software. When running your app on commodity hardware, don't expect anything better than commodity performance.

    If you are writing software to be used internally, sometimes springing for better hardware is worth it. But if you are writing software to distribute to the public, you can generally assume your customer has commodity hardware unless your software costs at least 1000 USD a seat.

  • I RTFA (Score:4, Informative)

    by Jorl17 ( 1716772 ) on Monday September 06, 2010 @02:36PM (#33490430)
    I just RTFA. It isn't that good. These aren't many tips and they also don't seem to be too specialized. Most of them are already known or predictable. I can say that I didn't learn anything from TFA.

    I think that anything that reads "___ things to know about ____" or similar gets instant hits on /.

    -1, Boring from me; hope it helps others.
  • by petes_PoV ( 912422 ) on Monday September 06, 2010 @02:36PM (#33490434)
    Sure, you can do all the superficial stuff with simple point and shoot. But I wish I'd known (before I started?) that to do anything beyond that meant diving deep and dirty into PHP, Javascript, CSS, DOM, and a whole lot more alphabetti spaghetti.

    And that's before you get into the really difficult stuff (that very few have managed to master) of getting a website that is easy to navigate and intuitive to use

  • by 93 Escort Wagon ( 326346 ) on Monday September 06, 2010 @02:41PM (#33490492)

    Don't assume that, even six months from now, you're going to remember why you did things a certain way.

    And the corollary: Don't assume you're going to be the one modifying the code a year or two from now.

    Either way: Add comments liberally. Even if you're a conservative.

  • by melted ( 227442 ) on Monday September 06, 2010 @02:46PM (#33490548) Homepage

    Do not make things super-modular and generic unless they 100% have to be. In 99.9% of the projects no one, including yourself, will use your stupid dependency injection, and logging / access control can be done just fine without AOP. Don't layer patterns where there's no need. Aim for the simplest possible design that will work. Don't overemphasize extensibility and flexibility, unless you KNOW you will need it, follow the YAGNI principle (you ain't gonna need it).

    • Re: (Score:3, Insightful)

      by Anonymous Coward

      (too lazy to log in)

      hear hear.

      i'm working in an over-architected codebase now and all the Design Patterns thrown in haven't done squat for making it flexible or modular,
      they've just made it obtuse.

  • by bogaboga ( 793279 ) on Monday September 06, 2010 @02:47PM (#33490562)

    "Modern Linux distributions are capable of a lot, and most hard problems are already solved for you. You just need to know where to look."

    First off, I must say this piece says a lot about the Linux ecosystem. Specifically that this system's documentation is anemic at best. Why won't we have something like:

    "What do you want to do?...with an associated answer...this kind of arrangement surely cannot hurt the Linux ecosystem.
     

  • by caywen ( 942955 ) on Monday September 06, 2010 @02:47PM (#33490564)

    You know, I find that as I get older, I am able to avoid overengineering things a lot better than when I was twenty something. There's nasty effect, though. I'm learning a lot less in depth about systems than I normally would.

    Overengineering is terrible for a project, but it often is highly educational.

  • One more tip (Score:3, Informative)

    by Posting=!Working ( 197779 ) on Monday September 06, 2010 @02:55PM (#33490660)

    Visual Basic - Don't. Just don't.

    It's always great to learn a language then have the company change it so drastically in the next version that all your knowledge of the language is useless. I don't believe it'll be the last time that happens either. I do know I will never bother to learn another MS programming language again.

    Good luck to all you C# programmers when they switch to C#.NET, or whatever they call the next one. Hope you like reading!

    • Re: (Score:3, Insightful)

      by radish ( 98371 )

      Right - but a real programmer realizes that languages always come and go, that the real skill is PROGRAMMING not C# or Java or C++ or Python or whatever. If you have a real understanding of the fundamentals then learning a new language is usually easy (and often kinda fun).

    • Re:One more tip (Score:5, Informative)

      by bertok ( 226922 ) on Monday September 06, 2010 @04:39PM (#33491794)

      Visual Basic - Don't. Just don't.

      It's always great to learn a language then have the company change it so drastically in the next version that all your knowledge of the language is useless. I don't believe it'll be the last time that happens either. I do know I will never bother to learn another MS programming language again.

      Good luck to all you C# programmers when they switch to C#.NET, or whatever they call the next one. Hope you like reading!

      C# is already .NET, there has never been any other version.

      And what about C++, hmm? That's a language that went from "C with classes" to a multi-paradigm language with a sprinkling of template mate-programming programming thrown in! The shift was so huge, in most compilers, the standard libraries have two versions, a legacy and a modern template version.

      I had to re-learn C++ several times. Some of the new features are so advanced, that not even all compilers support it. Things like "partial template function specialization" are only turning up now, 10 years after standardization. It's a language where I was shocked to learn that there were entire language features I wasn't even aware of after having used the language in production code for 20 years! That kind of thing has never happened to me before or since with any other language.

  • Yes, and no (Score:3, Informative)

    by drwho ( 4190 ) on Monday September 06, 2010 @03:03PM (#33490736) Homepage Journal

    Some oversimplified philosphy, some good hints. Programmers and SysAdmins who do a lot of resource management eventually become managers. This isn't neccessarily a bad thing, as the world needs more managers with extensive experience with that which they are managing, and the respect of those people they are managing. It's true that it's silly to adopt some software, technology or process just because it's new. But Ted seems to be resistant to any change, which is not good either. The problem with "don't fix it if it ain't broke" reasoning is..what do you do when it eventually breaks? This is a mistake made by many in process control / automation eniveronments: failure of a part which is so obsolete that it has become difficult and expensive to obtain a replacement. Just try to find a new motherboard with an ISA bus these days. Or a composite monitor. The same thing can happen with software and the OS..where are you going to find a guy who knows enough about that old Kaypro which was running some COBOL software on CP/M, which controlled the electroplating machinery? This is why companies have lifecycle management, so that the pain of switching to newer software / hardware comes with predictable cost and timetables instead of sudden, possibly prolonged unavailability and expensive, awkward, band-aid fixes.

    This flows into the idea of organizational amnesia, where important processes become lost. This is perhaps best illustrated by the US DoE forgetting how to make this secret substance called FOGBANK, which is a critical component of H-bombs. Upper management felt as though, because there was no need for additional H-bombs, the process was unimportant, and didn't take into account that H-bombs become (more) dangerous with advancing age, and eventually these needed to be replaced. It took considerable time and money to re-engineer FOGBANK.

    These are both examples of failure to consider that all equipment wears out, and failure to plan for long-term needs.

  • by Murdoch5 ( 1563847 ) on Monday September 06, 2010 @03:30PM (#33491066) Homepage
    Hey

    I know these might sound odd but hear me out. Start by trying to rewrite the basic library's. make your own printf, strcpy. strlen etc..... Write copies of your own link list and tree storage methods and above all really really start to understand how memory works.

    Another really really important thing that I have learned is stay FAR FAR away from OO programming until your really really comfortable in lower level languages. The reason is that to many students and beginners sit there trying to figure out why there variable started with value X and ended up with value Y only to find out that there object bashed some memory earlier on.

    Basically just grab a good C compiler, I mean C COMPILER, not C++, not C#, not F# and start to learn how all the functions you use on a dailiy basis work, it will give you new insight into why and how you can quickly avoid and fix problems when and before they happen. It's also important to get a really really good handle on using a CLI over a GUI, Stay away from Visual Studio and other simular compilers. Use GCC and CC and make sure you look at how LD is working and understand how compilers do optimizations and improvements to your own code. This post is taking about grabbing tool to do Image processing and preform functions that have working solutions. However taking the time to see how the solutions work and why they work will give you good insight into not only great code design but great programming methods. It might seem odd for me to suggest to a beginner to try and rewrite strcpy or strcmp, but once you see how they really work you'll be far less likely to make the simple mistakes that can ground your program / project from working. It's the same say with with a beginner figuring out how malloc works and where memory gets taken from and put to, all of these suggestions are coming from the way I learned to program in C and other languages.

    Feel free to throw any of these away or take any of them into your own programming adventure, but one thing is for sure. When you can figure out how the basic functions you use every day work it will save you hours and days of trouble shooting and leave you with a greater pallet of tools to use in the class room and on the job. I welcome and one who wants to add ideas to this post and attack it with there own view points.
    • by spiffmastercow ( 1001386 ) on Monday September 06, 2010 @03:54PM (#33491330)
      That's essentially what the K&R C book steps you through, and I'd say it's the best programming book ever written (or at least the best I've read). I don't get to do much in C these days, but the stuff I learned 10-15 years ago in C has made me a much better programmer. It's sad how programmers these days give you a blank stare when you ask if you passed something by value or reference.
  • by LihTox ( 754597 ) on Monday September 06, 2010 @03:43PM (#33491194)

    I'm in a different boat from most commenters here, I think, because I am a scientist writing simulations; some simluations run a long time and create a lot of data which would be costly to reproduce, and what I wish someone had told me early on was that I should comment my *data files*, not just my code. Each file should include the exact parameters used to create it, an explanation of what each column represents, and preferably there should be a way of knowing what version of your simulation code was used to create it. A couple of times in grad school I had toss out months of data after I discovered a bug in my code, and didn't know when the bug showed up and which data was affected by it.

    (I'd welcome other advice from simulationists too; I've never had an advisor who was particularly programming-savvy, even though programming was always a large part of my research, and so I always had to make it up as I went along.)

    • Re: (Score:3, Informative)

      by dch24 ( 904899 )
      I had the same experience. As the data collection evolved, I used the revision number (from the source tree) compiled into the code and embedded in each data file.

      The boss wanted everything in XML, since that was extensible, but then went halfway because raw images don't encode well in XML. So we maintained the dataset in XML and binary.

      But as a result, I was able to keep around all versions of the binary-to-xml converter in the current code base. With some unit tests, and some comments, it really helpe
    • Re: (Score:3, Insightful)

      Yep. I learnt that lesson too when recording astronomical observations for research. You must design your software to *automatically* put in *all* the relevant information - just in case you need it. Rely on a human to put it in and you get mistakes that take a huge amount of time to untangle (if at all possible, sometimes you just don't have enough information to deconflict bad human-recorded values). My general rule is, "Never lose information". Once information has been thrown away it becomes a huge effo
    • Re: (Score:3, Informative)

      by owlstead ( 636356 )

      Yes, and if you use units (and generally you do) then make it clear what units each parameter expects. I am in crypto and I am always guessing if things are in bits or bytes. In physics it is even more important - fortunately students of physics will probably be more inclined to describe the units they expect. Also, the names of the parameters are even more important than those in the source files. Basically, if you have e.g. a configuration file, it should be thought of as part of the user interface.

    • Re: (Score:3, Interesting)

      by B1ackDragon ( 543470 )
      Very much agreed, though I'm not a simulationist per se anymore (these days I just do all kinds of crazy things to large data sets, and need to remember what crazy things I did, and when, and as you said, what the output means!)

      Here's another tip, which I also thought about last time someone asked slashdot about scientific data organization: keep a wiki, and write down all the things you do (at least everything that isn't trivial to reproduce) there. Commands, paramaters used, input and output files crea
  • by daseinw ( 244962 ) on Monday September 06, 2010 @03:49PM (#33491258)

    we could not figure out whether the author was an incredibly elaborate troll or just a run-of-the-mill idiot.

    Reading this comment of his reminds me of something I read recently:
    Physicists stand on each other's shoulders. Engineers dig each other's graves.

    I've never understood why so many software developers feel the need to disparage one another in an attempt to prove their intelligence/superiority. There are plenty of tough problems out there and we all can learn something from one another, no? I've definitely been guilty of this in my tech career but lately I'm wondering more and more, why does the person who has a different solution always have to be an "idiot?" Why isn't he/she just someone who has a different take on solving this particular problem?

    Now, I'm not saying that engineers do this more than any other group but out of all of my friends (some of whom are doctors, lawyers, teachers, etc.) it certainly seems like a more common event among software developers.

    • by azmodean+1 ( 1328653 ) on Monday September 06, 2010 @05:07PM (#33492038)

      I think there are several factors that contribute to this:
      1. Programming is a very popular and easy to enter field.
      2. It's actually pretty easy to get by as a programmer without really understanding what you are doing.
      3. Regardless of how much you hear about it, modularity, reusability, and highly structured programming do not have good penetration in Software Engineering.
      4. Because of #3, it is all to easy for otherwise competent programmers to paint themselves into a corner and generate software with really messy architecture and/or implementation.
      5. Programmers OFTEN have to clean up after other programmers.

      So, due to #1 and #2, there actually are quite a number of really bad programmers running around.
      Due to #3 and #4, there are quite a number of otherwise decent programmers who produce working but unmaintainable code.
      Due to #5, most programmers have ample opportunity to experience a great deal of pain from other programmer's incompetence.
      Due to human nature, programmers tend to assume that all that bad code comes from #1 and #2 rather than #3 and #4.

      And more speculatively and unrelated to the above:
      6. Lots of programmers tend to hang out on Usenet, internet fora, mailing lists, and IRC, where harsh criticism is de rigeur, and internalize the habit of harsh criticism in their professional lives.

  • Version Control (Score:5, Insightful)

    by BluePeppers ( 1596987 ) <BluePeppers@@@archlinux...us> on Monday September 06, 2010 @03:59PM (#33491374)

    Put everything in version control. Everything. EVERYTHING!

    Well. You could skip /home, but I know a roll back of /etc has saved me a couple of times on config upgrades.

    Remember that once code is deleted, you can't get it back. However, version control changes that. Version control is one of the most vital tools for anyone developing/working with a computer.

    Oh and git rocks and stuff :)

  • LISP/Scheme (Score:5, Informative)

    by turgid ( 580780 ) on Monday September 06, 2010 @04:03PM (#33491424) Journal

    I wish I'd know about LISP 25 years ago. Stupid people told me it was "for processing lists." If only I'd known better. Functional programming gives you wings and a jet engine.

    I wish I hadn't paid too much attention to people with limited imaginations. Just because they're older, have more money and shout louder doesn't mean they are clever or wise.

    C++ is way over-rated but it's worth knowing because it's so widely used. Don't let it detract you from mastering C and learning scripting languages. Understanding object-oriented design is more important than knowing the latest trendy language.

    Objective-C.

    Just because software is Free/Open doesn't mean it's "cheap" and poor quality. I could have saved myself 2-3 years there.

    Ignore Windows and it will ignore you.

  • by fahrbot-bot ( 874524 ) on Monday September 06, 2010 @04:11PM (#33491528)
    I don't know if this is still around, but a long, long time ago, I got this, and nothing else, from the shell when it died:

    Assertion botch: This can't happen!

    Nice.

  • The Truth (Score:5, Insightful)

    by TheCount22 ( 952106 ) on Monday September 06, 2010 @04:13PM (#33491552)

    A few rules of thumb for a startup environment:

    1. Don't overengineer! Overengineering wastes time on things that may never be used. Features should be customer driven.

    2. Functions and methods should be as small as possible. You should make it an obsession to split methods and functions into the smallest possible components. Only then can you have good code reuse. Don't start thinking I will split it when I need it, you never will!

    3. Never ever reinvent the wheel. Reinventing things that exist is overengineering.

    4. Don't optimize ahead of time. When I say that I don't mean don't use a hash table instead of an array where it makes sense. I mean don't try to avoid exception handling or function calls or other minor optimizations. If it has an impact on readability don't do it. Optimization always comes last. Often you'll find there are only 1 or 2 "hotspots" in your code. If you spend time optimizing these "hotspots" after your application is built thats when you'll get the best return on your investment. Another gotcha with optimization is using technologies that can't deliver the level of performance you expect. You should test to make sure the underlying components you plan to use will perform as expected before you start coding.

    5. Don't cram as much code in a single statement as possible. Every compiler I know about today will produce identical code whether it's one statement or 5 statements. It makes it hard to read so don't do it!

    6. Allocate time for testing. No one writes perfect code.You want to give a good impression to your customer so don't skip this step.

    7. Make unit testing an obsession. Always add unit tests for new code, it reveals errors in your code. When you find a bug in your code add a unit test to test for it. If in the future someone decides to rewrite some function or method you wrote because it's not elegant enough they will not reintroduce old bugs.

    8. Don't rewrite code if possible. Refectoring is almost always easier and less error prone.

  • by SanityInAnarchy ( 655584 ) <ninja@slaphack.com> on Monday September 06, 2010 @04:20PM (#33491622) Journal

    If you are writing a program that touches more than two persistent data stores, it is too complicated.

    Others have already mentioned cases where multiple datastores make sense. A trivial example: One database to handle user data, another to handle blobs (image conversions, etc) -- bonus if the second store can do its own conversions; a third to handle logging -- that's already three, and that's before we start considering things like RESTful services, which can function as intelligent datastores of their own...

    If Linux can do it, you shouldn't.

    Unless you're not on Linux. And, specifically:

    Don't do image processing work with PIL unless you have proven that command-line ImageMagick won't do the job.

    If you're doing something that truly works as a shell script, and isn't part of a larger app, I agree. However, PIL likely performs better, and it removes the shell as an issue -- if you thought SQL injection was bad, wait till you have people exploiting your shell commands. You can do it safely, but why would you bother, when you've got libraries that accept Python (or Perl, or Ruby) native arguments, rather than forcing you to deal with commandline arguments? Why do you want to check return values, when you can have these native libraries throw exceptions?

    Parallelize When You Have To, Not When You Want To

    If you don't at least think about parallelization in the planning stage, it's going to be painful later on. It's easy to build a shared-nothing, stateless architecture and run it in a single-threaded way. It's hard to build a stateful web service with huge, heavyweight sessions, and then make it run on even two application servers in the future. Possible, but awkward, to say the least.

    For example, if you are doing web crawling, and you have not saturated the pipe to the internet, then it is not worth your time to use more servers.

    ...unless, maybe, it's CPU-bound? And this is odd to mention in a section about parallelization -- wouldn't slow servers be a prime candidate for some sort of parallelization, even on a single machine, even if it's evented?

    If you have a process running and you want it to be restarted automatically if it crashes, use Upstart.

    Cool, but it looks like Upstart is becoming a Maslow's Hammer for this guy. Tools like Nagios, Monit, and God exist for a reason -- one such reason is knowing when and why your processes are dying even if they're spread across a cluster.

    NoSQL is NotWorthIt

    People who have read my other posts likely know where I stand on this, but...

    Redis, even though it's an in-memory database, has a virtual memory feature, where you can cap the amount of RAM it uses and have it spill the data over to disk. So, I threw 75GB of data at it, giving it a healthy amount of physical memory to keep hot keys in...

    So you found out an in-memory database wasn't suitable when you have far more data than physical memory? Great test, there.

    Redis was an unknown quantity...

    Maybe so, but that wasn't terribly hard to guess.

    Yes, maybe things could have been different if I used Cassandra or MongoDB...

    So maybe you should've benchmarked a NoSQL database which is actually designed to solve the problem you're trying to solve? Just a thought.

    especially if something like PostgreSQL can do the same job.

    If PostgreSQL could do the same job, the current generation of NoSQL databases wouldn't have been invented. Unless something's changed, PostgreSQL can't scale beyond a single machine for writes, unless you deliberately shard at the application layer, which would violate his rule about multiple datastores, wouldn't it?

    It seems like the attitude is to no

  • by SL Baur ( 19540 ) <steve@xemacs.org> on Monday September 06, 2010 @05:02PM (#33492000) Homepage Journal

    Don't do image processing work with PIL unless you have proven that command-line ImageMagick won't do the job.

    I think the worst mistake I made as Mr. XEmacs was attempting to unify our graphics support to call ImageMagick libraries instead of the custom stuff we were using (and later restored when ImageMagick was backed out).

    Does it work any better now? The last time I looked at display(1) a couple of years ago, it still wasn't close to long lost and patent challenged xv(1) that got shut down by the GIF patent war.

BLISS is ignorance.

Working...