background preloader

The Principles of Good Programming

The Principles of Good Programming
Heron-Centric: Ruminations of a Language DesignerThe Principles of Good Programmingby Christopher DigginsJuly 24, 2011 Today's post is a lightly edited repost from my blog at The Area, a web-site dedicated to users of Autodesk media and entertainment products. I came up with this list of principles to help with a recent C# training I gave, and I thought that members of the community could appreciate these principles and have some interesting insights to share. The principles of good programming are closely related to principles of good design and engineering. DRY - Don’t repeat yourself - This is probably the single most fundamental tenet in programming is to avoid repetition. KISS (Keep it simple, stupid!) Avoid Creating a YAGNI (You aren’t going to need it) - You should try not to add functionality until you need it. Avoid Premature Optimization - Don’t even think about optimization unless your code is working, but slower than you want.

Semantic Versioning How do you handle your Project Manager - Programmers - Stack Exchange Normal Stuff - API Design Principles English Русском One of Qt’s most reputed merits is its consistent, easy-to-learn, powerful API. This document tries to summarize the know-how we’ve accumulated on designing Qt-style APIs. Although these guidelines are aimed primarily at public APIs, you are encouraged to use the same techniques when designing internal APIs, as a courtesy to your fellow developers. You may also be interested to read Jasmin Blanchette’s Little Manual of API Design [] or its predecessor Designing Qt-Style C++ APIs [] by Matthias Ettrich. Six Characteristics of Good APIs An API is to the programmer what a GUI is to the end-user. In his Qt Quarterly 13 article about API design [], Matthias tells us he believes that APIs should be minimal and complete, have clear and simple semantics, be intuitive, be easy to memorize, and lead to readable code. Be minimal A minimal API is one that has as few public members per class and as few classes as possible. Be complete Be intuitive

Normal Stuff - Personal names around the world Background People who create web forms, databases, or ontologies are often unaware how different people’s names can be in other countries. They build their forms or databases in a way that assumes too much on the part of foreign users. This article will first introduce you to some of the different styles used for personal names, and then some of the possible implications for handling those on the Web. This article doesn't provide all the answers – the best answer will vary according to the needs of the application, and in most cases, it may be difficult to find a 'perfect' solution. Scenarios There are a couple of key scenarios to consider. You are designing a form in a single language (let’s assume English) that people from around the world will be filling in. In reality, you will probably not be able to localize for every different culture, so even if you rely on approach 2, some people will still use a form that is not intended specifically for their culture. Examples of differences .

Application structure: Concepts & Features I spoke about this topic quite a bit in ALT.Net Seattle. This is mostly relating to application architecture and how you structure your application. This is the logical result of applying the Open Closed and Single Responsibility Principles. Feature may not be as overloaded a term in our industry as a service, but it still important to define exactly what I mean. A feature creation may not involve any design activity. That is probably something that would raise a few eyebrows, but the idea is very simple. Let us take NH Prof as a good example. Session & statements Stack trace Loaded entities Reports Alerts Filtering That is it. As for features? Remember that a feature involves no design? We can get to this situation by paying attention to friction points, applying the Open Close Principle and utilizing conventions. A real world example would be NH Prof’s alerts. Let us say that we want to give an alert about too many joins. Adding this class means that NH Prof will: That is almost it.

You are NOT a Software Engineer! - You are not a Software Engineer. You do not build skyscrapers. You do not build bridges. You grow gardens. You are a Software Gardener. Do you try to plan your gardens in such detail that you know where each leaf will be positioned before you plant a single seed? You probably have a good idea of what your garden should look like a week into the future. If you were building a bridge or a skyscraper and you told me, before you began, that you knew exactly how it would look when it was finished – I would believe you. So why do so many gardens fail, yet so many skyscrapers succeed? Remember that time when someone in your company unsuccessfully used an Agile gardening methodology, and then went around saying that it was horse shit that doesn’t work? Unlike a skyscraper, your garden will grow weeds. In most countries, Engineers need a license to build a bridge. I am a Software Gardener. So are you.

The Usability of Passwords (by @baekdal) #tips Security companies and IT people constantly tells us that we should use complex and difficult passwords. This is bad advice, because you can actually make usable, easy to remember and highly secure passwords. In fact, usable passwords are often far better than complex ones. So let's dive into the world of passwords, and look at what makes a password secure in practical terms. Update: Read the FAQ (updated January 2011) Update - April 21, 2011: This article was "featured" on Security Now, here is my reply! How to hack a password The work involved in hacking passwords is very simple. Asking: Amazingly the most common way to gain access to someone's password is simply to ask for it (often in relation with something else). When is a password secure? You cannot protect against "asking" and "guessing", but you can protect yourself from the other forms of attacks. The measure of security must then be "how many password requests can the automated program make - e.g. per second". Like these: It takes:

Normal Stuff - Ovid at What to know before debating type systems Originally located at this article explained some basic concepts of type systems. Unfortunately, that page is gone and I had to fetch it from the web archive of that page. The note at the bottom states that contents are in the public domain, so I think it's OK to reproduce here. What follows is a short, brilliant introduction to the basic concepts of type systems, by Chris Smith. What To Know Before Debating Type Systems I would be willing to place a bet that most computer programmers have, on multiple occasions, expressed an opinion about the desirability of certain kinds of type systems in programming languages. There are a few common misconceptions, though, that confuse these discussions. Classifying Type Systems Type systems are commonly classified by several words, of which the most common are "static," "dynamic," "strong," and "weak." Strong and Weak Typing Probably the most common way type systems are classified is "strong" or "weak." Why?

How Not To Sort By Average Rating By Evan Miller February 6, 2009 (Changes) Translations: Russian Ukrainian Estonian PROBLEM: You are a web programmer. WRONG SOLUTION #1: Score = (Positive ratings) − (Negative ratings) Why it is wrong: Suppose one item has 600 positive ratings and 400 negative ratings: 60% positive. Sites that make this mistake: Urban Dictionary WRONG SOLUTION #2: Score = Average rating = (Positive ratings) / (Total ratings) Why it is wrong: Average rating works fine if you always have a ton of ratings, but suppose item 1 has 2 positive ratings and 0 negative ratings. Sites that make this mistake: CORRECT SOLUTION: Score = Lower bound of Wilson score confidence interval for a Bernoulli parameter Say what: We need to balance the proportion of positive ratings with the uncertainty of a small number of observations. (Use minus where it says plus/minus to calculate the lower bound.) You will quickly see that the extra bit of math makes all the good stuff bubble up to the top. Agresti, Alan and Brent A.

IoC container solves a problem you might not have but it’s a nice problem to have | Krzysztof Koźmic on software On frame­works and libraries A log­ging frame­work helps you log what's hap­pen­ing in your appli­ca­tion. A UI frame­work helps you ren­der and ani­mate UIs to the user. A com­mu­ni­ca­tion library helps con­nect­ing parts of a dis­trib­uted system. All of these tasks and con­cepts are pretty easy to under­stand. They are quite down to earth, and there­fore, at a high level at least, easy to explain. Also the code of your appli­ca­tion changes in order to use those frame­works and libraries. What about IoC container? So what about inver­sion of con­trol con­tain­ers? I got one of the IoC con­tain­ers, put it in my appli­ca­tion, and then all hell broke loose. Let's ignore the details for now and con­cen­trate on the wider sentiment. So? The sen­ti­ment is one of con­fu­sion, scep­ti­cism and frus­tra­tion. Truth is, those aren't nec­es­sar­ily the right ques­tions to ask. I have seen appli­ca­tions where intro­duc­ing a con­tainer imme­di­ately, would only worsen things. What isn't there…

Netflix Open Sources “Resilience Engineering” Code Library Hystrix: it’s the genus name for “Old World” porcupines, and it’s also the latest release from Netflix. But you won’t see it in their catalog of movie and TV titles, and you can’t add it to your queue, because it’s not content–it’s how Netflix makes sure its content is highly available. Now, Netflix has made Hystrix open source, for anyone using Amazon Web Services (AWS) to implement in their own cloud applications. Read on for details on this “resilience engineering” code library. Mention Netflix, and most people will think of the company’s DVD-rental-by-mail service or its growing library of “Watch Instantly” streaming video titles. This week, Netflix added Hystrix to its bag of open-source tricks. The Hystrix home page on GitHub defines the problem: [R]unning an application that depends on 30 services that each have 99.99% uptime we get: 99.9930 = 99.7% uptime 0.3% of 1 billion requests = 3,000,000 failures 2+ hours downtime/month even if all dependencies have excellent uptime.