What makes a code-base well designed and maintainable?

What makes a code-base well designed and maintainable? What underlying principles or qualities do you look for in a system of classes that tells you they are well designed and maintainable?

As there are many things, I will mention a few in the form “a over b” (a is more important than b, but b is also important).

Local consistency over global consistency: You are doing a one line change to a module. That module has good style, but is not the house style. It does not make sense to rewrite the whole module. It is not a good idea to mix styles within a module. Therefore do the change in the existing style.

What it does over how it does it: Every module supplies a service to other modules (its clients). It is important to be able to know what a module does without reading all of its code. It should be possible to easily read the client code without reading the code of its suppliers. Therefore design the module interface so that client code reads as clearly as possible.

Working code over fast code: It is more important that code does the correct thing than it is for it to be fast. It is difficult to write correct fast code, moreover most attempts to write fast code will result in slow unreadable code. Therefore first write working code with tests, then if necessary speed up the code, with tests to prove you sped it up.

Readable code over working code: If you have to make a change to existing code, that is almost unreadable, it is difficult to do correctly, you will wish it was well written the first time. If you find yourself in this situation, then first rewrite the section of code, so that when you break it (which you will), you can fix it.

Readable code over comments and documentation: Comments and documentation quickly become out of date, and good documentation is no substitute for badly written code. Therefore whenever you are tempted to add a comment, fix the code to make it more readable. Exceptions, answering why questions in code is hard (maybe impossible) so maybe add a comment explaining why you did it that way. Automatically generated documentation, extracted from the code, is good. Some times a lack of expressiveness of the language you are using, e.g. lack of design contracts, will lead you to need to use a comment.

Teach Free Software and programming

We have been putting a lot of effort into teaching kids to program, over the last few years. This is a good thing, bit is it having the effect that we want?

I accept that there is intrinsic value in learning to code. In the same way that we should learn poetry. However what practical outcomes are we expecting?

Why are we doing it? Is it to train them to do programmer jobs? If so this is wasting the time of most of them. Is it too free them, to become masters of their own devices? This is a good idea, BUT if we look at the table below, we see that we may not be achieving this.

typing-handcuffs

Our options when we want a change made to some software
Beg owner Ask/pay someone Do it yourself
Free Software Non programmer
Programmer
Proprietary software
Non programmer

We are still teaching the use of proprietary software. If we wish to make a change to proprietary software, then (programmer or not) we have only one choice, to beg.

  • Using Free Software adds to our freedom.
  • Learning to program adds to our freedom.
  • But learning to program gives no freedom other other peoples programs, until those programs are Free Software.

Free Software is software that gives you freedoms, it is not about price.

A program is free software if the program’s users have the four essential freedoms:

  • The freedom to run the program as you wish, for any purpose (freedom 0).
  • The freedom to study how the program works, and change it so it does your computing as you wish (freedom 1). Access to the source code is a precondition for this.
  • The freedom to redistribute copies so you can help your neighbour (freedom 2).
  • The freedom to distribute copies of your modified versions to others (freedom 3). By doing this you can give the whole community a chance to benefit from your changes. Access to the source code is a precondition for this.

See also these other related posts on Free Software.

Computing in school — comparison with water.

I teach computer science, not computer products. We need to stop pushing products.

Schools should be teaching computer science and IT, not products. At this time computers are set up as office tools, and many IT-support departments work in opposition to teaching computer science and IT. We look to the companies that sell software to teach us about software.

This is like asking Evian to help with pupils swimming classes, just because they make a lot of money selling water. Yes we can ask them to provide money, but often they, instead, send a crate of bottled water, and we get the pupils to try to swim in it.

There is nothing wrong with a bottled water company sponsoring a school. However we should not be using their water. It has been shown that bottled water costs about 1000 times more than tap water, in most places in the world the tap water is better than more than half of the bottled water, and in blind taste tests people can not tell the difference. The argument that it is provided for free to schools is irrelevant, this is a marketing ploy to create dependence (“first one’s free”). It is not about price, it is about education. Another thing these companies do is to move in to a region, and start pumping out water, so that there is none remaining for the local population. They then step in with a solution “buy our bottled water”. In parts of the world with a strong legal system there have been court cases (e.g. in the USA), but the companies have argued that it is not there fault “it was a bad year, it did not rain”. The fact that this was not devastating in the past, because there was not a big company extracting to much water, seems to be irrelevant. In other countries it does not even go to court.

This is exactly what is happening with computer software. We need to teach students to be responsibly empowered, to use computer in the way that will enhance there lives, and not be dependent on big corporations.

Therefore Microsoft, Apple, Oracle, Google, Facebook, … should have no place in the classroom. We should start this by not promoting them. We should then start removing them, so that pupils can learn, better, how computer work and how to use them.

What is a computer virus?

Let me answer what turns out to be a simpler question. What is a virus checker?

Let us imagine that your computer is a house, and it is under attack from criminals. Maybe a little, maybe a lot, just like a normal house.

You decide that you need to secure your house, so you by the most sophisticated intruder detection system. It will photograph, scan, fingerprint, anyone approaching the house. If it recognises a person, and that person is in the criminal records database, then it will not let them in. All other people are allowed in. If the person is wearing gloves and a mask then they are not recognised and are let in. If they have not get been caught, then they are let in.

Alternatively you get a lock, and issue keys to the few people that you want to access your house. You may get a cheap lock or a very good lock. Ever way you probably will not come home to find that your neighbours kid has wandered in, and is sitting watching your TV.
Therefore stop trying to detect viruses, and protect your computer properly.

Amendment:

  • Behaviour monitoring is a good idea, some software named anti-virus, may do this. Do your homework, find out what it dose, and how. Decide if it will be effective.

Some useful tools:

  • Mandatory access control is also useful (such as apparmor).
  • Mount options such as nodev, noexec, …
  • Firewall
  • Secure software repositories such as Debian, so that you are not downloading random software.

Today I was asked “What changes would you make to the [IT] national curriculum [for the UK]”

Today I was asked “What changes would you make to the IT national curriculum”. So here are my answers:

  • It says “use 2 or more programming languages, at least one of which is textual, to solve a variety of computational problems …”. I would add that the languages should be different, though I have not worked out how to define different, but C# and Java are too similar, C# and Visual Basic are too similar, C and C++ are too similar.
  • Next I would add “use 2 or more operating systems, at least one of which is textual, to solve a variety of computational problems …”

Web access not working, but internet is — on “3” (three.co.uk) mobile

2015 early

My web access stopped working recently, although the rest of the internet services where working ok: ssh, imap, dns, etc. It was affecting all web browsers on the phone, and tethered computer.

So I phoned tech support at three.co.uk. They sounded surprised when I told them “web access in broken, but the internet is working”. On the first call we tried many things, mostly to do with the web-client (browser). But then eventually we reset the APN (Access Point Name), this fixed it for a time, but not for long. I ended up having to reset the APN regularly, and often it did not work. The process was something like: power off, reset APN, pray, turn internet off and on again, test, and repeat.

2015-02-17

Today I phoned again. After many wrong paths, we tried to delete the APN, but this saw not possible, so we added a new one. This is the configuration we set for the new APN: Name=3 WAP, APN=three.co.uk.

So far it is working.

2017-11-15

It has been unreliable again. I went to APN setting, reset to defaults, then followed what I did in 2015-02-17. Seems to be working, but only been a few minutes since I did it.

Software, In the beginning.

This article only concerns the world of computers. If you never use a computer then this is of no use to you, stop reading now. But if you do then read on.

In the beginning [of the world of computers], there was Software, and the software had Freedom, and the Software was Free. The Software had freedom in the beginning. Through Free Software all computations were made; without Free Software no computations were made that have been made. In Free Software was life, and that life was the light of all mankind. The light shines in the darkness, and the darkness has not overcome it.

“Free software” means software that respects users’ freedom and community. Roughly, the users have the freedom to run, copy, distribute, study, change and improve the software. With these freedoms, the users (both individually and collectively) control the program and what it does for them.

When users don’t control the program, the program controls the users. The developer controls the program, and through it controls the users. This nonfree or “proprietary” program is therefore an instrument of unjust power.

Thus, “free software” is a matter of liberty, not price. To understand the concept, you should think of “free” as in “free speech,” not as in “free pizza”.
The freedom to run the program, for any purpose (freedom 0).
The freedom to study how the program works, and change it so it does your computing as you wish (freedom 1). Access to the source code is a precondition for this.
The freedom to redistribute copies so you can help your neighbour (freedom 2).
The freedom to distribute copies of your modified versions to others (freedom 3). By doing this you can give the whole community a chance to benefit from your changes. Access to the source code is a precondition for this.

Do we need Free Software — How can we bring about a socially just, environmentally sustainable, and spiritually fulfilling human presence in our computers?

https://ctrlaltdelor.wordpress.com/2013/01/10/free-software/ — part 0 Introduction

https://ctrlaltdelor.wordpress.com/2013/02/10/free-software-where-are-we-now/ — part 1 Where are we now?

https://ctrlaltdelor.wordpress.com/2013/03/10/free-software-how-did-we-get-here/ — part 2 How did we get here?

https://ctrlaltdelor.wordpress.com/2013/04/10/free-software-what-is-possible-now/ — part 3 What is possible now?

https://ctrlaltdelor.wordpress.com/2013/05/10/free-software-where-do-we-go-from-here/ — part 4 Where do we go from here?

A missing pattern: Command, Query, Observer and ???

When I read about the observer pattern in design patterns, I though but what about the other patterns. By this I mean the other patterns that govern the communication relationship between exactly 2 already existing objects.

There is a finite set of patterns governing the relationship between 2 objects that already exist. This finite number I believe is 4. (These relationships do not involve creation or destruction.) The 2 objects may have any combination of these relationships.

Notation

UML is inadequate for what is being shown here, so I have used another notation.

Rectangular box
A rectangular box represents an object
an arrow with a solid line
An arrow with a solid line, represents data flow
an arrow with a dotted line
An arrow with a dotted line represents control flow.
an arrow with a zigzag line
An arrow with a zigzag line represents synchronization, when to do something. A simple method call with possibly no arguments and no return value, and no action except to tell the called object that something has happened. The called object then synchronously does something.

The patterns — but only an introduction

Command

Also called: procedure.

Uses: method, routine or sub-routine
Used by: Command Query Separation
Implements: Setter, Do-er

Command methods/sub-routines should be verb phrases.

A Command is a method/sub-routine or even a code fragment, used to make an object do something. A command can be passed data, but can not retrieve(return) data, in it self. The command read-line-from-file returns nothing, though it will change the state of the object, the object will store this line of text and any error condition.

A controls and passed data to B

Query

Also called: function

Uses: method, routine or sub-routine
Used by: Command Query Separation, functional programming
Implements: getter

Query methods/sub-routines should be noun phrases, unless the return type is Boolean, in this case it should be an adjective phrase. It should not start with the verb get.

A Query is a method/sub-routine or even a code fragment, used to find out something about an object. A command can retrieve data, it can except data, but it can not change the object.

A controls B, but B passes data to A

Observer

Uses: method, routine or sub-routine
Used by:
Implements: dependency inversion

Observer is used when B is in control, but A knows when things need doing.

B Queries A, but at A's request

Note: It is an anti-pattern, to use observer to update state in B when state in A changes. Use Query chaining for this. Use observer to update objects that you do not know if they are being queried, e.g. a display that is queried when a person looks at it. Or to trigger processing, that can not be deferred e.g. event logging.

The other pattern

Also called: to be decided

Uses: method, routine or sub-routine
Used by: see below
Implements: see below

So first we see from the diagrams that the following diagram has not yet been described.
B Commands A, but at A's request

When I looked at this diagram I realized I had seen it before. It us used in Graphical User Interface frameworks, when there are multiple overlapping windows. If a window is covered the windowing system may forget what is covered; When the covered window is exposed the windowing system can not on its own redisplay the missing region. It therefore sends an expose event to the owner of the uncovered window. This owner then sends commands the the windowing system to redraw the area.

Used by: Windowing system, …
Implements: Refresh, …

Part 4 — Do we need Free Software? — Where do we go from here?

Try it

You can get many Free Software applications for Microsoft-Windows and Apple-Mac, but to really appreciate it you will need to run a Free operating system such as Gnu/Linux.

Debian Gun/Linux (and many others) will run directly from CD/DVD (live CD), so you don’t have to install it to try it.

Migration

“So how do I start using free software, I use xyz, I can’t change, I depend on abc.” Your current software provider does not care about your freedom. Sorry this is not fair, they do care, they care that you have none: They are actively trying to take away your freedom. This includes the freedom of choice, the freedom to change your mind, to use alternative software. They do this my making there software not interoperate, and by scaring you: telling you the other software is “incompatible”.

So you are locked in, how do you escape, don’t panic it is possible.

We will now look at migration roots. If you are new to computers you are lucky it is easy for you. However you will probably have the most fear, and need the most support. However if you are well entrenched you will need a migration strategy. You will need to start to move to a new way, but if you try it all at once you may fail. First I will show some things to consider, then show some ideas of what you can change.

Levels of freedom

  1. AwarenessThe most important step, if you miss this step you may be tempted by non-free software.
    It is important to value your freedom, to fight for it and to pay for it;
    Be prepared to pay more for Free Software than for non-free software.
    Remember Free Software is about freedom not price.
  2. Avoid lockin — use open standards (file formats / network protocols)It can be hard to change; We have been using software that uses proprietary formats, to lock us in, for years, so it may be difficult to change. Ironically it is easier for new users to adopt Free Software, but these are the least confident to do it on there own (so ask for help, or offer help depending on who you are). However it is still possible to change, and the sooner you do it the easier it is. An important step is to avoid lock-in by using open protocols/file formates.
  3. Use some Free SoftwareYou can run some Free Software on Microsoft Windows, Apple Mac and other proprietary systems.
  4. Install a Free operating system, such as Gnu/LinuxYou can install Gnu/Linux on most hardware including PC and Mac.
  5. Use 100% Free Software

Other factors

  • Free market vs closed market.
  • Free file formats / network protocols vs Locked-in.
  • Multiple supplier vs single supplier.

Migration Tools

  • Free Software is well established on servers, if you are running a business then migrate you servers to Free Software.
  • Stop generating files/documents in non open formats: Continue to use the old proprietary software only to read old files/documents, and configure the old tools to write open formats — Microsoft Office can now be configured to write Open Document Format.
  • Look at what Free Software applications are available for your current operating system.
  • Try out a Free operating system using a live CD/DVD.
  • Install a Free operating system, duel boot or in a virtual machine.
  • Then when you are doing most stuff with the Free system, put the old proprietary system in the virtual machine, with the Free system as the main system.

Above all find someone that can help you.

We have looked at reasons to use Free Software, but why write it?

  • Because it is the right thing to do.
  • Because I can be part of a community.
  • Because it gives be an opportunity to learn and extend my skills. http://www.youtube.com/watch?v=qN7u1j44QTo&feature=colike
  • Because I want to give back, in gratitude for what I have received.
  • Because it well reduce my maintenance costs.
  • etc.

Be careful with language

Alternative names and confusing words

What about alternative names to avoid confusion of the word free, such as Open Source?
Some people use the term “Open Source”. Most software that is Open Source is Free Software. But the ideas are different.

In a mailing list post, MJ Ray FROM the Association For Free Software described some of the reasons why they strongly prefer the term “free software”:–

“Open Source” is an ambiguous phrase with definitions FROM OSI, !OeE, Becta, Microsoft(!) and many others. One of the original reason for the Open Source Initiative was to remove ambiguity by securing a trademark on the phrase (wishful thinking?) and to clarify things through marketing it. However, they didn’t get the trademark and their marketing effort is dwarfed by other people defining “open source” as other things. The Free Software Definition is simpler and the ideas have had 20 years or so to establish themselves.

Another reason for “Open Source” was to remove the connection with the ideas of sharing and being a good member of the community. From what I heard at the conference, those are still very popular ideas with people working in education. Some people class promotion of these ideas as political. I guess in that case, Chris could call AFFS a political group. Oh well. I’m not sure why it would be less popular with educators or why it should stop us promoting free software for the practical benefits too, though.

If you sympathize with the goal of providing effective promotion of our preferred software licensing, please use the older term “Free Software” and do the relatively simple explanation about “free as in freedom.” Ambiguity and division never help marketing.

note: Freedoms 1 and 3 require source code to be available because studying and modifying software without its source code is highly impractical.

The opposite of Free is proprietary, do not use the word commercial; Free Software can be exchanged for money, it can be commercial.

Do not use the word Intellectual Property. It lumps together many concepts, and allows the idea of theft to be applied. You can not steal in idea, as you can not take it off of somebody. They still have it, and you have it. You copied it, you grew it, there is now more of it than there was before.

Some people say “for free” this is not the same, you can sell Free Software.
Some people say “Freeware” or “Shareware” these are term that refereed to something else.
Some people say “free download” this is the same at “free of charge” is Free Software.
Some people say “Linux“ Linux is the most common kernel used in Gnu. If we refer to Gnu/Linux as just Linux, then what do we call Linux. Android phones contain Linux, but (usually) not Gnu. When you hear that Android contains Linux you may be fooled into thinking is like your desktop (Gnu/Linux).

What are we for, what are we against

We are not against anything, we are for freedom. We would like you to have freedom when you use your computer, but we are not saying you should use a computer.

We are not against the software companies, no, we believe that people should be free to sell software, including Free Software.

This is about your freedom, not about the suppliers. You have to demand Free Software (and be prepared to pay for it), or you won’t get it.

Summary

  • Free Software is about your Freedom, not about price.
  • We believe you will be free only when your device is free.
  • We believe that your device is your device.
  • We believe you should be able to decide what you want to do today.
  • We believe you should live in a world without walls, fences and gates :-)

What will you do next?

  • Try some Free Software today:
    • Download and use some Free Software for your current System.
    • Download a live Gnu/Linux System, and try it out.
    • Ask for help?
  • Tell other about Free Software.
    • Tell people what is happening and what exists.
    • Tell people about Freedom.
    • Use the words Free Software and explain what Free means (Thus, “free software” is a matter of liberty, not price. To understand the concept, you should think of “free” as in “free speech,” not as in “free beer”).
    • Share a link to this blog.
    • Take the material improve it and share it.

Other resources

Popular

https://www.openoffice.org/
https://www.mozilla.org/

Other Free Software for windows

http://opensourcewindows.org/
http://osswin.sourceforge.net/

Other Free Software for Mac

http://opensourcemac.org/

Free Software Operating Systems

http://www.debian.org/ — version 7 was released on 04 May 2013

About Free Software

http://www.fsf.org/


See a list of all my blog posts on Free Software at https://ctrlaltdelor.wordpress.com/tag/free-software/

Licenses: Creative Commons License
Free Software by Richard Delorenzi is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Part 3 — Do we need Free Software? — What is possible now?

What is possible now

Free Software is growing fast. It is the fastest growing software sector, Microsoft’s have stated that it is there only real competitor.

Free Software is everywhere, you already use it:

  • A netcraft graph, showing what web-server software is used on the internet.Free Software web servers are running most of the Web. This graph shows that Apache (Free Software) is the most popular web server since 1995, before that NCSA (Free Software) was the most popular. nginx (Free Software) is growing in share, it may overtake Microsoft (proprietary) soon. In some of Netcraft’s graphs it already has.
  • Most of the infrastructure on the internet is running Gnu/Linux or BSD, both Free Software operating systems.
  • Most of the e-mail transport and Domain Name look-up is done on Free Software.
  • Google, WordPress, Wikipedia and others run on Linux and other Free Software. Even Hotmail (a Microsoft web mail server) runs partly on Linux.

Most of the top 500 super computers use free softwareScientists use Linux: Of the 500 fastest computers in the world 457 run Linux (Free Software), 1 BSD (Free Software), 1 Open Solaris (Free Software), 11 mixed Linux (Free Software) plus other, 28 run AIX Unix, 1 runs CellOS Unix and 1 runs Microsoft-Windows. That is 459 Free Software, 11 mixed, 30 Proprietary.

It is not just for geeks; The geeks saw the need first, but then others started joining in.

Chances are your web browser is Free Software
Chances are you are already using Free Software. Firefox and Crome account for about 50% and rising of browser use. They are Free Software. IE the default of Microsoft windows has under 50% and falling. OpenOffice.org, VLC, Audacity, Gimp, Inkscape, Filezilla, X-chat, PeaZip, Juice, Mplayer, Thunderbird, Miro, Pidgin, Transmission, zenmap, wireshark, Kdiff, mono, python, sub-version, VirtualBox(gpl version) to name a few, are all Free Software.

Screen-shot of KDE a windowing system used on Gnu/Linux
Free Software on the desktop. The Free Software desktop is as easy to use, or easier than Microsoft-Windows and Mac. It looks very similar, the change is like going from Windows XP to Windows 7, only better. Free Software had 3D desktop effects before Microsoft-Windows.

The Free Software that is produced not only is free, but is also low cost; You can usually download it for no charge, or get it for a few pounds (Free as in freedom, not as in free of charge). It also tends to be of higher quality than non-Free Software (as the motivation of the developers is to produce software not to make money, and because anyone can fix it).

Debian Gnu/Linux comes on 6 DVDs, though you only need one CD no get the core system. It includes pretty much all the software you will need. Equivalent to Microsoft Windows 7 Professional, plus Microsoft office, plus Microsoft Visual studio Professional, plus Microsoft Server, plus, plus, plus … . No Licenses to worry about. Just one single install for the base system, then just click to add applications.

List of organizations:

  • Free Software foundation
  • freedomdefined
  • Free art
  • Internet Engineering Task Force
  • Open Knowledge
  • Open Source
  • Free/Libre Knowledge

See a list of all my blog posts on Free Software