Best Practices Software Engineers (Tue Dec 5, lecture 37)

Important note about today

While the homework is required, you may use the class time today for working with your team on your project. You can do this if you feel that would be a better use of your time or you’re not that interested in this topic. Just let me know ahead of time. Note: This is not 80 minutes free time:It is mandatory that you either come to class or work, face to face, with your team for the duration of class time.


  • What do you most want to know about being a professional software engineer?
  • What will stay with you for years, and what will evaporate this afternoon?
  • What’s the best way to spend the coming hour?

Programming Rules of Thumb

  1. You must a source control system. It’s your safety net. This is especially true when working with other programmers. Learn your tool so you are never reluctant to use it. GIT can be hard to master, but take the time to do so!

  2. Don’t go beyond the immediate requirement. Write only the code you need to solve the problem RIGHT now. You might think that this class clearly will need all this methods even though no one is calling them yet. This almost never works out. Don’t spend time to set things up for what you’ll need in a month. You’re usually wrong. This is known as YAGNI - You aren’t gonna need it!

  3. When your program blows up you should stop and read the error messages. Catch yourself jumpint to conclusions or seeing what’s not there. Fight the impulse that you know what must have failed. Often the right answer is right there in the error message. It might be buried in the middle of a lot of noisy trace output, but discipline yourself to actually read it. This is sometimes known as RTFM.

  4. Catch yourself engaging in magical thinking. If it worked yesterday, and not today, then something changed. Similar story as “It worked on my machine, why doestn’t it work in production?” Both of these are a symptom of magical engineering thinking. It’s just a computer. If the behavior changed, then something cause that change in the behavior. Methodically go through each thing that might be different and, like a scientist (or Sherlock) figure out what it was.

  5. Don’t be satisfied with blind luck Copying some code without knowing what is going on is not a good idea. Eventually it will come back to haunt you. Be really curious!. If a certain change fixed the problem, investigate until you understand how it fixed the problem.

  6. Learn to Debug Debugging is a craft in itself. Approach it like a scientist. Don’t poke blindly at the code, or solve the problem just by thinking about it. Have hypotheses to test. Do experiments.

  7. Don’t optimize early Optimizing too early is one of the cardinal sins of programming. You never know where the bottleneck will be, The thing you think will be slow, will be fast, and vice-versa. Actually you might end up ripping it out anyway!

  8. Keep a list of ‘technical debt’ items These are coding chores, cleanups, fill ins, removal of dead wood, that you purposely put off, even though you know you will have to come back to them. Later, when you want a change of pace in your coding, you can look at that list for some easy pickings!

  9. If you think you spot a code smell you should come back and eradicate it Train yourself to recognize (and HATE) code smells. Like nails on a blackboard, badly designed code should make your stomach turn or your skin crawl.

  10. Don’t cut and Paste code. DRY is a law. If you see any duplicated code it is almost always a bad thing. Look for it and kill it.

  11. Learn how to Refactor. This is a fundamental coding skill. When you see non-dry code or other violations, refactor ruthlessly.

  12. Don’t leave dead code behind. Delete it.

  13. Keep your files, methods and functions short Depending on the language and the program, the right number may vary. But a method that has more than 20 lines is almost always a serious code smell. A guideline would be 10 lines. A class that is more than 100 lines is a likely code smell.

  14. When designing software, you should keep concerns as separate as possible. Design for loose coupling. Pay attention to the Single Responsibility principle. Whether it’s a single class or function, a subsystem or module, or a whole system, minimize dependencies. Learn about dependency injection and other techniques for decoupling.

  15. When doing object oriented programming you should avoid using class inheritence While tempting, it is almost always better to avoid using inheritence in your class design. It brings undesireable coupling with little benefit that could be had in a simpler way.

  16. When programming you should use ‘intention revealing names’ Chosing the right names for classes, variables, methods is one of the best ways to ‘document’ your code. Follow your language’s naming conventions closely and then create names that reveal your intention. Name things after what they do, not after how they work! Also make sure names are internally consistent. (Ref: Intention Revealing Names)

  17. When programming, you should comment your code, but not too much. The exact line is a matter of (fervent) debate but it is almost universally accepted that having no comments is a bad idea and that its easy to have too many comments. Keep your comments at the start of each source file, and at the start of each method. Occasionally you might want to put a few lines of comments inline. But that desire often alerts you to a refactoring opportunity.

Personal Effectiveness Rules of Thumb

  1. When you have your best idea ever, you should remember that the idea is just 1% of the journey Yes, ideas are cheap. At least in the world of software engineering and product development, everyone and their grandfather have ideas that may be great. The distance between the idea and the reality is great. Here’s Steve Jobs about ideas

  2. Things change fast. Always be learning. Congratulations for picking one of the fastest changing fields around! Software engineering, programming languages, libraries, platforms, hardware and software are constantly changing. It take a real sustained effort to keep yourself up to date. Don’t be too proud that you know all the details of node.js or ruby on rails. That knowledge evaporates. The big, fundamental concepts, theories, philosopies, patterns change far more slowly. You need ot keep up your game.

  3. When learning new things don’t fall in love with the shiny toys It’s ok to be proud in your expertise and trying to perfect your craft. But platforms and languages come and go, and you must remain alert to newer and better ways to solve problems as they are invented. Don’t fall in love with a language or platform. It will change and the specific details you memorized will eventually become useless.

  4. When arguing about a design or a feature, you should stop and go ask a user. Good products don’t come from debate around a table, they come from discussion with the actual users. Don’t guess, don’t argue, go ask! This is known as “getting out of the building”.

  5. When you are spinning your wheels, you should stop, think, and only then act. Google It! The amount of knowledge and down and dirty solutions that you can find on google is infinite. See a strange error message? Google it! And learn how to edit the error message, removing the parts that are specific to you so that you get matches. Or ask on the right forum or mailing list. You need to learn how to ask a question in a way that it will be answered. Make it as easy as possible on the answerer.

  6. When you are posting on a technical forum, you should formulate the question carefully. Here are the best practices:
    • Explain precisely what you are trying to accomplish
    • Give a step by step explanation of what you’ve tried and the result.
    • Give code samples, links to github accounts, and so on. If the code samples are not brief, create a gist and put the link in the post.
    • Include listings of the relevant data, file names, console logs, and versions of various software you use.
  7. When you are writing a ‘business’ email, you should follow best-practices
    • If you expect action, have a single person in the to:
    • Know the difference between reply and reply all. Usually don’t reply all
    • The first sentence should state what action you are looking for
    • Keep it short and sweet. Make it “skimmable”.
    • Know your audience and write appropriately.
    • Get to the point. Be polite.
  8. When planning a project, you should work in short increments. Follow Agile practices, whatever your favorite flavor is, scrum, XP, Kanban, it doesn’t matter. Different teams and people like different approaches. And they change and evolve all the time. But there are eternal truths there. Work in small chunks. Even smaller. Even smaller. Don’t change many things at once because when your code invariably breaks, you won’t be able to tell why.

  9. When your project is late, don’t ADD people Most of the time this will slow you down. The reason is that with each additional person you add to a project you’ve created that many more paths of communication. If a project is late, adding people to it will make it later. See * The Mythical Man Month by Fred Brooks.

  10. When you have to write up a design or a spec, you should keep it to a few pages. Prefer writing short ‘stories’ over writing long ‘specifications. There is no requirements ‘phase’ to a project any more. Write many short stories and prioritize them relentlessly. If the story is more effort to write than the code, you should be writing the code!.


Many of these are from books, blogs and my own experience. I will list all the credits that I can identify but I think in some cases these rules are so deeply embedded that I cannot recall where I got them from. If you see sonething that you think you came up with, I appologize!

Look at next class