Saturday, April 14, 2012

Do Have A Cow, Man!

It looks like I've got another "old fart" programmer rant here.  Josh On Design has an open letter to language designers in which he urges them to kill a few of what he feels are sacred cows of programming language design.

Some of his points are ones that I can't disagree with (type systems, garbage collection, extending the syntax), but his points 1, 2 and 4 stick in my craw

Cow #1 is "stop storing source code as ASCII files on disk".
Cow #2 is "use an IDE that is more than a text editor"
Cow #4 is "stop using whitespace or indention or braces styles"

For #1 he suggests storing code in XML/JSON or a database, and storing the code structure, along with any metadata, and non-text resources together.  This is not a bad idea, but it seems to gloss over one detail - a programmer will need to read the code to understand it, so it will end up being displayed as text in the end, even assuming it's not XML.  His point is that once the structure of the code is set, having a compiler/interpreter extract that structure every time is wasteful.  It is, but it gives the programmer great flexibility.  The only thing like what he suggests that I can imagine is something like the visual programming languages that represent the constructs as icons with slots for the details, like a loop is an arrowed circle with the start, end, and increment values inside the circle.  But what if you need to change from a loop to a recursive call?  You would need to somehow remove the loop icon and replace it with another icon (drag&drop?  emacs-like ctrl-meta-bucky keys?) and fill in the recursion endpoint and recursive calls.  And you'd have to find a set of symbols that would be clear to all programmers, which is not an easy task.  The great benefit of written languages is that they can carry a lot of meaning in a compact form.

For #2, he promotes requiring an IDE, since the source code would not be in a pure text format.  IDEs are great tools - I was reminded of this recent;y in a class where Eclipse was being used, and the auto-import feature for Java code was really useful.  But if the code requires an IDE to even look at it, you are adding complications - the language structure is now tied to the IDE understanding it, or you get incorrect rendering.  Then you must wait for the IDE developers to update their code before you can safely work on your code.  This seems a bad idea, especially if the IDEs are commercial tools, where corporate interests will have undue influence on the process.  I was distressed to hear, years ago, that a C++ feature was misimplemented in the official version because one of the corporate members of the standards committee did not want to be forced to fix their broken extension of C++, and ramrodded their version into the language.  Now imagine something similar, but where a good feature is rejected because a corporate member doesn't want to update their toolset!

Point #4 is superficially on target.  Arguments over brace style and how many spaces a tab should be are probably the least useful, and most heated, disagreements in software.  However, they are underlaid with a critical point - we need to understand the code to work on it, and different people find different layouts more suited to their mental models.  But the point is a bit of a strawman - there are already tools to adjust the layout to suit - store the code in one format, and have the repository filter it to your favorite style on checkout so you see it in the style you prefer.

Basically, the point of source code is to provide the programmer with an easy-to-understand format.  We have lots of computing power now, so why not use that to deduce the details, instead of making the human do the drudgework - compilation/interpretation can be done from the text much faster then understanding the code intent from a complex layout.

Now, it is still a good idea to perhaps save an intermediate step in a non-human-readable form, like Java class files or Python .pyc files, and there is always room for better ways to organize the source code of a project and its libraries, but assuming that one-size-fits-all is almost certainly going to fail.




Friday, April 13, 2012

The Circle Of Life

One of the funnier things about this profession is how so many things are cyclical.  Language mavens are fond of saying that every programming language eventually turns into a poor copy of Lisp, and every 10 years or so there is another format for encoding data so that the machines will have some ideas of how to process it (ASN.1 was XML before XML was born)

So I was tickled to read about Taco Bell Programming, where Ted Dziuba describes how to do web crawling and MapReduce with UNIX utilities.  It rang true, especially given the current situation at The Job, where new tech is being enthroned.  Then I found Mike The Coder's post about his reaction and Ted's response, which was even better.  I find new things about the OS every time I look, and there are great ways to do most tasks already in place.  But every generation needs to invent its own set of tools before it learns that much of what they want is already there,

It's almost like the end of The Wizard of Oz, where Glinda tells Dorothy that she would not have believed that the ruby slippers would take her home before she experienced the magic in Oz.

Heck, given the number of flying monkey's I've worked with, that's more apt that I care to think about.....

Thursday, April 12, 2012

Why We Code (again)

(As opposed to Why We Fight)

I've always felt that there was a unique property of writing code that was not found in other professions - getting in the Zone, seeing the data in your mind, making a machine do your bidding.  It's something that I always like when I get the chance to write new code (a rare occurrence these days).  Debugging provides the thrill of the hunt, as an alternative to pure creation, for variety.

So I was greatly pleased to find someone else who considers himself Lucky to be a Programmer

Gustavo covers much of the same ideas that I have felt, and I'm heartened that an apparently younger programmer (or at least newer programmer) is still finding the same joys in the work.





Friday, March 23, 2012

I Can't Handle The Truth, Apparently

What a day.  After spending almost three weeks digging around a test system trying to find the cause of a communications failure, someone mentions that the test endpoint is prone to locking up.  Which causes the errors we were seeing.  And this just after getting an email from the developers of the test endpoint asking about some new messages in the API.  New, that is, 4 years ago.  Which they have not implemented yet.  Despite 2 revisions of the API since then.

Words fail me.


Thursday, March 22, 2012

Duck, Duck, Goose!

A few weeks ago, I read this post about something called Duck Programming, and it rang a few bells.

I've run across a number of these systems in my career,and each has proven to be an abject failure.  It is simply not viable to make a complex system totally flexible without programming in some form.

The first system I ran into this was one for replacing single-purpose cellphone provider consoles in stores selling cellphones.  The goal of the system was to interface with the store's systems to provide all the options to sell the service without requiring a special-purpose console.  It was not simple, but we were well on the way to having this when we ran into the bete noire of cell phone sales - the service plans options.

It seems that at the time, all the cellphone service companies allowed their salespeople to define almost anything as a package, to allow them to make sales.  So even though I could not get just call forwarding as an option, a salesman could decide to offer just call forwarding to a customer if the salesman thought it was necessary to make the sale.  So every possible option had to be allowed, but only if it was defined from the cellphone service side.  And it had to be simple to set up.  No programming necessary.

Needless to say, we did not succeed.

The second time I saw this, it was a special-purpose language to control telephone switches, that was supposed to not require programming.  It didn't require programming, but required you understand trees and stacks, which meant that you had to have taken programming classes to get everything right.  We ended up replacing it with a database and C, which had the added benefit of allowing us to hire programmers from almost anywhere, instead of those who had happened to work in that system previously.

The third time was an attempt to replace a complex control system that had 4 main sections of data, each of which had numerous relationships, with a key:value store.  Everything was a tuple, and the keys connected everything in great transitive chains that taxed the system just to get the basic data out.
It failed as well.

I'm starting to believe that the Managerial class fears programmers the way that Bronze Age nomads feared blacksmiths - programmers wield mystic powers that shape reality, and are best done away with when you are done with them.



Sunday, January 08, 2012

Legacy Code and New Developers

I just read this article about legacy code, and I am dumbfounded.  The author seems to embody the attitude that nobody before him/her was a capable programmer.

(Warning, Old Fart Programmer Rant approaching...)
What new programmers forget is that the legacy code was written over many years with evolving needs.  The original schedule was probably a Death March, there have been 4 major OS version updates, 7 compiler migrations, and a database vendor change in those years.  The customers have made thousands of change requests, all of them urgent needing immediate fixes that have to be tested on the customer site because they have a configration that cannot be duplicated in-house in less than 2 weeks.

There have been 20+ developers working on this, some of them contractors with less interest in long-term maintainability, some of them fresh out of school, and most of them overworked.

One of the systems this code has to interact with is ancient and does not use a modern communications protocol, so you have to write raw socket code and parse proprietary binary streams - no well-defined XML with a DTD here, bucko!

There are no unit tests, because 1) this code was written before Agile was invented, and 2) the project managers are old-school, and testing is not part of their schedule, it's for the Test Group, so you can't waste time writing tests during Development, or you get fired.



So don't get all holier-than-thou about old code, laddy - your code will look like this someday. if it's still in use.



Wednesday, December 21, 2011

Coding Quality and Your University Courses

All programmers are self taught - or are they?

The basic point of that post is true, at least in my case - my courses did little to teach me the details of good coding style and practice.  Of course (ha!) I also learned 5 programming languages in undergrad, so there was not a lot of time to get beyond the basics.

However, the courses also noted the building blocks of the larger concepts - modularity was handled in the first class via the "Karel the Robot" exercises - writing programs to make a small robot trace shapes.  This covered the idea of wrapping repeated actions in functions/subroutines to allow later re-use.

Pascal covered the side-effect in procedures vs functions

But the big thing I think that the courses gave me was the space to realize that I knew the right thing to do.  I was able to see the correct way by being allowed to do it wrong.

Case in point - I was taking a course that was taught in Fortran, and was waiting to turn in my program printout when the guy ahead of me in line asked if I would look over his program to see if I could spot the error in his code that was messing him up.

He told me that he knew BASIC already, so he was writing the programs in BASIC to get the algorithm right, then translating into Fortran for the grade - an excellent idea.  Then I looked at his code.  It was bad.  The first thing that struck me was that he was jumping all over the place, instead of having blocks of code in reasonable places.  IF X THEN GOTO 130 ELSE GOTO 200, instead of having the ELSE be a fall-through.  And so on.

I worked through his code to offer advice, but I don't know if he got the big ideas out of it.

But my main point here is that  if you go into programming, you should have the mindset to see the good stuff on your own - university education is to teach the things that your can't see.