Slashdot Mirror


Old-School Coding Techniques You May Not Miss

CWmike writes "Despite its complexity, the software development process has gotten better over the years. 'Mature' programmers remember manual intervention and hand-tuning. Today's dev tools automatically perform complex functions that once had to be written explicitly. And most developers are glad of it. Yet, young whippersnappers may not even be aware that we old fogies had to do these things manually. Esther Schindler asked several longtime developers for their top old-school programming headaches and added many of her own to boot. Working with punch cards? Hungarian notation?"

19 of 731 comments (clear)

  1. Some, not all... by bsDaemon · · Score: 5, Insightful

    Some of those are obnoxious and good to see them gone. Others, not so much. For instance, sorting/searching algorithms, data structures, etc. Don't they still make you code these things in school? Isn't it good to know how they work and why?

    On the other hand, yeah... fuck punch cards.

    1. Re:Some, not all... by Blakey+Rat · · Score: 5, Interesting

      I did a ton of work in THINK C 5 on Mac OS 7. Programming in C on a computer with no memory protection is something I never want to experience again. Misplace a single character, and it's reboot time-- for the 13th time today.

      What's *really* weird is that at the time I didn't think that was particularly strange or difficult. It was just the way things were.

    2. Re:Some, not all... by SanityInAnarchy · · Score: 5, Insightful

      any programmer who can't do a list, hash table, bubble sort, or btree at the drop of a hat ought to be kicked out of the industry.

      Why?

      Lists, hash tables, and sorting is already built in to many languages, including my language of choice. The rest, I can easily find in a library.

      When performance starts to matter, and my profiling tool indicates that the sorting algorithm is to blame, then I'll consider using an alternate algorithm. But even then, there's a fair chance I'll leave it alone and buy more hardware -- see, the built-in sorting algorithm is in C. Therefore, to beat it, it has to be really inappropriate, or I have to also write that algorithm in C.

      It's far more important that I know the performance quirks of my language of choice -- for instance, string interpolation is faster than any sort of string concatenator, which is faster than straight-up string concatenation ('foo' + 'bar').

      And it's far more important that I know when to optimize.

      Now, any programmer who couldn't do these at all should be kicked out of the industry. I could very likely code one quickly from the Wikipedia article on the subject. But by and large, the article is right -- there's a vast majority of places where these just don't matter anymore.

      Not that there's nowhere they matter at all -- there are still places where asm is required. They're just a tiny minority these days.

      --
      Don't thank God, thank a doctor!
    3. Re:Some, not all... by Ruie · · Score: 5, Insightful

      any programmer who can't do a list, hash table, bubble sort, or btree at the drop of a hat ought to be kicked out of the industry.

      Why?

      Because if these well known tasks are difficult for them their job title is really typist, not programmer. The challenge is not to write bubble sort day in and day out, but being several levels above that so it is as easy as computing six times seven or reading road signs.

    4. Re:Some, not all... by Unoriginal_Nickname · · Score: 5, Insightful

      I'll agree with you for most of what you said, but I disagree that programmers should learn to implement sorting algorithms. Unless they're doing serious research on the subject it's doubtful that Joe Programmer is going to be whipping up a sorting algorithm that's better than the one provided.

      What you're suggesting here isn't like a mathematician not understanding calculus. It's more like a mathematician only having pi memorized to the 8th decimal. I see zero value in learning to parrot quicksort, especially since the information is easily obtained and the implementation you use is almost certainly as fast as is possible (assuming you aren't Abrash).

    5. Re:Some, not all... by Garridan · · Score: 5, Insightful

      Recently, I had a colleague ask me what sorting algorithm he should use in the inner loop of some algorithm he was implementing. Most CS majors I've talked to just blurt out "QUICKSORT!" without thought. Ok, that's got an average runtime of nlg(n). After about an hour of discussion and analysis, we came up with an algorithm that ran in sub-linear time. Now's the time for the CS kids to blurt, "ZOMG, but you can't sort in less than O(nlg(n)!" Ah, but you can, if you know what your input is going to look like.

      When a function gets executed billions or trillions of times, it's worth optimizing. Often times, doubling the speed of a deep internal function does nothing -- other times, it can cut the runtime of your program in half. I come from a mathematical background, and I do lots of computation. Often times, it can take a year or more to solve a problem with a quick implementation. Spend a few weeks optimizing it, and you might be able to solve the problem in a few hours.

      There is no substitute for analyzing your code. And I do mean, sitting down with a writing implement and a blank surface, and tracing through the algorithm. Then, profiling the code and hammering down hotspots. And then, take a page out of Knuth's book -- throw the code away, and write it again.

    6. Re:Some, not all... by Anonymous Coward · · Score: 5, Insightful

      *different* AC

      Why, why, why do people get SO offended when you tell them they have to learn computers to be good at computers?

      People expect to learn engineering to be a mechanic. To study biology if they want to be a surgeon. Hell, to read a cookbook just to learn how to cook.

      But answer "How do I program?" with "Well, there's this manual, see..." and you get "Elitist! Elitist! Hey everybody, come see the arrogant condescending elitist who's persecuting me! Come and see the violence inherent in the sys-teeeem!"

      Fine then, let's start telling everybody it's magic. Get some chicken bones and some goat's blood and some black candles...

    7. Re:Some, not all... by 16Chapel · · Score: 5, Insightful

      Number of times I had to implement sorting algorithms for my degree: 3

      Number of times I've had to implement sorting algorithms in my 10 year career: 0

      They make good teaching exercises, but any programmer in my team who wasted time building their own sorting algorithms rather than using a library function, would get a few sharp words about efficiency.

  2. Re:Hungarian Notation by smellotron · · Score: 5, Informative

    And the language type is rarely interesting- I want to know that the variable outsideTemp holds degrees farenheit, not that it's an integer. But Hungarian doesn't tell me that

    Good Hungarian notation does exactly that, actually. Check out Apps Hungarian, which encodes the semantic type of the data, rather than the language-level data type.

    Of course stupid Hungarian notation is stupid. Stupid anything is stupid. Problem is, most people don't hear about the right approach.

  3. Yes, I'm old by QuantumG · · Score: 5, Insightful

    * Sorting algorithms

    If you don't know them, you're not a programmer. If you don't ever implement them, you're likely shipping more library code than application code.

    * Creating your own GUIs

    Umm.. well actually..

    * GO TO and spaghetti code

    goto is considered harmful, but it doesn't mean it isn't useful. Spaghetti code, yeah, that's the norm.

    * Manual multithreading

    All the time. select() is your friend, learn it.

    * Self-modifying code

    Yup, I actually write asm code.. plus he mentions "modifying the code while it's running".. if you can't do that, you shouldn't be wielding a debugger, edit and continue, my ass.

    * Memory management

    Yeah, garbage collection is cheap and ubiquitous, and I'm one of the few people that has used C++ garbage collection libraries in serious projects.. that said, I've written my own implementations of malloc/free/realloc and gotten better memory performance. It's what real programmers do to make 64 gig of RAM enough for anyone.

    * Working with punch cards

    Meh, I'm not that old. But when I was a kid I wrote a lot of:

    100 DATA 96,72,34,87,232,37,49,82,35,47,236,71,231,234,207,102,37,85,43,78,45,26,58,35,3
    110 DATA 32,154,136,72,131,134,207,102,37,185,43,78,45,26,58,35,3,82,207,34,78,23,68,127

    on the C64.

    * Math and date conversions

    Every day.

    * Hungarian notation

    Every day. How about we throw in some reverse polish notation too.. get a Polka going.

    * Making code run faster

    Every fucking day. If you don't do this then you're a dweeb who might as well be coding in php.

    * Being patient

    "Hey, we had a crash 42 hours into the run, can you take a look?"
    "Sure, it'll take me about 120 hours to get to it with a debug build."

    --
    How we know is more important than what we know.
  4. radio in the computer case by bcrowell · · Score: 5, Interesting

    Circa 1984, when I did summer programming jobs at Digital Research (purveyors of CP/M), one of the programmers there showed me how you could put a transistor radio inside the case of your computer. You could tell what the computer was doing by listing to the sounds it picked up via the RF emissions from the computer. For instance, it would go into a certain loop, and you could tell because the radio would buzz like a fly.

    Documentation was a lot harder to come by. If you wanted the documentation for X11, you could go to a big bookstore like Cody's in Berkeley, and they would have it in multiple hardcover volumes. Each volume was very expensive. The BSD documentation was available in the computer labs at UC Berkeley in the form of 6-foot-wide trays of printouts. (Unix man pages existed too, but since you were using an ADM3A terminal, it was often more convenient to walk over to the hardcopy.)

    On the early microcomputers, there was no toolchain for programming other than MS BASIC in ROM. Assemblers and compilers didn't exist. Since BASIC was slow, if you wanted to write a fast program, you had to code it on paper in assembler and translate it by hand into machine code. But then in order to run your machine code, you were stuck because there was no actual operating system that would allow you to load it into memory from a peripheral such as a cassette tape drive. So you would first convert the machine code to a string of bytes expressed in decimal, and then write a BASIC program that would do a dummy assignment into a string variable like 10 A$="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx". Then you would write self-modifying code in BASIC that would find the location where the string literal "xxx...." was stored, and overwrite it with your machine code. So now if you gave the LIST command, it would display the program on the screen, with the string literal displayed as goofy unprintable characters. Then you would code the program so it would execute the machine code stored at the address of the variable A$. Finally you'd save the program onto cassette.

  5. swapping two values without a temporary variable by domulys · · Score: 5, Interesting

    x = x xor y
    y = x xor y
    x = x xor y

    Now you know!

  6. Re:Fortran implicit integers by Geirzinho · · Score: 5, Informative

    Nonsense, it's simply because i - n commonly is used to denote integer variables (sum x_i from 1 to n) i mathematical notation. This is a practice dating back at least to Gauss.

  7. True story by Moraelin · · Score: 5, Interesting

    Let me tell you a true story to illustrate why I think people should still learn that stuff.

    ACT I

    So at one point I'm in a room with what looks like two particularly unproductive Wallys. Though it's probably unfair to call both Wally, since at least one looks like the hard working kind... he just makes as much progress as a courier on a treadmill.

    So Wally 1 keeps clicking and staring at the screen all week and spewing things like "Unbelievable!" every 5 minutes. My curiosity gets the better of me and I ask what's happening.

    "Look at this," goes Wally 1, and I indeed move over to see him toiling in the debugger through a Hashtable with String keys. He's looking at its bucket array, to be precise. "Java is broken! I added a new value with the same hash value for the key, and it just replaced my old one! Look, my old value was here, and now it's the new one!"

    "Oh yes, we had that bug too at the former company I worked for," chimes in Wally 2. "We had to set the capacity manually to avoid it."

    I clench my teeth to stop myself from screaming.

    "Hmm," I play along, "expand that 'next' node, please."

    "No, you don't understand, my value was here and now there's this other key there."

    "Yes, but I want to see what's in that 'next' node, please."

    So he clicks on it and goes, "Oh... There it is..."

    Turns out that neither of them had the faintest fucking clue what a hash table is, or for that matter what a linked list is. They looked at its hash bucket and expected nothing deeper than that. And, I'm told, at least one of them had been in a project where they actually coded workarounds (that can't possibly do any difference, too!) for its normal operation.

    ACT II

    So I'm consulting at another project and essentially they use a HashMap with string keys too. Except they created their own key objects, nothing more than wrappers around a String, and with their own convoluted and IMHO suboptimal hash value calculation too. Hmm, they must have had a good reason, but I ask someone.

    "Oh," he goes, "we ran into a Java bug. You can see it in the debugger. You'd add a new value whose key has the same hash value and it replaces yours in the array. So Ted came up with an own hash value, so it doesn't happen any more."

    Ted was their architect, btw. There were easily over 20 of them merry retards in that project, including an architect, and neither of them understood:

    A) that that's the way a hash table works, and more importantly

    B) that it still worked that way even with Ted's idiotic workaround. It's mathematically impossible to code a hash there which doesn't cause the same collisions anyway, and sure enough Ted's produced them too.

    ACT III

    I'm talking to yet another project's architect, this time a framework, and, sure enough...

    "Oh yeah, that's the workaround for a bug they found in project XYZ. See, Java's HashMap has a bug. It replaces your old value when you have a hash collision in the key."

    AAARGH!

    So I'm guessing it would still be useful if more people understood these things. We're not just talking abstract complaints about cargo-cult programming without understanding it. We're talking people and sometimes whole teams who ended up debugging into it when they had some completely unrelated bug, and spent time on it. And then spent more time coding "workarounds" which can't possibly even make any difference. And then spent more time fixing the actual bug they had in the first place.

    --
    A polar bear is a cartesian bear after a coordinate transform.
    1. Re:True story by fractoid · · Score: 5, Insightful

      My mother, who was programming before a fair few of us (including me) were born, once told me this: If you think you've found a bug in a compiler, or an operating system, or a programming language, or a well-known commonly used library... you're wrong.

      Of course, this doesn't hold true 100% of the time, especially when you're pushing the limits of new versions of large 3rd party libraries, but when one is just starting to program (and hence using very well known, well tested libraries and code) it's true 99.99% of the time.

      (Oh, btw, I love your sig. Makes me laugh every time. :)

      --
      Rampant carbon sequestration destroyed the Dinosaurs' tropical paradise. I'm here to help repair the damage.
  8. OO isn't even different. by jd · · Score: 5, Insightful

    There is no practical difference between OO code and structured code. The article assumed structured code means goto and gosub, but any Real Programmer knows that procedures (which are just gosubs by name rather than address) are still structured programming.

    So what's OO? Each class is just a bunch of functions and procedures, with one entry point and one exit point for each - your standard structured programming methodology. The fact that there are different classes makes no difference. Calls between classes don't change the nature of a class any more than pipes between programs change the nature of programs.

    I wasn't impressed by other claims, either. Garbage collection is still a major headache in coding, which is why there are so many debugging mallocs and so many re-implementations of malloc() for specialist purposes. Memory leaks are still far, far too common - indeed they're probably the number 1 cause of crashes these days.

    Pointer arithmetic? Still very very common. If you want to access data in an internal database quickly, you don't use SQL. You use a hash lookup and offset your pointer.

    Sorts? Who the hell uses a sort library? Sort libraries are necessarily generic, but applications often need to be efficient. Particularly if they're real-time or HPC. Even mundane programmers would not dream of using a generic library that includes sorts they'll never refer to in, say, an e-mail client or a game. They'll write their own.

    One of the reasons people will choose a malloc() like hoard, or an accelerated library like liboil is that the standard stuff is crappy for anything but doing standard stuff. This isn't the fault of the glibc folks, it's the fault of computers for not being infinitely fast and the fault of code not being absolutely identical between tasks.

    The reason a lot of these rules were developed was that you needed to be able to write reusable code that also had a high degree of correctness. Today, you STILL need to be able to write reusable code that also has a high degree of correctness. If anything, the need for correctness has increased as security flaws become all the more easily exploited, and the need for reusability has increased as code bases are often just too large to be refactored on every version. (Reusability is just as important between versions as it is between programs - a thing coders often forget, forcing horrible API and ABI breakages.)

    The reason that software today is really no better, stability-wise, than it was 15-30 years ago is that new coders think they can ignore the old lessons because they're "doing something different", only to learn later on that really they aren't.

    --
    It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
  9. And more cargo-cultism by Moraelin · · Score: 5, Funny

    And a few more examples of cargo-cultism, from people who were untrained to understand what they're doing, but someone thought it was ok because the Java standard library does it for them anyway.

    1. The same Wally 1 from the previous story had written basically this method:

    public static void nuller(String x) {
        x = null;
    }

    Then he called it like this, to try to get around an immutable field in an object. Let's say we have an object called Name, which has an immutable String. So you create it with that string and can't change it afterwards. You have a getName() but not a setName() on it. So he tried to do essentially:

    Name name = new Name("John Doe");
    nuller(name.getName());

    I understand that he worked a week on trying to debug into why it doesn't work, until he asked for help.

    2. From Ted's aforementioned project:

    So they used the wrapper classes like Integer or Character all over the place instead of int or char. This was back in Java 1.3 times too, so there was no automatic boxing and unboxing. The whole code was a mess of getting the values boxed as parameters, unboxing them, doing some maths, boxing the result. Lather, rinse, repeat.

    I ask what that's all about.

    "Oh, that's a clever optimization Ted came up with. See, if you have the normal int as a parameter, Java copies the whole integer on the stack. But if you use Integer it only copies a pointer to it."

    AAARGH!

    --
    A polar bear is a cartesian bear after a coordinate transform.
  10. Premature optimizations by IntentionalStance · · Score: 5, Informative

    This is one of my favourite quotes:

    "The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet." - Michael A. Jackson

    That being said, when I hit the experts only situation I can usually get 2 orders of magnitude improvement in speed. I just then have to spend the time to document the hell out of it so that the next poor bastard who maintains the code can understand what on earth I've done. Especially given that all too often I am this poor bastard.

  11. Re:Ya I would compare it to long division by CrashandDie · · Score: 5, Funny

    I'd rather do it by hand. I'd love to see you divide a pizza in 6 using only your head.