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


Forgot your password?
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:
  • 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

  • Don't program in C if Python will do the job.

    But in a lot of cases, Python does not do the job. It doesn't do the job on iOS because Apple has explicitly banned everything but Objective-C++. It doesn't do the job on Xbox 360 or Windows Phone 7 because IronPython uses Reflection.Emit, and the version of .NET used by XNA doesn't support Reflection.Emit. And it doesn't do the job on Nintendo DS because the runtime uses up a lot of the available 4 MB of RAM.

  • 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.

  • 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? ).
  • Re:xargs mapreduce? (Score:4, Informative)

    by tepples ( 727027 ) <tepples@gmail.BOHRcom minus physicist> on Monday September 06, 2010 @02:43PM (#33490522) Homepage Journal

    I guess I'm an idiot, but.. err... did someone REALLY use mapreduce to solve an argument passing problem (the domain of xargs), or is the writing just shit?

    xargs and its successor GNU parallel [wikipedia.org] implement the "map" part of MapReduce.

  • 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!

  • 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 jpate ( 1356395 ) on Monday September 06, 2010 @03:19PM (#33490922) Homepage
  • by costing ( 748101 ) on Monday September 06, 2010 @03:38PM (#33491150) Homepage

    whatis apropos

  • 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.


    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 Trepidity ( 597 ) <delirium-slashdo ... g ['kis' in gap]> 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.

  • 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.

  • by dch24 ( 904899 ) on Monday September 06, 2010 @05:08PM (#33492048) Journal
    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 helped explain ancient data.

    I enjoyed reading your comment. Thanks.
  • by Joe Tie. ( 567096 ) on Monday September 06, 2010 @05:41PM (#33492366)
    At some point at least, centos didn't. Or possibly it shipped with it, but in a useless state. I remember we used to get calls about it fairly frequently. That was a hell of a long time ago though.
  • by owlstead ( 636356 ) on Monday September 06, 2010 @08:13PM (#33493420)

    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.

  • by Kludge ( 13653 ) on Monday September 06, 2010 @09:46PM (#33494020)

    Hell, I got an N900 6 months ago, and it's already EOL'd as far as updates to the OS are concerned.

    I suppose I could wait till there's a port of Android or something, because the three coders on the project are doing a fine job, in less than a year I'll have the same functionality as a 3210.

    Or you can read a little farther and see that upgrades are already available: http://en.wikipedia.org/wiki/MeeGo [wikipedia.org]

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

    by WolfWithoutAClause ( 162946 ) on Monday September 06, 2010 @10:58PM (#33494370) Homepage
    No, the comments above would explain that we're trying to do, e.g. find a needle to sew with, and the comments around the data structure definition would explain that we use a hashtable to speed up searching for ... The point *isn't* simply to do

    // add 4 to y
    x = y + 4;

    it's more like

    // we need to calculate the x coordinate, it's equal to y to be on diagonal, but add 4 due to border width
    x = y+4;

    So you explain *what* you're doing in HIGH LEVEL terms, and set CONTEXT. And you don't comment each line, you comment each group of lines that do one thing.

    And I also disagree with your 'despise' thing. It's very, very rare that code is over commented, and in most cases failing to correct comments helps create bugs, because it shows you weren't able to understand the code well enough to explain it to others, chances are there's a bug there goes way up. I also find that after I've written code, then's a good time to read it over and comment it. I find lots of bugs that way, and the code ends up much better. Not doing that wastes time in the long run because you'll find the bugs the hard way.
  • by selven ( 1556643 ) on Tuesday September 07, 2010 @01:45AM (#33495252)

    The code in question (9 lines actually) is:

    private int variable;
    public void setVariable (int val)
      variable = val;
    public int getVariable()
      return variable;

    Ironically, making your code less object oriented (ie. screw encapsulation) fixes this problem.

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

    by EsbenMoseHansen ( 731150 ) on Tuesday September 07, 2010 @05:11AM (#33496154) Homepage
    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.
  • Re:Comment your code (Score:3, Informative)

    by Coryoth ( 254751 ) on Tuesday September 07, 2010 @09:30PM (#33504640) Homepage Journal

    I really think that means that you need to become better acquainted with those tools. specifying what you intend to happen is a lot easier than specifying how to do it. The first is a specification, the second is an implementation. Consider, I can specify a sqrt function by simply saying the result squared should be within some error tolerance of the input; that is a long way from writing an implementation of a square root function. Likewise, I can specify a sort function (the output list should contain exactly the same elements as the input list, and they should now be in order with respect to a comparison operator) without ever doing anything as complicated as actually implementing quicksort, or mergesort, or heapsort or ... Try looking at the tools and what they can do and you'll satrt to get the idea.

God helps them that themselves. -- Benjamin Franklin, "Poor Richard's Almanac"