Live data from Hacker News

Old-school programming techniques you probably don't miss

computerworld.com

31–33 of 33 posts

Re: Old-school programming techniques you probably don't miss

#31
post #28
post #24

Earlier quoted context omitted.

OK, I'll bite. How do you do it in one loop?

Two loops: (I'm sure I'll get this wrong.) for (int ii = 0; ii arr[jj+1]) { swap(arr[jj], arr[jj+1]); } } } One loop: int ii, jj; for (ii = 0, jj = 0; ii Unreadable, but it's one loop. EDIT: use code formatting, oops. EDIT 2: add proper conditional for jj update instead of jj = jj + 1.

Not really bubble-sort-specific; you can make any pair of loops into a single loop that way.

  for (set up initial conditions for both loops;
       check the outer loop termination condition;
       if the inner loop is done reset the inner loop and advance the outer loop,
       if the inner loop is not done advance the inner loop) {
    // do the inside of the loop
  }

Re: Old-school programming techniques you probably don't miss

#32
post #16
post #9

This kinda misses the point of Hungarian. I don't care that two variables are both floats, the compiler will keep track of types for me. I do care very much that I'm not trying to add a width to a height, for example. Hungarian can help with that in languages like C and Python.

In principle we ought to be able to treat width and height as two separate subtypes of some numeric type and have the compiler generate an error if we add them together. But unfortunately today's common languages like C and Java don't support that. Here is the original Hungarian notation article by Charles Simonyi. http://msdn.microsoft.com/en-us/library/aa260976.aspx

When I was forced to learn Ada for my current job, I was skeptical that it would be a good experience. But I must admit, I like being able to declare things in feet and meters and have the compiler complain when I try to add them.

But it's overbalanced by the sheer amount of effort necessary to make the compiler shut up when I do want to do that. Something like half my Ada code winds up as inane type conversions. I find myself very hesitant declare things in feet and square feet and milliwatts and meters because I know what a phenominal amount of work I am making for myself. Writing in Ada is a strange exercise in type engineering, trying to get exactly the amount of error-checking that I want out of the compiler without distracting myself too much from the actual problem I'm trying to solve. I'm rarely successful. I once recently spent four hours developing an algorithm in Perl, and then--with it understood and debugged--two days translating it into Ada. Most of that time was spent making reassuring gestures toward the compiler.

Then again, the extreme permissiveness of a language like Perl has its own drawbacks. I recently lost a whole day to a function I thought was expecting named parameters (but which wasn't). Ubiquitous default values and silent conversions are nice when you're expecting them and brutal when you aren't; to write efficiently, I must sprinkle die everywhere. And that's the catch: I'm not persuaded that truckloads of 'turn error-checking on' incantations are an improvement over truckloads of 'turn error-checking off'. It's inane code either way.

When you get right down to it, one size doesn't fit all, even within the same program. Ideally, I'd like a language that let me 'tag' variables and functions with types or units or associations, and let me decide when and what to check by default in what contexts. I'd love a language that stopped me from setting a variable in feet to one in meters, but also gave me a way to say "don't check units on this line--it's a formula--but please still check my pointer indirection". Alas, between building Perl up, quieting Ada down, templating C++, or simply building a baroque OO hierarchy in Java, nothing I've used seems really robust and flexible enough to serve this purpose well.

Re: Old-school programming techniques you probably don't miss

#33
post #28
post #24

Earlier quoted context omitted.

OK, I'll bite. How do you do it in one loop?

Two loops: (I'm sure I'll get this wrong.) for (int ii = 0; ii arr[jj+1]) { swap(arr[jj], arr[jj+1]); } } } One loop: int ii, jj; for (ii = 0, jj = 0; ii Unreadable, but it's one loop. EDIT: use code formatting, oops. EDIT 2: add proper conditional for jj update instead of jj = jj + 1.

At least one of those loops in the 2-loop version should be backwards... :)
Post reply on HN