Organizing complexity is the most important skill in software development
johndcook.com
johndcook.com
It turned the job from hellish (features were impossible to add) to very nearly boring (there wasn't much to do anymore). So with this newfound freedom I built some machines to automate the data entry and once that got rolling the job got even more boring. Because it was a small company with a very long learning curve the owner didn't let people go, but instead kept them on so that he didn't have to hire and train new people as growth accelerated.
But with all the automation some slack found its way into the system and problems that had normally required me to stop working on my normal job and help put out fires now got handled by people who weren't stretched a little too thin.
Sadly there's (seemingly) no way to interview people for this ability so we're stuck with the standard "write some algorithm on a whiteboard" type problems that are in no way indicative of real world capabilities.
There's no way to interview for what you're looking for, but compilers seem to require both great organizational skills and some algorithmic chops. there's enough complexity you can't hide lack of one side or the other.
Anyway, asking about building and enhancing a compiler seems like one of the ways to get insight about how people grow code. Every program is a seed. Is this the kind of guy that will end up with a mighty oak tree, or kudzu in 10 years?
A compiler doesn't have that. It's blissfully old-fashioned, really: read files in, write files out -- no interruptions or real-time requirements. You could do compilers on punch cards.
In a way, the compiler is the most complex piece of software that you could imagine in 1960... But software has moved on and faces a different kind of complexity.
Hence I'm not sure if asking about compiler architecture is really representative of the organizational skills needed by today's software engineering.
The degree of asynchronicity is low, I agree. The most significant was just interrupting compilation on user request. But the complexity was not trivial.
These days I work at a startup on a full stack SaaS; C++, Java, Rails, and Coffeescript with as few blocking browser actions as possible. It is far less complex than compiler work, but it pays better. I've never had to debug OS code to diagnose runtime library issues in this job; nor write manual structured exception handling. I haven't had to try and build stack frames dynamically to implement reflection calls, nor unpick stack frames dynamically to implement virtual method interception. The relative complexity of potential races with SQL read-committed, or writing UI such that it can't become inconsistent, really doesn't compare.
Ok, you can do more complex. I work on a compiler, which does it lazily. Transformations are per file and depend on each other. If something goes wrong, you print out the graph to figure out the problem. No idea what the benefits could be. Might actually be a good example, where it could have been simpler.
The nice thing about compilers, it requires a ton of code.
It's the kind of thing that any programmer can do (well good ones), and there are organizational tradeoffs to be made. There is no "right" answer, it's an opportunity to talk about organization. There are blind alleys that seem like a good idea, but turn out not to be. There are opportunities to merge and split passes. Some layers might want information from other layers, some layers might look very similar to other layers.
Compilers have been developed by lone developers in isolation. Some compilers are only a few thousand lines of code.
Someone who can demonstrate knowledge of making a compiler could well be completely behind in their knowledge about language design. He or she shows how calculations are turned into a tree and then into code on a register machine (i.e. "for-mula tran-slation"). But no idea how to compile exception handling, closures, and doing advanced things with type (beyond just checks) and such.
That is to say, the bar for what can be legitimately called a compiler is quite low.
On the topic of languages, I'd rather interview someone who knows about a lot of modern language features and how they can contribute to the improvement of program organization, yet is foggy about the details of how some of them are might be compiled to machine code.
There is still "compiler worship". On a previous job, I fixed a code generation bug in gcc affecting MIPS targets. Everyone was talking about that: "like wow, he fixed gcc".
Writing a C compiler seems like one of those standard undergrad activities. If a programmer can make that work, they probably have sufficient organizational skills. It seems like real-time, distributed, multi user app development is a separate filter.
I guess it's the distinction between looking for someone who is capable of solving those problems vs looking for someone who has solved those problems.
If the threads have to stop, it's still concurrency in the sense that threads are stopped in arbitrary places (just like an interrupt can stop a task at any point in its execution and dispatch another task or whatever).
But the garbage collector isn't running concurrently with the threads.
I.e. I think the term "concurrent garbage collector" is understood to be in contrast with "stop-the-world garbage collector" not with "synchronous garbage collector as a library function in a single-threaded virtual machine".
But there are a number of algorithms that most people would probably consider "real GC" that don't stop the world. Modern Java GCs use the train algorithm [2], which bounds pause times to some arbitrarily-sized constant. Erlang per-process heaps [3] also give good soft-real-time characteristics.
It is theoretically possible to run the whole GC in a background thread (eg. while a GUI is idle). Both the JVM and the CLR have options for this [4][5], but they're only useful for workloads with large pause times (eg. GUI apps, lightly-loaded servers) and so aren't enabled by default.
[1] http://researcher.watson.ibm.com/researcher/files/us-bacon/B...
[2] http://www.ssw.uni-linz.ac.at/General/Staff/TW/Wuerthinger05...
[3] http://prog21.dadgum.com/16.html
[4] http://www.oracle.com/technetwork/java/javase/gc-tuning-6-14...
[5] https://msdn.microsoft.com/en-us/library/ee787088(v=vs.110)....
Point is, I've been modestly bringing these up during interviews when asked what I've been doing the past few years. It is always glossed over.
I don't think companies want or recognize that they want someone who will be able to handle these tasks. If they knew these tasks needed to be done, they'd hire for it, right?
Seems some of the most important things that can be done for a company may be hidden to the executive team.
Ultimately all you can really do is try and work your way into a situation where you have some kind of meaningful equity. Founder, co-founder, early hire, buy a piece of a company, whatever. That's the only way to really get rewarded for your skills; knowing enough about the state of the art to see what can be done better and also having the skills to see those projects through to completion and realizing the benefits thereof.
I wish there was a job title for "good all-arounder with knowledge of the state of the art in a role with substantial self-direction", but I think that's probably "founder" or something. Or "owner of a very small business" maybe?
That's the way I am drifting. I just can't seem to get in gear on my own. :(
I have a couple of friends doing a startup in the same space in which I'm writing some software, and their software is nowhere near as far along as mine, yet I don't have anywhere near the "business development" that they do. I'm not there because it's too much work for one person and I've focused on the tech. Their tech isn't that great because it's too much work for one person and they've focused on the biz.
Aaaaah, I just don't know. They're pretty inexperienced, mostly just straight out of college. I'd like to find one person who is as passionate and experienced about business development as I am about software development. Instead, I mostly get contacts from guys who've worked in government offices all their lives, looking for a free programmer to boss around on their "1 in a million idea".
Some of it is selfishness on my part, too. I want as much ownership and control as I can keep, and I want it to be on my ideas. I've tried working on other people's ideas before and it just doesn't move me. I have a pretty clear vision of where I want to go, both tech and business. I guess I'd rather keep going slow right now than get side-tracked working on someone else's ideas.
If their current project ever tanks, they might be interested in coming on board with me. I think we're both just trying to see where everything we're currently working on is going.
Part of it is having trouble focusing on a single idea. Finding the right partner would help here: see #1.
Part of it is fluctuating levels of depression sapping my motivation outside, and sometimes inside, work. I have been fighting this for almost a decade. At one point several years ago the mere thought of doing things outside of work so reinforced how miserable I was in my day job that I couldn't get anything done.
I'm slowly working through my barriers. My most recent dip into the job market has demonstrated that the only way I am going to get the job I want where I want it is to make it myself, so I have renewed motivation to get moving.
I'd be interested in working on a project together (I have a recent "good idea" but it will need to be built ground-up). I don't have a lot of money, but I'd be fine with putting some capital down for hosting, domains, etc..
It would be very casual. No pay either way of course. Ownership is something to discuss.
For your first part, I feel everyone has that to some degree. You just have to do it. Email startups.
In a recent interview, I spent 45 minutes pairing with a current employee. Our goal was to take a (contrived) piece of legacy code, clean it up, and add a new feature to it. I imagine it was a very telling experience for them, and I feel it was more useful than the whiteboarding we'd done before.
Hopefully we as an industry will keep iterating on this sort of interview.
Asking for some work to be done off site before an initial on site interview, where the potential employer is getting something of value, would be a much bigger red flag to me, personally.
They could have given me more work, put me on new projects, etc., like I kept asking to be done, but instead they just wanted me to figure out some way to bill the client for 60 hours a week, and not call it "bug fixes" or "new features", because the client wasn't paying for it. That left data entry, which I had automated from a whole day to 10 minutes. They wanted me to go back to entering data by hand.
I would have quit then, but I didn't want to give them the pleasure. A flood had recently destroyed all of my stuff and I used the insurance check to get out of debt rather than replace the lost stuff, so I suddenly didn't need money for a LONG time. It's funny how easily debt can make you a compliant little slave towards people who want you to perform bullshit tasks.
I've been freelancing ever since, making twice what they paid me for only half a week's worth of work. And the flexibility of the freelancing enabled me to pursue a long-distance relationship that eventually lead to marriage. So I say getting fired was the greatest thing that ever happened to me.
It's an interesting read. This book was written in 1880, and if not for the dated writing style, would fit right in to the modern day self-help genre. It really helps underscore the idea that there's "nothing new under the sun."
And of course your thoughts were "I'm going to work extra hard initially, which will make a good impression and get the product built on time and all the tasks automated, and then I can coast and it will still be worth their money."
The manager doesn't care because when your code starts rotting due to bad maintenance and badly added features (or just the fact that nobody has bothered taking it over), he'll already have been promoted or changed companies.
It means I'm not making as much as I could be, but it's not their fault I agreed to the arrangement 3 years ago.
I think there is. Show the candidate some bad code. Not WTF code, but something you wouldn't be proud of but is realistic. Bonus points if you're comfortable enough to pull this out of your own production system. Ask the candidate about adding some functionality, but be clear that cleanup and refactoring changes are fine (even encouraged). The conversation should be enlightening.
It was a great interview experience though. One of the engineers commented that they gave the same task to other interviewees too.
I think this is a smart and lazy way to hire people :P No need to spend an hour in the room asking random questions, having awkward pauses etc. Just let the candidate fight with the codebase - lazy and simple!
Of course, that's not true at all. But giving someone a defective-but-not-entirely-broken tool can be a clever way of seeing how they work around problems or how they deal with frustration. Joking aside, we once let a guy go during his 1 week probationary period because he got a little too angry at a slow server. It's a valuable test.
If someone's approach to a broken keyboard is some workaround instead of just asking for another keyboard it is a sign they handle problems very, very poorly.
(And then make a preprocessor run where \/\/ is replaced with a w)
Unless you're from a very poor country there is no excuse for not having a working keyboard.
I don't know if that was part of the test, but if it was, it's worse than the big blue chip corps asking about the number of piano tuners. Which actually can be valuable at understanding how one reasons about unknown problems/areas.
About the server being slow, well I don't know the magnitude of the slowness or the anger, but unless you're a ramen fueled startup there is no excuse for having slow machines. It's management failure. It's a waste of developer time. Instead of coding the dev is having to deal with stress inducing constant 5 second hiccups or similar things.
Put yourself in the interviewee's shoes. Do you really want to work in a company that can't conduct a proper interview and has broken/slow hardware?
And yes, I do use vim and I do like w very much.
Slow is relative. The employee in question was trying to figure out why a remote server was experiencing extreme slowdown. He ssh-ed in, but he was able to type far faster than the beleaguered remote could echo his keystrokes. So he needed to just carefully type his commands, wait for them to appear, and then press enter. Instead, he typed angrily and too quickly, swore at the connection, and eventually started slamming his keyboard in a fit of pique.
It was a totally reasonable real-world slow machine problem, and a totally useful insight into the mindset of a potential new employee.
Not egregious at all. We're developers, sometimes we have to walk into an annoying situation and deal with it like adults.
>Joking aside, we once let a guy go during his 1 week probationary period because he got a little too angry at a slow server.
If the "w" key weren't working I'd copy-paste "w" characters from elsewhere in the document, or bring up the on-screen keyboard. Writing bastardized code -- for (;;), really?! -- would be a huge negative against a candidate. And, of course, if a company really didn't have a working keyboard to provide me with, I'd never work there in the first place, because if they can't even provide working peripherals there's no limit to what else they might skimp on.
I actually have three keyboards at my desk right now -- one with Cherry MX blues, one with Cherry MX browns, and a Model M. No way in hell would I ever write code without "w"s.
#define ever (;;)But then computers were not provided, each school had to travel with a computer for each student. So around 1993/94 a friend of mine, who also had some terrible medial situation at the time, and was quite weak decided to compete, and to make things worse for him - his spacebar wasn't working. I think he did a lot of presses of Alt+32 (or was it Alt+20 - I haven't used this combination of entering ASCII codes in a long time). He finish pretty good for the situation and keyboard problem he had, and next year when he was healthy and with good keyboard he did just awesome!
I have a keyboard with a broken 'w' key myself, and I know exactly why that key cap died young. It sure wasn't from typing out "while".
What I like most about this is how close to reality their interview model is. Less than stellar equipment, legacy code, and a maintenance task... just a normal Monday.
Good times.
The key was in how we presented it - we didn't want to come across as elitist jerks (but we probably did to some people), so we tried to soft-sell it to them and work it in gradually during the interview.
Some teams are like "Man, what idiot wrote this code! This is garbage!" (sometimes in other words). I can imagine they couldn't do the type of interview you're doing.
In your interview, you show them some bad code, ask them to change it, and if they start disparaging whoever wrote it, you can red card them before they start dragging down team morale.
Or, if they start wondering about 'how did this code get like this? are there other issues leading to the bad code?' they've got some strengths in areas outside of development.
If you don't do public projects, then you start a few steps behind the other candidates. This isn't insurmountable, but the error bars are wider, making you a somewhat greater risk.
> I think open source development is virtuous and is something that I want to promote and encourage
Then pay them for it.
Though, even if it didn't mean I was getting a view into how they actually work, I'm okay with preferring public-minded people who give things back and make the world a better place through it. I try very hard to live by the motto "pay it forward" and I find it to be rewarding and pleasant to work with those who do likewise.
> Then pay them for it.
My last two employers did exactly that. Should I need to hire directly for my consulting adventures, I'll do it there, too. I mean, this reply makes no sense to me: why would I not?
Then either start one or resign yourself to not getting the best possible tech jobs out there?
As a discriminatory practice it's probably one of the most benign. There's a low bar to putting open source code out there. You can write a simple project and put it out there in a couple of weekends. That alone puts you ahead of about 80% of candidates.
It's a way better discriminatory practice than the current default assumption that the best developers out there are white, male twenty-somethings.
don't you think that there's a higher proportion of white, twenty-something people who would have public projects (because they tend to have the most spare time)?
Don't you think that the over-worked CRUD programmer at an obscure insurance company wanting to get out because they are in a difficult situation (may be financially, may be race/background etc), would find it hard to have time for a public showing of their coding prowess?
No one is saying don't use public projects, but i would only consider them after other aspects, and certainly wouldn't cull people because of it.
Like I said: the amount of time you realistically need to get something out there is about a couple of weekends.
The problem with this is that it doesn't let my personal projects be Play. If I'm writing something for myself, it's not going to be as clean and documented to the level it would be in the workplace. And why should it? It's supposed to be for me.
And if I'm learning a new technology, I'm going to be sloppy. I'm going to make mistakes. That's the very nature of learning-by-doing.
But in the real world of managers and companies looking for reasons to say "no hire", I have to assume that every public checkin I do is another potential "no hire" justification. Which means if make all my checkins public, I have to treat my personal projects as Work, not as play. Which is an excellent way to burn out.
Or I just give you a curated look at the final product. Which ought to be enough.
But still, there must be one project that the candidate considers his best work, one he/she is proud of, one where he/she has motivation to do best. If the employer can just ask the candidate for that project, and the candidate can show that project in a public or private repository, this would give really important insights to the employer about the candidate which would be beneficial for that both.
Also, this doesn't mean that the candidates who doesn't have public repository to show have any disadvantage, they are at the same point. Its just that the candidate who is able to provide a project of his choice through public repository would be a few points ahead other candidates.
For an experienced developer, that would be a workplace project, which you probably could not see. Indeed, it _should_ be a workplace project; would you hire a professional developer whose best work is their personal project?
But if what you're saying is that the mark of an ideal developer is one who has produced a personal-time product of professional quality, where every checkin is to workplace standards, and has developed the project from conception all the way to release, again all on personal time, then what you're asking for is not a developer who also codes as a hobby, but a developer who (at least part of the time) works two actual jobs. One of which they do for free for portfolio development. I don't find that to be a reasonable expectation, even if it would give employers "important insights".
Were I to have such a project that I could show to people, it would be for a company that I had founded and as such despite my having the ability to show it, I would have absolutely no incentive to do so.
Basically if I had EXACTLY everything you purport to want in an employee I would be entirely unmanageable. Someone who has not only the skill and ability to turn out such a project but the motivation to do so on their own time is probably the definition of a founder. And founders are often terrible employees.
So while you're right that it would theoretically be better for candidates to share their codebases with potential employers, in practice I suspect that it rarely happens.
Actually I hold myself to a higher standard when writing open source - A) because I know everything is open to the world, and B) because I'm not under tight time constraints.
Nonetheless, there's no perfect project, and any employer that looked at a github project and was needlessly, ridiculously picky or made a presumption that there shouldn't ever be mistakes would end up just not hiring anybody at all.
>And if I'm learning a new technology, I'm going to be sloppy. I'm going to make mistakes. That's the very nature of learning-by-doing.
Only idiots expect a perfectionist. Thus if you try to make every commit an exercise in perfection you're only selecting out the idiots.
I'd actually far rather see incremental improvement (in code quality, documentation clarity & commit messages) than sheer perfectionism.
Also bear in mind that no matter how interested the employer is in you, the chances of them taking anything but the most cursory glance at anything beyond HEAD is very small.
Also we simply need to teach people the things that we want them to know after we hire them instead of looking for perfect fits.
I had one interview where the interviewer simply showed me a printed page of code, and asked me to talk about it.
I spotted a few problems and debatable constructs, and we had a good 3 minutes discussion.
Since at least I spend more time reading code than writing it, that felt like a truer test of my abilities than many of the coding tasks.
PS. Yes, I got the job.
I'm definitely stealing this trick.
The problems were those you see daily in production code. Misleading names. Duplicated constants. Overly complex constructs. Off by one errors. Maybe a resource leak when exceptions are thrown. Etc.
(OPC also refers to one's own code that when you can't remember wtf you did and the comments aren't useful)
Code reading: In <10 minutes, I can have a basic grasp on someone's ability to read, understand, and explain new code. Usually simple examples of <50 LOC in the language of there choice. I've used it a lot in phone screens (just providing URL to the code) and gained the reputation of being able to predict fairly well the quality of a code submission to a "take-home coding challenge".
Whiteboard: in ~15-20 min I can get a grasp on how someone takes a vague problem and works toward a solution and how they are to work with. I'm actually less concerned about code, and more about how they handle ambiguity, flesh out requirements, communicate issues, and think holistically without the distraction of a compiler/syntax-highlighter/etc. I think whiteboarding is slightly more about communication than coding and can provide a lot of context in a short amount of time. Of course, not all whiteboarding interviews are equal - I spent plenty of days complaining about certain whiteboarding interviews, and now I'm clearly biased to believe that mine take the good and leave behind [most of] the bad.
Code pairing. Takes ~1hr to understand and modify some piece of code in a meaninful way. (Maybe there are simpler versions - but in an effort to feel more "realistic", I've always focused on changing a requirement to the candidate's code submission). It's more realistic than whiteboarding, but it carries the [real-world] overhead of getting syntax right, finding docs for a specific function, and other surpries that come up (network issues, desktop crashes, editor problems, etc.). I've seen it work well when there are several interviews that focus on very different skills, but inevitbaly after such interview, I've often felt like I had a very narrow view of a candidate.
I think one reason why what you did doesn't happen more often, though, is because they wouldn't have the freedom to reimplement in a language they felt was more suitable.
I'm pretty happy that I did what I did in school, but I wish that people didn't rely on the whiteboard situation as much. If I can talk about what I did to find the edges and corners of a piece of mail in a picture, and how I used that I can rotate the image to be square and then crop the image so that all you see is the letter and not the background, perhaps my ability to do some kind of whiteboard coding exercise isn't terribly relevant. The odds that I can answer questions about how I developed such an algorithm while still not being able to actually write code are pretty small.
You're hiring me to solve business problems and last I checked FizzBuzz or reversing a singly-linked-list aren't business problems. End Rant.
The most important skill in software development
Posted on 18 June 2015 by John Here’s an insightful paragraph from James Hague’s blog post Organization skills beat algorithmic wizardry:
When it comes to writing code, the number one most important skill is how to keep a tangle of features from collapsing under the weight of its own complexity. I’ve worked on large telecommunications systems, console games, blogging software, a bunch of personal tools, and very rarely is there some tricky data structure or algorithm that casts a looming shadow over everything else. But there’s always lots of state to keep track of, rearranging of values, handling special cases, and carefully working out how all the pieces of a system interact. To a great extent the act of coding is one of organization. Refactoring. Simplifying. Figuring out how to remove extraneous manipulations here and there.
Algorithmic wizardry is easier to teach and easier to blog about than organizational skill, so we teach and blog about it instead. A one-hour class, or a blog post, can showcase a clever algorithm. But how do you present a clever bit of organization? If you jump to the solution, it’s unimpressive. “Here’s something simple I came up with. It may not look like much, but trust me, it was really hard to realize this was all I needed to do.” Or worse, “Here’s a moderately complicated pile of code, but you should have seen how much more complicated it was before. At least now someone stands a shot of understanding it.” Ho hum. I guess you had to be there.
You can’t appreciate a feat of organization until you experience the disorganization. But it’s hard to have the patience to wrap your head around a disorganized mess that you don’t care about. Only if the disorganized mess is your responsibility, something that means more to you than a case study, can you wrap your head around it and appreciate improvements. This means that while you can learn algorithmic wizardry through homework assignments, you’re unlikely to learn organization skills unless you work on a large project you care about, most likely because you’re paid to care about it.
Cached version: http://webcache.googleusercontent.com/search?q=cache:Mf9074z...
Agreed.
very rarely is there some tricky data structure or algorithm that casts a looming shadow over everything else
Agreed, BUT...
In order to organize, sooner or later, you will have to get clever (with tricky data structures or algorithms).
How I have always built something big and/or complex:
1. Add lines of code.
2. Add lines of code.
3. Add lines of code.
4. Holy shit! What have I done?
5. Refactor.
6. Combine similar sections.
7. Genericize with parameter-driven modules.
8. Still too many lines of code! Optimize Step #7 with something clever.
9. Go to Step 1.
2 years later: What the hell was this clever parameter-driven multi-nested process for? Why didn't I just code it straight up?For me, organizing complex code has always been a delicate balance between readibility and cleverness.
Don't remove enough lines of code and it's too much to navigate. Remove too many and it's too much to comprehend.
Organization + Cleverness + Balance = Long Term Maintainability
> Nobody is really smart enough to program computers. Fully understanding an average program requires an almost limitless capacity to absorb details and an equal capacity to comprehend them all at the same time. The way you focus your intelligence is more important than how much intelligence you have.
> At the 1972 Turing Award lecture, Edsger Dijkstra delivered a paper titled "The Humble Programmer." He argued that most of programming is an attempt to compensate for the strictly limited size of our skulls. The people who are best at programming are the people who realize how small their brains are. They are humble. The people who are the worst at programming are the people who refuse to accept the fact that their brains aren't equal to the task. Their egos keep them from being great programmers. The more you learn to compensate for your small brain, the better a programmer you'll be. The more humble you are, the faster you'll improve.
[1] http://blog.codinghorror.com/why-im-the-best-programmer-in-t...
I try to imagine that 6 months from now I'll have a critical bug in whatever I'm writing and so I write it for that.
Apropos of nothing, I'd love an editor that could completely hide (not collapse) comments, as when something I write them I don't need them so hiding them would be great but showing them but been able to toggle them on later would be awesome.
In ideal code, functionality and all paths of execution flow should be as visible as possible and easy to reason about.
Unnecessary abstraction should be avoided.
Naming should be consistent and sufficiently descriptive.
In terms of performance you sometimes need to do less conventional things, but that's precisely where documenting WHY you're doing it that way is so important.
The small bits of performance you're going to get isn't worth the maintenance hell it's going to cause.
I've always said, that's the difference between programming and developing.
Being organised has nothing to do with fewer lines of code. A 10 line script can be disorganised and a million LoC app can be well organised. What makes code organised is things not being tangled up together - having well encapsulated logical modules that do one thing (or a set of related things), with a well designed API to get each bit to work with the other bits.
I've found that the more I write testable code the better organised my code gets. Automated testing forces you to design maintainable, organised code - because your test suite really won't cope with disorganised code.
It can, but it will get out of hand really quickly. Worst case scenario the test suite becomes so tightly bound to the implementation that is becomes a part of it. This forces the test suite to be rewritten in the implementation changes, this is the worst case scenario and must be avoided at all costs.
The first is the more obvious kind: exploiting various conditions that occur in your code, in order to come up with a nonstandard solution. E.g. using if (x mod 15 == 0) in fizzbuzz. The problem with this kind of cleverness is that it's hard to understand the code, and it breaks whenever the conditions it relies on stop holding.
The second kind of more subtle. It is where you organize code to properly express the nature of the problem, but this organization is itself conceptually complex. A typical example is using C++ templates where they make logical sense, but they make the code that much harder to read.
The second kind is where balance is needed most. If you use too little cleverness (or maybe too much humility), you end up with spaghetti code, or code where all the organization is done via convention instead of enforced by the compiler. If you use too much cleverness, you end up with code that is hard to read, and brittle, since so many assumptions are embedded in the code.
The most important skill in low-level technical support: diplomacy.
The most important skill in high-level technical support: figuring out what people are actually complaining about.
Note that many low-level technical support problems look like high-level problems, and vice versa.
Once I learnt to think about why I was getting grumpy, and vocalize the actual problem it was easier.
e.g. A client said to me recently could clicking the blog link open a new window? When I started programming I'd have said "Yes! I can do that!". Then after a few years I'd have got grumpy about it and said something passive aggressive "I guess so. That's not normal though...". Now I think about it, realized I hate it when links on the web behave unexpectedly and that's what's making me grumpy. Then explain to the client that that's you shouldn't take control of other people's browsers on public websites, and the better way is to have a clear link to get back to the shop on the blog.
The reasoning is that sometimes what the client is asking is his best guess as meeting a need he has. By asking why, chances are you'll get to the actual need and, oftentimes, find a better solution where both the client and you are happy.
Over the years as a grumpy developer, this piece of advice has served me wonderfully well.
In my experience it has been that designs which look "locally simple" because they have such a high level of abstraction are actually the most complex overall. Such simplicity is deceptive. I think it's this deceptive simplicity which causes people to write a dozen classes with 2-3 methods of 2-3 lines each to do something that should only take a dozen lines of code (this is not that extreme - I've seen and rewritten such things before.)
Perhaps we should be focusing on teaching the techniques for reducing complexity more than hiding it, and that abstraction is more of a necessary evil than something to be applied liberally. From the beginning, programmers should be exposed to simple solutions so they can develop a good estimate of how much code it really takes to solve a problem, as seeing massively overcomplex solutions tends to distort their perspective on this; at the least, if more of them would be asking things like "why do I need to write all this code just to print 'Hello world', and the binary require over a million bytes of memory to run? Isn't that a bit too much?", that would be a good start.
I work for such a business right now and it's killing me. No amount of high quality code will fix this.
This reminds me of something Scott Shenker, my computer networking professor at Berkeley, drilled into us every chance he got: Don't manage complexity. Extract simplicity.
Finding complex solutions to complex problems is comparatively easy. Finding simple solutions to complex problems is hard.
I can't second this enough. This is why it's so important to throw away your prototype code, sometimes, instead of trying to fix it. It's also the big value-add of TDD: Well written tests make that extracted simplicity explicit.
These interviewers do not seem to care at all about the actual process of writing and refactoring code, or what your finished products actually look like.
I know plenty of programmers who can write highly optimized code, but do so in a way where it is completely impossible to maintain.
It's especially heightened when you are given a problem such as "validate if this uses valid brackets, and you have 10 minutes." When under time constraints to solve what is basically an algorithm 99% of programmers are not going write their best code or write code in the way they would normally write code.
If you are using lots of algo's on your programming interviews, I suggest you take a step back and determine if those skills are actually what you want to be testing for in this job. Odds are that it is NOT algo's. Give your interviewer some really sloppy code to refactor into something beautiful. Give them a few hours to work on it, watch how they put the pieces together.
If your position isn't going to require someone to write advanced algorithms on daily basis, testing for them only cuts out a huge swath of potential talent. I also think it probably leads to less diversity in your work place, which is a bad thing.
A Web Developer will never need to solve the towers of Hanoi problem, but they will need to write clean code that can be maintained by others.
</rant>
And as someone who is about to graduate computer science, your rant makes me hopeful :)
I am much better at refactoring and finding patterns than memorizing algorithms and other things (mainly because they are relatively easy to look up). Do you suggest that I try to strike a specific balance between practicing dealing with complexity, optimizing and making code readable, versus actually trying to memorize and implement certain algorithms for learning's sake?
That being said, I do force myself to practice algorithms thru various coding challenges only because I know that this is the specific skill that will land you a job. Which is a shame.
That is not to say that there are not positions that really do require this specific skill, but the vast majority of development positions don't and yet nearly every employer tests their candidates as if their success depends upon their ability to solve an algo in under 5 minutes, instead of their ability to write a good library.
It's a disservice to those of us who do not have CS degrees and have learned to code by spending a great deal of our time writing code.
Another thing I learned is that dumb, explicit code is highly desirable - It's better to have 10 dumb components to handle 10 different use cases than 1 clever component that can handle all 10 cases.
I think the most important skill is being able to break down problems into their essential parts and then addressing each part individually but without losing track of the big picture.
I knew for a long time that "dumb" code was easier to reason about, but it wasn't until I started looking at compiler output and profiling my code that I realized being "clever" in the source text really didn't matter. Now I'm quite happy to write code in the most straightforward fashion, rather than foolishly "compress" things. I imagine the same experience could be enlightening for a lot of newbie and intermediate programmers.
Of course, if you're just writing some I/O bound program anyway, it hardly matters.
1. Skills in Creating 2. Skills in Organising those creations
The thing is, the Creating part is always exciting but it's disruptive in nature. The Organising part is boring because it's about taming or tempering the creation in such a way that it can be referenced later on (just like filing your invoices, or timesheets - yuck - but necessary).
Unless you've got a systematic method to organise your creations, you will always be alone with your ideas, find it hard to resume creative chains of efforts and ultimately flounder without profit.
Both in business and in programming.
Damn right it's the most important software development skill.
We learn it when we're kids : "Clean your room (2) before playing with toys (1)".
Such a basic concept, so hard to scale.
This is also why I like game programming that much. A big chunk of the codebase is throwaway code that won't be transported to the next project. When the final deadline comes, you don't feel bad making hundreds of hacks everywhere, and it's fun.
At least not since this was published:
http://www.amazon.com/Refactoring-Improving-Design-Existing-...
Martin Fowler really struck a chord all the developers trying to do the right thing by cleaning up badly structured code, by giving the practice a name and explaining why it's important. Refactoring is definitely a widely acknowledged and accepted practice today, although probably more so in some communities than others.
- Incomplete, conflicting and misunderstood requirements.
- Lots of "We never thought we would need to do X".
- Poor team communication.
- Mistrust, frequently well earned.
- Harmony valued over truth.
Once these were winnowed away, the problems rarely overwhelmed the technical teams. This isn't to diminish the importance of technical skills. Rather - when everything else is f*cked up, you can't blame the technology or expect a 10xer to pull you out of it.
If you genuinely can write code 10x as fast as the average developer, and get feed requirements through a 10x faster channel, that would be the life! I suspect that's where the mythical 100x developer comes from.
I certainly don't intend to diminish the impact of these 10x developers, just that projects generally get messed up independent of developer quality.
I am amazed at all the code I see that has terrible/too generic names for functions and variables and objects. Some people get so obsessed over short function names, one character variable names, and complicated looking one liner evaluations.
http://webcache.googleusercontent.com/search?q=cache:Mf9074z...
I think a large issue is when an application has new people working on it or entirely new teams that maintain it. That is when the original authors methodology and organization of the application falls to the immediate need of the day.
The functionality of the software should speak for itself. Commenting your code with why you are doing something is important to help other maintainers later on, including yourself, understand what you were thinking when it was written.
Some folks like the analogy of software and building construction. I like the comparison to cooking... in this case the closest thing would be how a chef sets up their work space and how it is organized for what they are cooking.
Some like it one way, some like it another - is one way better or worse?
Looks like there is a great value to organise your app in way to be able to throw away large chunks of code and start over in case there is a big design change.
:)
You can learn how to create clean, readable methods and classes with a book (1).
You can learn how to refactor old methods and classes with a book (2).
You can learn how to organize a small team to allow fast iterations with many books.
But building a project lasting more than a few months with constant changes in the requirements, new developers every month, new SDKs and frameworks every 3 days, without the code rotting to death and everything going out of control is a different story, at least for me.
I guess you just learn by watching old guys do what they do after decades of experience...unless someone has a magic book for me?
(1) http://www.amazon.com/Clean-Code-Handbook-Software-Craftsman...
(2) http://www.amazon.com/Refactoring-Improving-Existing-Addison...
I was lucky that this was one of the first things I had learned as a developer out of school. It was a little different because the projects were small enough to be solo, but it was humbling because all of the mistakes were my own.
http://www.amazon.com/Practical-Object-Oriented-Design-Ruby-...
This is a very good book on subject, very clear:
http://www.amazon.com/Practical-Object-Oriented-Design-Ruby-...
Summary: Toyota settled an unintended acceleration lawsuit connected with analysis of the source code for a 2005 Toyota Camry showed it was defective "spaghetti code."
There'a a lot of poorly-organized code in the world, and a typical excuse for not cleaning it up is that "it works" so there would be no return on fixing it. In the Toyota case, the code may have contributed to unintended acceleration, and did result in a legal exposure for which Toyota felt it was necessary to settle a lawsuit.
Do Not Program Yourself into a CornerBut yes, seek the minimum amount of complexity to materialize the inherent, necessary complexity. But don't allow a drop of complexity more than that. Architecture astronauts, pattern fashionistas, I'm looking at you. KISS. Spend your complexity dollars where it gives you something you truly need or want. Don't do things Just Because.
It should be no surprise that almost every single design pattern can be replaced with a simple lambda in languages supporting them.
I recently had to modify someone else's Mac app. On the surface it looked like a textbook example of successful use of design patterns. Everything was highly modular, functions were simple, there was clear separation of concerns, controllers and views were distinct, and so on.
Problem was, the key features were still baked in and hard to modify. So while it looked modular, it wasn't - the affordances were fixed and there was no way to generalise them without pulling apart at least a couple of levels.
IMO it's not abstract organisation that matters. Organisation is only good if it makes it easier to achieve clearly-defined goals and benefits. You need to know what the goals are, and make some guesses about what they might be in the future. Otherwise you're just putting stuff in layers and boxes and drawing arrows everywhere for no good reason.
Features are by definition almost always cross-cutting concerns in that they touch half the systems that makes up the application.
Even if your systems are pure isolated islands properly decoupled from each other, they can still be tangled back into a spaghetti mess when wiring it all together.
Furthermore, design patterns define data structures rather than data flow, even the behavioral ones, making them horrible at organizing the application's features.
Remember the 239th Rule of Acquisition, “Never be afraid to mislabel a product.” That goes for methodologies, too. If they could get away with it, they would probably say it cures baldness, too.
This article isn't about the choice of an algorithm, it's about organisational aspects. That's something different altogether, and an even larger topic.
Life is complex. Business and workplace dynamics can be complex. People are complex with their own strengths, quirks and situations. Having a broad outlook, developing patience and skills to deal with life and work is part of becoming mature.
The most important skill in software development, by far, is managing your own psychology.
- Establish conventions early; Conventions in managing projects, conventions in code. And stick to those conventions. Be predictable, in the code. Use simple names.
- Protect your interfaces. By this I mean, use a central place like a wiki to document your interfaces, so all involved parties may agree upon. Write unit-tests for interfaces. Use libraries like mockito and hamcrest that make it a breeze.(You would lock your home every time you go out, don't you?)
- I mentioned this in the previous bullet, but write tests. Write lots of them, write tests that document any tricky, magical behavior. Cover all the cases(A boat with one hole is bad as one with two holes). Cover all the invariants, any thing that you notice but didn't mention in the source code. Write tests for the bugs you just fixed.
- If you are developing in Java, please use an IDE. I use Intellij, but Eclipse is good too. It makes refactoring code much easier. Rename fields, pull classes up the hierarchy, create abstract classes, create getters and setters automatically with refactoring tools. I am not against emacs or vi, but it is hard to manage Java's sprawl with them.
One of the best programmers I know writes code like it has been generated with a program. It is boring, dull and looks alike in every direction. Every field and method is documented, it says what its purpose is, and why it is needed. He is very fast(fast for a startup, not your average enterprise), accurate and gets a lot of stuff done without magic.
Having a clear functional organization at the start (and respect it throughout development) is very important, but after that is equally important to code clean and efficient code, to test, to debug, etc. Then, going up and dow on the solution stack is important to make the right decision on hardware, OS, server, services, etc.
While there are many things that are important they all have different priorities, though.
All that said I'm also very sceptical that there is one thing you can learn and then you are a the best programmer. You have to learn thousands of things. And sometimes learning a currently low priority thing now might save you hundreds of hours of pain further down the road. So it's really hard to say what you have to learn.
thinking of it, I've also seen this as a typical difference between fresh CS graduates and those who have been programming for 10+ years. The latter would sometime take way longer to come up with clever math-oriented algorythms than the first, because the graduate has been trained for it and still has it fresh in memory, but experienced programmer would make up for that by being able to use the algorithms in all proper 'best practice' ways one can think of. Whereas the graduate would just slam it in somewhere and call it a day even though there are now x more dependencies and whatnot, you get the picture.
Yet nearly every job I apply for these days wants a 90 minute online test. (I just had to implement a sorting algorithm in psuedo code - I have never in 12 years had to implement a sorting algorithm as I choose an appropriate library to do that for me).
True, but if you can't implement a simple sorting algorithm how are you going to implement _____ ?
From my own experience programming here are some the most common and best ways to better organize complexity:
1) Create DSLs. The Sapir-Whorf hypothesis is the theory that an individual's thoughts and actions are determined by the language or languages that individual speaks. By creating DSLs we are able to reason about a problem domain with increased efficiency.
2) Reduce cognitive load by reducing state. By reducing the number of variables in a given section of code we can more easily reason about it. values.map (x) -> x * x is a lot more understandable than newArr = [] ; for (i=0; i<values.length; i++) { newArr.push( values[i] * values[i] ); }
3) Build tools to build tools. The history of computing is one of building tools on top of tools. From assembly language to C to high level languages. What is is the next step? I suspect it is some kind of polyglot environment that is a hodgepodge of languages all working together combined with automated code creation from AI.
Thus, as a result: Interpreting complexity is by far the most important skill in software development. More-so then organizing complexity.
Being able to search for and manipulate symbols at the AST level goes a long way towards eliminating any resistance to refactoring.
Disclaimer: Haskell is not a silver bullet, not a panacea and I'm only claiming a modest increase, not miracles, but it helps me deal with complexity better than any other language I know.
- 10% of the LOC as previously
- Code significantly more understandable
- Jr. developer on the team suddenly became a rockstar b/c he could understand what was going on.
I personally think of the UI/API: what the code exposes to the outside world should be "simple".
Some people might think about language features. "Simple" is being very selective about what language features you use and what you avoid.
Others might think design patterns, and think the code is "simple" when you can point to any class and immediately recognize what pattern that class implements.
I've come to learn the word "simple" as in KISS (Keep It Simple, Stupid) isn't very useful at all.
I'm not a functional programming evangelist but that reads like a very good reason to go for FP. I think a similar point was made in "Functional JavaScript". I don't remember it exactly and it's on my shelf at home but there was some passage about the biggest downside of typical OOP codebases being the mental effort of keeping track of values and value changes.
This applies to systems as much as any thing else it possibly could.
As wise men said: All problems in software can be solved with more layers of abstraction, except of the problem of too many layers of abstraction.
ps: it's also reminiscent of recursion, dogfooding etc.
http://webcache.googleusercontent.com/search?q=cache:http://...
I worked on a system where we had to support imperial and metric units. It was done in a pretty bolted on fashion with if statements all over the place. And sometimes it isn't even clear if it could be done in any other way.
Any HN'ers have suggestions on how to do it elegantly.
I agree with this profoundly. Unfortunately, complexity is in the eye of the beholder. When comparing solutions to a problem, different developers will not always agree on which is the least complex.
Also, in business, if someone is really good administrator, it seems he never does nothing.
What are some others?
http://www.amazon.com/Working-Effectively-Legacy-Michael-Fea...
Clean code:
http://www.amazon.com/Clean-Code-Handbook-Software-Craftsman...
Any thoughts on it?
The big takeaway was that the way the project is split into libraries, files, folders etc and how these map to classes, modules and subsystems matters.
Although higher level languages provide some features for organization, you still must have the discipline and know what you're doing to use them properly.
For the most part, design patterns exist merely to fix the lack of a simpler lambda construct in the language. They more often than not add complexity rather than remove it.
The biggest balls of spaghetti code I've ever seen we're always OOP with design patterns. I've seen far more clean C codebases than Java or C++ ones.
However I would argue against the STL being well thought out. Every single large-scale C++ project I've worked on threw it out the window before even staring out. Our current project already takes an hour and a half to compile without parallel builds and barely uses templates at all.
I still prefer plain old C to C++ most of the time.
Java and C++ are often found in huge, legacy, or enterprise oriented code bases.
The are plenty of ways to use the abstractions in Java and C++ to write nice code. Just like it is possible to find a Scala or Clojure code base that went crazy with the usage of "cutting edge" features and abstractions in those languages.
And at least with Java, your IDE will always be able to navigate the code effectively.
What I'm saying is that it takes more discipline to cleanly use Java or C++ than it does to use Haskell or Clojure. For the simple reason that most of the abstractions provided by the former languages add to the program's complexity rather than remove it.
There's an excellent explanation by Rich Hickey in Simple Made Easy: http://www.infoq.com/presentations/Simple-Made-Easy
The server seems to be getting hammered.
I'm pretty sure I'm not as smart as I used to be, and I'm definitely not as smart or productive as some of the younger programmers I've worked with. (Sorry for the ageist remark!)
This may be my secret advantage: I have to keep my code simple enough that even I can understand it.
Here's a fun example that I've seen more than a few times in various forms: four-way navigation, either involving up/down/left/right or north/south/east/west, or both.
In one (somewhat disguised) project it worked like this: the code had several different modules to provide a keyboard interface for geographic navigation, while keeping the geo code separated from the low level details of key codes and events and such.
There was a keyboard manager that mapped keycodes to readable names that were defined in an enum:
switch( keyCode ) {
case 37:
return KEY_LEFT;
case 38:
return KEY_UP;
case 39:
return KEY_RIGHT;
case 40:
return KEY_DOWN;
}
Then an event manager broadcast navigation messages based on the KEY_xxxx codes: switch( keyEnum ) {
case KEY_LEFT:
BroadcastMessage( 'keyLeft' );
case KEY_RIGHT:
BroadcastMessage( 'keyRight' );
case KEY_UP:
BroadcastMessage( 'keyUp' );
case KEY_DOWN:
BroadcastMessage( 'keyDown' );
}
A navigation manager received these messages and called individual navigation functions: // Don't forget to reverse the directions here
events.on( 'keyLeft', function() {
moveRight();
});
events.on( 'keyRight', function() {
moveLeft();
});
events.on( 'keyUp', function() {
moveDown();
});
events.on( 'keyDown', function() {
moveUp();
});
These navigation functions panned a map in one compass direction or another: function moveUp() {
map.pan( maps.DIRECTION_NORTH );
}
function moveDown() {
map.pan( maps.DIRECTION_SOUTH );
}
function moveLeft() {
map.pan( maps.DIRECTION_WEST );
}
function moveRight() {
map.pan( maps.DIRECTION_EAST );
}
Of course most of you reading this can see the problem at a glance: Besides having so many layers of code, how many different names can we give to the same concept? We've got KEY_LEFT, keyLeft, moveLeft, and DIRECTION_WEST that all mean pretty much the same thing!Imagine if math worked like this: You'd have to have two of every function, one for the positive numbers and another one for negative numbers. And probably four different functions if you are dealing with a complex number!
That of course suggests a solution: use numbers instead of names, +1 for up and -1 for down, ditto for right and left. And pass these numbers on through any of these layers of code so you only need half the functions. If you need to flip directions along the way (like the left arrow key navigating right), just multiply by -1 to reverse it instead of having to make special cases for each direction name.
You might even decide to combine the two axes, so instead of vertical and horizontal, you've got +1 and -1 there too (or 1 and 0, or something that lets you handle both axes with one piece of code). Now you could be down to a quarter of the original code.
Unfortunately, I was brought in on this project near the end to help wrap up a few other tricky problems, and all this navigation code was already set in stone. (And to be fair, working and tested, and who wants to go back and rewrite proven code, even if it is four times the code you need?)
But this would make a pretty good "how would you clean this code up" interview question!
However, I've also solved this problem by passing around polar coordinates, it's elegant and very flexible but you have to munge some data at the beginning. You can also pass around a simple vector [{-1, 0, 1}, {-1, 0, 1}], which is basically what you describe.
The zen of Python https://www.python.org/dev/peps/pep-0020/ say:
Simple is better than complex.Use the right tools for the job. Most mainstream programming languages are ridiculously inadequate for building any production software of any significant complexity without introducing more problems than you are trying to solve.
Use a mature functional programming language that works with immutable data and is designed for building complex industrial systems.
Use a language that was designed from the beginning with the understanding that your software WILL be full of bugs and errors, yet systems must always continue to run.
Use Erlang.