Sometimes I think, in fact, I feel I know that the programming languages we have now don't quite do what we want it to do. Ideas don't transmit themselves so easily through code. Beyond a certain length, the ideas behind what is going on is replaced by a morass of code.
Code is both a kind of expression, perhaps even a poem, lyrical, beautiful. No, it's far too purposeful to reach that. At what point, does the mundaneness of purpose win out.
Ask yourself the following questions. Does it bother you if a class has more than 20 methods? 30? Do you say to yourself "Boy, that's ugly", or do you not even blink twice. The class is what the class is. If I need to add something, I add it. If that is what the solution requires, I won't try to make it "nice".
How about method length? Does it bother you that it's 400 lines long? That it can't fit comfortably in two screens? Or three? Or ten? Or do you simply keep writing because to break it up into functions would be hard. Passing parameters is "hard". You prefer to leave your thoughts uncluttered by having all variables accessible everywhere?
Does it bother you that you class does two things? Three things? Ten things? That you tie this object to that object to the next object? After all, that's what the problem seems to require. Why not do it that way?
In many ways, writing a program is like writing a story with lots of constraints. You want a boy, and a girl. OK, maybe you make them related. Oh, now you need two more boys, and two more girls. They'll all be related. This will be like the Dukes of Hazzard, where you had five cousins and uncle and not a married couple in sight with the exception of Boss Hogg and Lulu.
Think about it. Bo Duke. Was he dating anyone? Nope. Luke? Nope. Uncle Jesse? Nope. Any of the police staff? Daisy Duke? Relationships are complex, especially since most episodes were devoted to cars leaping skywards on fake ramps, and general shenanigans.
Some code makes as much sense as the Duke clan.
Does cut-n-paste code bother you? How often do you find yourself preferring to cut-n-paste rather than consolidate a function?
Ultimately, most of us as coders, myself included, don't read enough code, don't read enough commentary about code, and so we code blind, doing what we think makes sense, whether it makes sense or not. We learn through trial and error, repeating errors thousands of others made. It's as if people taking a creative writing course had never read anyone else.
I don't buy the idea that avoiding the study of others will make you somehow more creative. For every person who can break the trend and produce something truly original, a thousand churns out utter tripe, and would be far better served by studying others, and mimicking the best they can. History shows that this works far better than trying to be completely original.
And in programming, there's no need, most of the times, to be truly original.
All it requires, sometimes, is a matter of taste.
Three recent talks
-
Since I’ve slowed down with interesting blogging, I thought I’d do some
lazy self-promotion and share the slides for three recent talks. The first
(hosted ...
4 months ago
No comments:
Post a Comment