News for hackers. Stuff that matters.
Re:Write code that is easy to delete, not easy to extend by JoeAltmaier on Sunday February 14, 2016 @11:15AM (#11098776)
When I teach teenagers I tell them, there's never time to do it right OR to do it again. Time is money; Engineers are paid to solve the problem and not make a beautiful thing. Get used to just-in-time solutions and just-good-enough implementations.

With that in mind, its important to have some discipline, to make your 'just good enough' not too crappy. That's the difference between an apprentice and an expert.

Re:Write code that is easy to delete, not easy to extend by Flip-per on Sunday February 14, 2016 @12:04PM (#11098979)
I do not like this approach, and I think it is not the right way for medium to large software projects. Maintaining lots of interacting 'just-good-enough' code is a nightmare - and it can easily cost you way more than you saved writing it.

People get lazy and sloppy early enough. I would try to encourage teenagers to go for the best and most beautiful solution that they can possibly find.

Re:Write code that is easy to delete, not easy to extend by phamilton on Sunday February 14, 2016 @01:13PM (#11099237)
I don't believe this is actually measurable. Any claims about time saved or lost are merely guesses, especially in aggregate for a large project.
Re:Write code that is easy to delete, not easy to extend by Walkman on Sunday February 14, 2016 @02:29PM (#11099594)
Sorry, but I feel I need to be harsh to express how much I disagree; it sounds like you are a terrible teacher.

Beside feeding them with the "just write mediocre code" you are also taking away the beauty of software development: "you have to write something just good enough and move on"...

Re:Write code that is easy to delete, not easy to extend by JoeAltmaier on Sunday February 14, 2016 @11:49PM (#11101575)
No; I teach about responsible Engineering. To make beautiful code is a great thing. On your own time. That's how you become an expert of course.

So no I take nothing away from the art, in the right place and time. And thanks for the personality evaluation!

Re:Write code that is easy to delete, not easy to extend by hueving on Monday February 15, 2016 @02:03AM (#11101904)
It wasn't a personality evaluation, it was a critique of your teaching methodology.

Responsible engineering isn't targeting the minimum thing that works. That's short sighted thinking that involves taking on way too much technical debt up front to pay for a faster initial release. This method might work if you're writing one-off tiny projects, but it will slam you if the project needs to adapt to new requirements in the future.

That's the difference between writing software and building a bridge. Three weeks before a bridge is completed, nobody can say, "oh BTW, this needs to also carry two trains." With software major requirements can change last minute and you better have written your code to deal with that possibility.

Re:Write code that is easy to delete, not easy to extend by JoeAltmaier on Monday February 15, 2016 @04:32PM (#11106181)
For many, maybe most, engineers it is targeting the minimum thing that works. For every platform or structural problem, there are 1000 apps. And they get old faster than cheese in my refrigerator. Shipping sooner for less cost is a primary metric!
Re:Write code that is easy to delete, not easy to extend by manyxcxi on Monday February 15, 2016 @11:44AM (#11104284)
I disagree on the phrasing. When I'm teaching beginners or juniors in a school or professional environment, as I said, I hammer that it doesn't have to be perfect. It never will be. Don't over engineer things. But everything NEEDS to be right. Where right means the problem is solved, the code is understandable, the patterns (and there must be a pattern) are easy to discern and emulate. Along with proper code formatting- I am amazed at how many people in the workforce don't even understand how important formatting is! FFS most IDEs will auto format with a keystroke.

'Right' is definitely subjective, so to you, right be what I call perfect and we're talking about the same thing. But I feel like if someone is hearing me say it doesn't have to be right, I'm excusing bad behavior and shit code. Whereas when I say it doesn't have to be perfect I'm saying a small amount of code smell or some tricky areas are acceptable if they can't be helped given the money and time constraints.

Re:Write code that is easy to delete, not easy to extend by sbov on Sunday February 14, 2016 @03:32PM (#11099861)
At least one problem with this advice is you do not define "just good enough". When I was a new developer "good enough" simply meant it passed all obvious tests I could think of.
Re:Write code that is easy to delete, not easy to extend by dannypgh on Sunday February 14, 2016 @12:05PM (#11098982)
I'm not sure I object to just-good-enough solutions, but, there's still an awfully large benefit from paying down technical debt, and I hope your students appreciate that.

My approach is to pay down the technical debt before starting the next big change. I consider it akin to prepping my work site. As an example: consider a project where you're modifying some large continuously running system in production, creating an alternate codepath to ultimately replace some legacy codepath. You'll likely add the new codepath first and then migrate some subset of users to it.

There might be some diminishing returns from migrating a long tail of users to the new codepath (perhaps they were better served by the legacy codepath for reasons that don't quite justify the maintenance of both codepaths). And even when they're migrated, you quite likely don't need to rip out the legacy codepath. So at some point, perhaps before all the users are on the new path and perhaps before you rip out the legacy codepath, you'll consider the project a success and move on.

To me, that's quite reasonable. But consider then that any project on the same codebase in the future has to account for both of these potential codepaths. That adds an expense to every future change you make, as you have to maintain and support twice as many things. In my experience paying down that debt will pay for itself over the course of an astonishingly few (but greater than zero) number of future changes.

I mention greater than zero because quite a lot of systems get decommissioned, for one reason or another. If someone is going to bulk delete your code and everything near it, it doesn't really matter how the code smell was right before: the code that smells the least is the code that doesn't exist.

This is why I make various forms of cleaning up code - in-depth refactoring, deleting all unused code and tests, etc. - not the last thing I do when I finish a project, but rather the first thing I do when I start the next project. It's also much easier to explain why you're doing it to outside observers at that point - you're doing it not just because it "improves code smell" you're doing it because it makes what you're trying to do now substantially easier.

The only time I think this can start to fail is if you aren't the person who would be doing the next project / you could do the code cleanup far more efficiently than the person who is doing the next project. In which case this all becomes much more hard, and you should just remember to treat others as you'd wish to be treated. But I'm not sure it totally doesn't work -- for the person inheriting your work, getting to do some amount of refactoring and cleanup may well end up being a decent way of them getting to know the codebase better (if they knew it as well as you they could clean it up just the same).