## Maths, context and culture

I was reading this post by Dan Meyer on pseudocontext in maths problems.

If we invite pseudocontext in our classrooms without condition, it becomes harder and harder to tell the difference between the real and the unreal.

Back when I was young, a lot of maths problems made little sense to me. In those days, the maths syllabus up to primary 6 (at 12 years old, or grade 6 if you’re in America) wasn’t particularly hard. At least to me. I’m not bragging, I’m just saying that the education system made things more difficult by introducing word problems. The epitome of conquering a maths exam paper was solving all the word problems at the end.

Word problems were created to introduce another element into elementary math (to make them difficult?). They added language. Suddenly it was something like:

John, Fred and Ken had \$5 total. John bought 10 red marbles and Fred bought 12 blue marbles. If 1 red marble costs \$0.10, and 1 blue marble costs \$0.15, how many blue marbles can Ken buy if they still want to have \$1 left?

Your command of the English language became a factor. But it was still ok, because the wording usually formed a pattern. It was marbles, people’s ages, number of apples or oranges in the basket, or some such. In a normal situation, if I really wanted to know your dad’s age, I’d just go ask him. I don’t really need to infer that your dad is 2.5 times your age, and then I figure the answer out (assuming I know your age).

### Students here kill each other with A’s

Now if you don’t already know, it’s bloody competitive here in Singapore. Students are afraid of not doing well in school, of heads shaken by their friends, teachers, parents and relatives. Parents send their children to tuition classes (in addition to the normal school classes), regardless of their children’s grades. If the grades are bad, then improve them. If they’re great, great! Now perfect them. Go do your ten year series!

I went to tuition classes till I was 10 years old (primary 4 or 4th grade). I stopped because my dad couldn’t afford to pay for the classes. Being able to eat and pay the bills were more important. It’s a good thing I was disciplined enough to get good enough grades (and imbue enough motivation for all subjects, not just maths).

When I was in university, to supplement the cost of education, I looked into giving tuition. I was surprised that everyone from primary one to university level (?!) were asking for help. Let me just say, I make a lousy tuition teacher. I don’t really know the current syllabus well enough to help the students. Once, I brought up the subject of video games, using the position of battleships to illustrate … something. I can’t remember. I think it was x- and y-coordinate stuff. I was trying to interest the young boy I was teaching. It fell flat. I suck…

### The Singapore Math Method

Which brings us to curriculum. It turns out that under the Singapore maths curriculum, Singapore students rank high for maths internationally. It’s so good that America has adopted the method. There’s even a name for it: Singapore Math Method. Let me tell you, I’m simultaneously amused and confused.

I’m even more surprised that Israel adopted the method in 2002, translating the textbooks to Hebrew. I was browsing in the bookstore reading Start-up Nation (Amazon link). It told a story of how Israel, being surrounded by hostile countries, had to innovate hard. Their brightest people are in the universities doing research and are also in the top military ranks. The book told a story of how the “flat” nature of their military translated to their way of doing businesses, in particular start-ups. My friend Christopher told me that per capita, Israelis were the richest in the world. It’s their culture that made them more inclined to creating wealth. I was also told about the Jewish mother syndrome… So I’m a little surprised that this group of people want to know about our (Singaporean) method of teaching maths.

I still believe in solving real world problems. I believe we’re not injecting enough curiosity into our students. That Singapore Math Method seems to have less force-feeding of concepts, and more of coaxing the student to question. The Singapore culture doesn’t seem to require curiosity for the students to do well (have I mentioned the parents are bloody competitive?). Hopefully, that’s changing.

This is going to be a cynical view, but I think most Singaporeans are striving for wealth, and wealth alone. Wealth translates to a better life. There’s nothing wrong with that. Singaporeans strive hard to attain wealth so they can forget about (seemingly) miserable lives. Ok, let me take that back. Apparently, Singapore is one of the happiest places in the world. There’s a “but” though…

Singapore ranks high on evaluated happiness, but not on experienced happiness

Alright, this is starting to depress even lil’ cheerful me…

So. Problems are formulated, and then given to our students to solve. But they have to learn how to formulate problems too, and that comes from asking questions, from being curious, from being disciplined and persistent. And that comes from cultural and societal influences, not from educational systems.

## Pure programming knowledge is not enough

I’m short-sighted. The degree of blurriness isn’t terrible, so I can still make do without glasses. When I first started working, I thought working with computers the whole day warrants the wearing of glasses, so I got myself a pair. Turns out to be more trouble than it’s worth…

[image by Gene Chutka]

Anyway, I found out about it when I was in university, when I couldn’t see the notes on the projector screen or on the board properly. I’d have to sit in the first 3 rows if the words were to be clear. But the first 3 rows were occupied by uhm, zealous students, so I took seats slightly further away.

Since I couldn’t see much of the notes, I squinted. To forestall some of the obvious questions, no, vanity had nothing to do with not wearing glasses. Glasses were expensive, and so were contact lenses. And they’re really troublesome to wear on a regular basis. So yeah, no glasses.

To compensate for my “loss” of sight, my other abilities stepped up to take on the responsibility. After 2 and a half years of serving the nation (National Service in Singapore), I was suddenly very productive. I paid better attention to the lecturer. I listened carefully.

Since I can’t see very well, I got context from surrounding words. My language skills helped a lot, filling in grammar, spelling and sentence structure. In both proper and “broken” English no less. I was studying math, and my math background helped in making sense of the symbols and the esoteric language used, filling in gaps where my language skills were useless.

With perseverance, lots of context filling (from language and math), I got most of the lesson. I actually took very little notes, since I couldn’t copy them fast enough anyway. I opted instead to understand what the lecturer was teaching and try to quickly absorb them.

I’m not so much concerned with seeing the words correctly, but interpreting them correctly.

The squinting… Now the squinting seemed to blur the words even more. But I saw the words more “clearly”. It’s like holding a picture close to your face. It’s blur, and you can’t make out anything. Take it further away and you can see the picture. It’s something like that. I needed to “blurrify” the words so they became meant for far viewing in my case. Sort of like Nazca Lines.

After I graduated and started working, I got myself a pair of glasses. Then I stopped wearing them. I haven’t needed to read words at a fair distance. And the computer screen seems to read fine. I take regular breaks to rest my eyes. Besides, wearing glasses gives me a headache and dries my eyes easily. Sometimes, I still wear them, and only for reading books and playing video games (otherwise I can’t see the dialogue on the TV screen).

### The lesson?

When I read code, be it other people’s code or mine, I use a lot of context filling. Half the time, I’m using my knowledge of business logic, human psychology and languages (English or otherwise) to understand the code. The other half is programming knowledge.

It’s when I do this that I figure out patterns, of decisions made (where devoid of comments). That I understand where I needed to make changes for new business logic. That I can do simple refactoring (the refactoring is simple. It’s the understanding that’s hard. Different programmers do the same thing differently).

I found that when reading code, whether because of debugging or adding changes, pure programming knowledge isn’t enough. For example, if I knew the original programmer wrote that piece of code far in the past, I could make a guess as to why he wrote it that way. Say he’s trying to optimise a piece of code, but the optimisation is no longer relevant in modern times.

It bears repeating. Pure programming knowledge isn’t enough.

## Why you need linguistic skills – part 2

In a previous article, we explored the reasons for bad variable naming. In this article, we’ll look at why your basic spelling and grammar skills are important, and using your context-based linguistic skills in reading code.

### Simple language

Frankly speaking, you just need basic spelling and grammar skills. I mean, it’s not like you’re asked to code stuff about the number of defenestrations or keeping track of myocardial infarctions. Unless, of course, you’re working on a medieval game where throwing people out of windows is fun or a medical application predicting the likelihood of heart attacks.

For the most part, you’re working with concepts such as user IDs, names, sums of something, billed amount, tax amount and so on. These concepts are likely to be commonplace. If not, they would be explained in a business document. The hard work of naming variables is already done. You just need to name those variables. How hard can `sName` or `iSum` be?

All you really need to take care of is spelling and simple grammar. Why spelling? It’s easier to read and it’s easier to find. Imagine you need to do some refactoring, and you have to replace all references to “Result” to “Case”. You thought your find-and-replace was done. Then you find an instance of “Rslt” or worse, “Resutl”. The worst part is you don’t know if you’ve completely replaced every instance correctly, including those weird cases.

As for grammar, let’s look at the simple case of plurality. `GetResult()` suggests the return of a single record. `GetResults()` suggests the return of possibly more than one record, maybe a list or an array. An unimaginative programmer might name the second function `GetResult2()`, which tells us nothing whatsoever, other than it’s possibly another form of `GetResult()`.

This reminds me of something baavgai from Dream In Code said about naming database tables and columns. If I remember correctly, he suggested using the singular form, for example, “customer” for the database table storing customer information. This way, the “customer_id” column makes sense, instead of “customers_id” in the “customers” table. Even if the computer doesn’t care either way, please use appropriate singular or plural forms, for the sake of other human beings.

If spelling errors and inappropriate forms in code are travesties, spelling errors and inappropriate forms in database tables and columns are abominations! The database is the backbone of everything you code. If a table name is changed, can you imagine how many applications are affected by the name change?

Back-end programs, console programs, web applications, stored procedures. Every single one has to be checked and corrected. It just takes too much effort, so the table name remains incorrectly spelled.

Let’s go back to spelling for a bit, in particular, short forms or abbreviations. Don’t use them. Spell the word in full. Not everyone can decipher `decBillAmt` as billed amount (take note of tenses too). If the shortened form is widely known, or reasonably well known within the context, then by all means use the short form.

There was this time where a senior level manager was reading through the documentation to find out more about the nuts and bolts of our application. He stopped at `AcctNo`. He asked, “What’s account no?” He managed to decipher “acct” as “account”, but couldn’t make head or tail of what “no” means. The negative of “yes” didn’t fit the context. We had to explain it stands for “account number” in full. Shortening words for the sake of short forms is not an excuse for illegibility.

There’s also this instance where my colleague asked me what `mstIptRec` was. I thought for a bit, racking my brain for the business logic involved, scouring the surrounding code for clues and sifting through my vocabulary to fill in the missing letters. I came up with “master input record”. Make your fellow programmers’ lives easier; spell the word in full.

### Filling in gaps

Nothing has meaning except the meaning you give it.

This brings us to the next point, understanding your fellow programmers’ code. You may be a skilled programmer, but the sad truth is, you’re going to read other people’s code, and let’s face it, some of them are terrible.

You are able to understand what “i can has cheezburger” means because you can rearrange words and fill in letters. Your problem with code is that, well, the compiler has already “approved” the other person’s code. You know, by successfully compiling it. The compiler has already understood perfectly what the code has to do. You’re the one who’s in trouble.

Since the syntax (grammar) is correct, and the spelling is correct (compiler will have choked on “`ant i;`“), you have to look at the variable names, function names, class names and so on to decipher meanings. This is where your linguistic skills come into play. You need to fill in the context. This is crucial to your quick understanding of another person’s code, maybe even your own.

Compilers are incredibly unforgiving when it comes to syntax, yet unbelievably forgiving when it comes to context.

Remember, you’re the only one who knows if

```int i = 2 + 3;
```

should be

```int i = 2 * 3;
```

## Why you need linguistic skills – part 1

While writing code may seem very logic-based and technical in nature, your skill in human languages is equally important. Why else would Visual Basic read like English? In this series of articles, I’m going to talk about why improving your linguistic skills make you a better programmer.

A limited range of vocabulary restricts your imagination. Part of imagination requires you to describe something. The more words you can use for describing, the more vivid, the more exact and the more complete the object of description becomes.

As a programmer, you have to translate business logic, task requirements and given instructions into code. The better your grasp of language, the better you’re able to imagine the final product, and thus the better you’ll be able to visualise the code and write it. What it comes down to is you must understand something that someone else wrote. You need to know the nuances of your language of choice because that someone may have wanted one thing, but actually wrote something else.

For example, in one of my user task requests, there was this requirement about entering random input. Based on the business context and the web form that was to support this feature, I deciphered it as being able to enter any range and any number of input in a specific format. I checked with the user, and it was indeed that way. Sometimes users lie, unwittingly perhaps, and in this case, using the wrong words to describe what he wanted.

### Give it a name

What’s the one thing you do every time you code that requires linguistic skills? Name your variables. Every time you declare a variable, you make a conscious choice on what that variable’s fate in the ensuing code is. Every time you name a variable, you make a conscious choice on what is required of the variable.

There’s a concept I read in a fantasy story by David Eddings, and it goes like

Know the name of an object, and you gain power over the object

Yet some programmers are lousy at naming variables. Some programmers don’t care about the variable names. I bet some programmers even hate naming variables. Why else would there be names such as “a”, “b”, “c”, “DataGrid1”, “DataGrid2” and “Table1”?

Of course, there are perfectly rational decisions on using certain names. Variables in loops are usually single letters, and they are usually “i”, “j” and “k”. That’s probably a 3-level nested `for` loop in the making. I’ve gone up to “l”, “m” and even “n” before (matrix manipulations. Fun).

Based on context, you can easily know what those loop variables are used for. And that’s the important point, the context in which a variable is used. A simple “dt” for manipulating dates and times in a small and well-defined section of code is ok. But if there’s no context, can you tell what the variable is used for?

“It’s compiled into an executable anyway. Besides, there’s the search function,” you say.

Of course, tools such as Lutz Roeder’s Reflector make it easy to obtain code. You can use the search function to find where a variable is used and thus gain an understanding of its purpose. “t1″s and “t2″s don’t bother you at all.

Writing code is in the same spirit as writing a sestina, or writing a letter, or writing a business document. You are writing to be understood. And until artificial intelligence improves, you’re writing to be understood by a human.

The compiler might understand what you wrote (or not, depending on how bad a programmer you are). But you’re really writing for a human being. Someone is going to use that application you wrote, and they’d better know what it does. Someone is going to maintain your code, and they’d better understand what it does.

I can understand the difficulty faced by my Chinese reports (stationed in China), whom I pass some programming tasks. English isn’t their native tongue. The specification documents need to be written in easy, simple language for them to understand the business logic. Before any French or German programmers hammer me with protests, I want to point out the importance of the language used in the communication. Again, it’s about context. If your users use English and your documents are in English, your code had better be easily read in English.

Obfuscated code is hard to read because the context is taken out, be it requirements, indentation, spacing or addition of superfluous stuff. To add and support context around code, you need a certain level of linguistic proficiency (yes, basic spelling and grammar counts).

So my conclusion with bad variable names is that they arise out of a combination of:

• Limited vocabulary range
• Lack of imagination
• Plain laziness

What’s your excuse for bad variable naming?