Showing posts with label teaching. Show all posts
Showing posts with label teaching. Show all posts

Sunday, September 10, 2017

Should Bad Code Be Illegal?



A junior developer on my team asked me a rather interesting question recently.

If you were able to make laws, would you make bad code illegal?

I have a reputation where I work as being rather hard-nosed about not allowing hard to understand and maintain code into the codebase, so my answer surprised him.

No, I would not make bad code illegal, and there are very good reasons for having this opinion.

First, everyone writes bad code before they write good code. Whether it’s your first time coding in general or just your first time coding in a new language, with a new framework, etc, you are going to write bad code. I’m sorry. It’s just a fact of life.

Nobody starts out writing amazing code. Not me, not you, not Uncle Bob (in fact, Uncle Bob is open about the fact that he was a horrible developer when he started, just like the rest of us). We all get better by writing bad code, learning from our mistakes and pain, and, if we’re lucky, mentors helping us to see where things can be improved.

Second, “bad code” is rather subjective. What standard are we using for what “bad” code is?

Is it code that costs the business unreasonable amounts of money due to being full of bugs and difficult to maintain? That’s not a completely terrible definition because we can tie it to some external benchmark, but it’s still probably a bad idea since there is a risk/reward factor of why decisions were made at the time that may not be known at some later date.

Is it code that Developer X (whether me, Uncle Bob, or Joe in the cubicle across the hall) would look at and give a laundry list of things that need to change? For any given code, you can find some developer that would find flaws in it – whether it is inefficient, or it doesn’t implement their favorite pattern, or any number of other complaints.

Is it code that, six months from now, you will look back at and wonder what the heck you were thinking when you did it that way because there are so many better ways to accomplish what this code does? Here’s a hint. This should be most of your code. You didn’t know as much 6 months ago as you do now.

Third, sometimes bad code is necessary.

Yes, you heard me. There are times that it makes sense to write bad code.

If you are writing a script to perform some one-off function that you are seriously never going to use again, pretty doesn’t always matter that much. If writing code for 5 minutes and then throwing it away can save you hours of work, go for it. I’ve done it before, and I can almost guarantee that I will do it again.

Sometimes you need to fix a catastrophic flaw in a mission critical piece of software, because the company is losing millions of dollars per minute while the flaw exists. In that case, you have to do whatever you can in order to fix the issue, release the patch, and *then* go back and make it maintainable.

The same is true if we are in a startup where the money is limited, time is fairly short (as it is generally a function of money in this case), and we need to get a Minimum Viable Product out in front of users so we can start making money. This is another case were “Make it work, then make it better” can be the correct (and sometimes only) course of action.

We may not like it, but sometimes getting it to work right now is the right choice. These situations fall under the heading of consciously taking on technical debt with every intention of paying it back later and this is a very important business decision. If it’s a matter of “We can release it now and be able to make payroll” vs “It will take another month to make it perfect and we’ll be unemployed by then”, well, the choice is fairly clear then isn’t it?

Thankfully, most of the code we write doesn’t tend to fall into those categories, so we can make the effort now in order to make the code clean and maintainable, but we can’t ignore that those possibilities exist.

Making a law that is, on the whole, completely subjective and capricious is a just plain bad idea. As a general rule, when we write code that isn’t amazing, at worst we lose time in figuring out what is going on and/or fixing some bugs. Nobody generally dies from bad code (there are cases this is not true, but they are not the norm), and we can always make a conscious effort to improve it once the crisis is averted.

On the whole, yes, we need to strive to write clean, maintainable, bug free code, but we can’t be completely inflexible. If you want to make it a crime to write bad code, make the punishment be to learn how to write better code. I think that’s a fair sentence.
 

Current mood: Calm
Current music: Midnight Oil – Beds Are Burning

Friday, April 10, 2015

Encouraging the Next Generation



Recently, some of the people where I work have started a weekly writing prompt in order to get people to blog more often. This week's topic is “How do we involve the next generation of young minds?” and was inspired by two of my co-workers building quadcopters with a group of students in the northern part of the state.

This is a very open topic and very difficult to cover in a way that is less wordy than a copy or War and Peace (or at least your average work by Stephen King). However, I think it can be approached by breaking it down into a number of subjects which need to be addressed.

That being said, let's begin.


Start Them Early


The truth is that the earlier you start to instill curiosity and creativity in people, the easier it is to get them to continue on that path. There are a number of ways to do this, but if you're looking for ways to get a small child started, Legos, Lincoln Logs, Tinker Toys, etc are really a wonderful way to get the ball rolling. They offer nearly endless ways to combine pieces creatively, are tactile (which helps a lot of people, children or not. Never underestimate the value of physically building and handling something), and are generally fairly affordable.

Realize that not everything has to involve circuitry and code. Even things like basic woodworking projects can help instill creativity and the engineering mindset. I've built everything from birdhouses and toolboxes to actual buildings while I was growing up and I learned something valuable from every project.

As they get a little older, introduce them to things like crystal radio kits, 130-in-1 experiments kits (yes, they still make those), snap circuits and even simple programming languages like Scratch and Logo. A little later still get them involved in writing code on something like a RaspberryPi (it's fairly inexpensive and if you somehow manage to botch the os, just re-flash the SD card and start over. You can even extend it in order to interact with hardware). Tangoes are also a wonderful, inexpensive tool for teaching spatially related problem solving.

You want things that are simple to get a beginner's grasp of yet versatile enough to keep their attention after they master the basics and, most importantly, make them want to learn even more.


Mindset


“A mind all logic is like a knife all blade. It makes the hand bleed that uses it.”
- Rabindranath Tagore

Logic is a very important part of being successful in technology fields. However, there is another part of the equation that is often overlooked – creativity. You really do need both the ability to think your way through a problem as well as the ability to look at a problem from a completely different angle than other people at times.

We need to foster not only logical thought, but also appreciation of and involvement in the arts. I would almost argue that the type of art doesn't matter nearly as much as being involved. Painting, drawing, writing, music, theater, and countless others – all of these things exercise your brain in ways that simple logic based problem solving doesn't.

On the logical side, we need to encourage the next generation of technical people to cultivate the skills to look at situations objectively, come up with a set of possible answers, and then evaluate or work through them (revising their general assumptions as they uncover more information) until they reach a conclusion. This is the time for measured experimentation instead of just wildly poking at a problem until something happens (though, admittedly, sometimes poking at the problem is necessary in order to uncover behavior).

Encourage the next generation to ask questions. That's not to say that you should spoon feed them the answers since guiding them through the discovery process is both an extremely effective way of teaching and often fun for everyone involved. However you do it, you should encourage them to ask the “whys” and “what ifs”.

Continuing in the vein of asking questions, foster the questioning of authority. If someone says “You can't do that” they should ask WHY. If it's because doing that thing is dangerous, that's one thing. If it's just because they don't think it can be done or because of other foolish reasons (“getting above your station”, “that's not something that proper girls/boys do”, etc), they should be encouraged to CHALLENGE IT.

We are, among other things, professional troublemakers. We create and change current reality as a part of our jobs. It's what we do. Innovation is inherently disruptive. Embrace that; don't try to stomp it out of the next generation.

Encourage reading. I can't stress this enough. Fiction, non fiction, philosophy – just read. It exposes you to different voices and approaches from your own. It's literally a different view on the world, and being exposed to that will help you grow.


Quick Feedback, Small Victories


Make initial victories easy to attain. This is especially true for younger children. Defeat is frequently demoralizing. Starting off with a victory encourages people to continue. It doesn't matter if it's just making a ball bounce on the screen. Give them something that provides near instant feedback that they have done something with a real, visible result.

As they progress, keep feedback loops tight even though the difficulty of what they are doing increases with time. Yes, I realize that this sounds a lot like Agile practices.


Make it Safe to Fail


“I have not failed. I've just found 10,000 ways that won't work.”
- Thomas A. Edison

Failure, both professionally and personally, is an occasional fact of life. No matter what we try or how hard we work, there are times when things just won't happen the way we want them to.

The problem is that we have stigmatized failure to such a degree in this society that some people are afraid to even try because they might fail. This needs to stop.

Teach people that it's okay to fail on occasion. That's not to say that we should excuse laziness, but re-enforce the idea that failure occasionally happens, treat it as a learning experience, and teach others not to fear making a mistake.


Access to Tools


It may not occur to a lot of us in this field that not everyone is as well off as we are from an economic standpoint. Not everyone has ready access to the equipment needed to learn various technical skills. This is especially true in both poorer urban and rural areas.

Access to programing tools (IDEs, etc) has become considerably cheaper thanks to open source tools and educational/community licenses offered by companies like JetBrains and Microsoft. However, for some people, computers are still an expense that they can't justify (even if they are much cheaper than when I started learning to program).

That's not to mention the expense of things like quadcopter kits. Some of the things that you need access to for some projects are simply out of reach for a number of individuals as well as some school districts without outside help.


Access to Mentors


When I started out, I didn't have any mentors to help me learn how to code. The internet wasn't an option (yes, dinosaurs roamed the Earth and we had to walk to school uphill both ways). I had never even met or spoken to a professional software developer until I was in college. In fact, the only other people I knew who wrote code were a few friends in basically the same situation as myself.

It would have been much easier and a lot less discouraging if I had had access to mentors (even online) instead of having my only resources when I started out be the manual for a TRS-80 color computer and the occasional code sample in magazines borrowed from our very small public library (I told you that dinosaurs roamed the Earth at the time).

If you want to encourage the growth of a new generation of creative and technical people, you have to literally be there to encourage and guide them. Answer questions on the internet, make yourself available to schools/after school clubs and programs, and generally be a good community member.


Parental Involvement


This is the really difficult one. In order to encourage young people to go into technology based careers, their parents have to be positively involved. They can't just treat the computer as a way to babysit their child or, possibly even worse, view everything that their child does, no matter what it is, as simply “playing on the computer” like my parents did (which, I might add, included programming homework in college).

Keeping up momentum when it feels like nobody cares or you are being actively discouraged is extremely difficult. Not everyone is as hard headed as I am.

Parents don't even have to be experts in the field. They just have to be positive influences. Be curious about what your child is doing, encourage them, have them show off what they're doing to you a bit. Be a cheerleader. It's important.


Show Me The Money


Show people that there is a (generally) fun, well paying job doing work in this field and that it doesn't matter if they're a girl or a boy or even what socio-economic background they come from as long as they work at it. After all, it's important to be able to do things like pay your bills, go on vacation, and buy sandwiches.

As I said, this is by no means an easy problem, and this is only the short list of things that can be done to help, but it's a start and even if you can only manage a few of them that's better than the alternative.

Current mood: calm

Current music: Murray Head – One Night in Bangkok