On Being Stupid 40
This was posted originally to a mailing list, but is reproduced here essentially unchanged by request of a friend.
I frequently see code (written by others) that is completely double-spaced, heavily commented, loaded with many abbreviated or meaningless variable names, and hundreds of lines long. In order to read the function and understand what it’s doing, poor Tim must wear out a mouse, skip comments, and track the variables on paper. A “smarter” programmer could just load it into his head, I suppose, but not the simpleton who writes this email.
I’m not smart enough to just read it from top to bottom and understand it. Sadly, when I read through and understand what in the heck the thxIniFvt variable is doing, I will forget it by the time I figure out the purpose(es) of pszVbt. I can spend all day, or even a few days to figure out a method, and that’s an admission of feeble-mindedness to be sure. I guess I’m not up to the level of some of the rapid hackers. That’s a limitation I face most days.
I find that I can sometimes understand a method like that only if I just delete all the blank lines and comments first, then reformat to break lines, then inline all methods with seven or more parameters, and then start renaming variables, extracting explanatory variables, and extracting explanatory methods. I may have to break the method into classes even. I guess I’m not one of the smart kids.
I used to be one of the smart kids. I once built a module so complex and fragile that nobody but me could figure out what to do with it. It was all tables and indicators, and stunningly clever. I am so ashamed that I wrote it. It was such a mistake that they eventually disabled it rather than field it in such a state. That was years ago, but so memorable to me. Other programmers said it was like the inside of a swiss watch, all delicate and perfectly balanced, and scary to mess with unless you first knew exactly what each part was doing, and why.
I would like to be faster than I am both mentally and in the sense of quickly producing code. I’d like to be a little less intimidated at the start of a project. .But I would not want those things if it meant building crap that people who are not appreciably more talented than myself would trip over every day. Instead, I sometimes wish I could teach the really fast, smart kids how to dumb down the code for the rest of us morons to read.
The funny thing is that dumbing code to my level doesn’t make it harder for the smart kids to use it, and sometimes allows a compiler to do a better job with it. I guess stupid isn’t so stupid after all.
Hear, hear! Most programming languages (with the noteable exception of Whitespace) are easy to read. It’s what programmers do with them that make them hard.
I frequently advertise for this program: Code Browser. It’s a small editor that allows you to fold code (by inserting tags in comments). This can work as a non-destructive kind of refactoring by folding large pieces of redundant code. I use it mostly for mind maps and task lists and the like but it is actually quite neat for program understanding as well.
Thanks Tim,
It’s nice to read something and having a deja-vu feeling. I’m glad i’m on the moron side :-)
Well said.
Great email. I’m going to save this one.
I have to admit to being a “smart” programmer once or twice too. Odd how the longer you’re in this field, the dumber you get. :-)
Great post! It is really a pitty how few dumb developers i get to work with!
“I find that I can …” Sounds like the first thing you start doing is refactoring. Do you use coverage tests?
thats how i often see other people’s code
and sometimes, code solutions i did long ago
I am trying to get into some habits though:
- as simple as necessary - as elegant as possible - complexity if an advantage exists, and only if the complexity is managable - using meaningful variables (many people hat concepts about this, like hungarian notation, but what they dont ackknowledge is that var x,y,z,a,b,c isnt giving you any hints in 5000 lines of code anyway… for vars which disappear quickly anyway, i try to use _ or tmp as a name…)
@joseph
I try to, but there is a chicken-and-egg problem. Some legacy code I see, I have no idea what it is supposed to do and therefore can’t test it.
This is doubly true if it happens to have a lot of conditionals, and if the objects it receives as arguments are global hubs or god classes or big honking wads of conditionals.
A lot of the legacy code I see is truly beyond my ability to internalize. I have to fix it enough to be able to read it and test it. This is why I lament being dumb.
@She/foo
My take on meaningful names is at http://tottinge.blogsome.com/meaningfulnames/ By those rules I would never name anything _, and would almost never name anything tmp.
As you say, in 5000 lines, even good variable names are not enough.
Wow, could one be more passive-aggressive and self-pitying? His points are valid (communicating semantics through program structure rather than comments is hardly a new idea), but I could be spared all the smarmy, “Oh, but surely I’m not as smart as you, dear reader.”
I love hungarian notation. I can see something like “pszPsz” and know that not only is it a pointer to a null terminated string, but every time I see it I’ll have the leading “psz” to remind me of that fact. Oh, wait, what data is stored in that string? Dunno, the name doesn’t give me that information, but I can remember it easily, right?
(Also, sarcasm is useful – I don’t enjoy that sort of thing at all.)
Deja vu indeed. I recently took over a system that had been written by an ex-fellow-employee who was very smart, but quite junior. It was his first large-scale group project. He had been (rightly) experimenting with several potential solutions for months and had settled on one that should have been straightforward but somehow it never quite came together.
After he left, I spent two days rearranging jumbled whitespace and renaming functions and variables without changing any of the logic. After that exercise, it was clear that 4 lines needed to be changed to fix 4 bugs. The system has worked fine ever since.
No doubt much of the benefit was that in order to properly rename everything I had to figure out what each part actually did, but most of it was because the code no longer traumatizing to read. It was not randomly jumbled, it no longer contained dead code or variables whose function had changed but whose name had not or swaths of duplicated code where only the constants (and the whitespace) differed, etc…
I’ve always thought that it takes a really smart person to write bad code. Complexity is sometimes worn like a badge of honor for those of us with engineering backgrounds. “If it’s easy, then why did I take 4 semesters of calculus?”
Good article indeed !
Great post. You’ll probably like my new device, then: Smell# http://claudiolassala.spaces.live.com/blog/cns354.entry
I too cannot stand garbage code anymore…
Hah,that was really funny. I even ordered an essay paper on it.These online essay writers made an excellent essay for me.
worn like a badge of honor for those of us with engineering backgrounds. “If it’s easy, then why did I take 4 semesters of calculus?”
this is a god
Place stampstring into PDF page to make created PDF file different and unique. You can even adjust the stampstring’s font, size, color, style and other parameters.
more dangerous crimes
Word en PDF Convertisseur est un bon aide dans votre travail, il est utilisé comme une imprimante virtuelle et supporte convertir tous les formats qui peuvent être imprimable en document PDF. Si vous avez d’autres besoins, ce convertisseur contient huit formats de sortie : PS, EPS, PDF, PNG, JPEG, BMP, PCX, et TIFF, vous pouvez convertir vos fichiers en ces formats. Télécharger gratuitement Word en PDF Convertisseur et prendre un essai.
Nice topic.Thanks for sharing!!!
The software you can trust to export iPhone music, video and more to Mac.
No doubt much of the benefit was that in order to properly rename everything I had to figure out what each part actually did, but most of it was because the code no longer traumatizing to read.
No doubt much of the benefit was that in order to properly rename everything I had to figure out what each part actually did, but most of it was because the code no longer traumatizing to read.
rename everything I had to figure out what each part actually did, but most of it was because the code no longer traumatizing
effectively information
internette görüntülü olarak okey oyunu oyna, gerçek kisilerle tanis, turnuva heyecanini yasa.
KXPOS system is all-in-one touch point of sale system,it used in restaurant pos system ,cafes,bars,pubs,clubs,supermarkets,vegetable and fruit restaurant pos pos system sydeny pos system
pos sysem hardware
point of sale hardware
pos system manufacturer
all in one touch
touch pos
touch screen point of sale
epos point of sale
it needs a bokmark so i can come back to it later ,nice stuff
Designed with unique features that you won’t find on ordinary beats by dr dre studio black with the Beats by Dr. Dre Studio headphones you not only get incredible sound, but advanced, useful function to make your listening experience the best it can be. With advanced speaker design, powered amplification, and active noise canceling, the headphones delivers all the power, clarity and deep bass today’s top artists and producers want you to hear.
Red Wing Work Boots—Highest quality Work Boots You Can Get Millions have enjoyed superior quality craftsmanship of Newest Red Wing Footwear. As you pick up a pair of these tough boots, you get Red Wing Suede Work Boots from a organization who cares about their work and who has been making Newest Red Wing Fur shoes for more than one hundred years. Realize now why they are considered by many the perfect work boots you are able to get. If you ever rely upon the saying you get what you pay for, you’ll be proud to purchase a pair of Red Wings Crazy Horse Shoe. These work boots are regarded for high quality and renowned longevity.
thanks very much for share with us
Cheap alfredia louboutin profit designed. 2010 Brand-new Design alfredia louboutin Footwear, Jimmy Choo Pompesalfredia louboutin bridalPumps, Innovative sandals resorts in jamaica, Alfredia Louboutin Boots. Excellent Promises. Jimmy ChooNo charge Travel. Get hold of Now!, canada gooseAlfredia Louboutin women’ ersus attire around ShopStyle. canada goose outlet,Glance prevalent sellers to uncover alfredia louboutin pumps for cheap profits – a lot of a particular posture.
LOS ANGELES just simply currently,
north face jakke
a person’s sizeable theaters round the usa in a hurry to the shops humorous hwy humourous training video launched, “usuanorth face jakke
lly means all over, ” furnishing increase so you might witnessing a different false male or female, this actually also popular issue is certainly absolutely in the training video merely a astounding sport activity gamed outside just by Zhang Xin Yi A person’s “ garnishment hoax girl. ”Recently established in 2006, http://www.snapbackhatcaps.com is the website of a company that has been in business in the Chinese market for about 3 years. They are Cheap Snapback Hats manufacture in china, The company specialize in supplying Wholesale Snapbacks Hats, such as Wholesale Snapbacks, NBA Snapback Hats, NFL Snapback Hats, NHL Snapback Hats and so on. They pay attention to their products quality and service.
it needs a bokmark so i can come back to it later ,nice stuff
The reason sport is attractive to many of the general public is that it’s filled with reversals. What you think may happen doesn’t happen. A champion is beaten, an unknown becomes a champion.
Make it possible to backup all stuff including contacts to computer and restore to iPhone when necessary.
a person’s sizeable theaters round the usa in a hurry to the shops humorous hwy humourous training video launched
LOS ANGELES just simply currently,