Fork me on GitHub

There are two ways of constructing a software design

There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.
C. A. R. Hoare

Posted in Quote | Tagged | Leave a comment

Optimizing for the Number of Keystrokes

Can you please tell me what this is supposed to be?

...
++count
...

You know what this screams? “Look at me I am super smart, I know the difference between pre-increment and post-increment! Besides I’m 5 years old!!”

I think that this one little expression summarizes the whole issue with the programming craftsmanship. The problem lies in the underlying hierarchical behavior of programmers, and when I say programmers I’m of course talking about men.

So what the hell is this hierarchical behavior that I’m talking about? So if you are a men then you already know for sure what I am talking about:

  • Your friend tells a story, but you have to tell a better one.
  • Your friend makes a joke, you have to tell a much funnier one.
  • You friend tells something really hard and ugly they had to program, you tell something much more ugly you programmed.
  • …and on and on and on.

Every man know that there is always a competition in conversations. Men always want to impress in some kind of way even when they look ridiculous, not if, when! Of course all women would know what I am talking about. Although women are often much smarter than men they typically don’t feel the need to impress someone with that, that would seem ridiculous to them, they are typically much wiser than men.

You see how far we got with this digression. Men always want to show off. On one hand it’s good because it’s what drives them but on the other hand it leads to unnecessary side effects.

In case of programming you always want to write the clearest code imaginable. The best thinkable presentation I’ve ever seen on software quality was given by Douglas Crockford (which you can find on Youtube).

He perfectly summarizes the issue of programming: “As our progresses become more agile, our code must always be in a state which is editable”, and you can only achieve this by writing clear and literal code without showing off.

The question is for you as a programmer: is it really that complicated or am I trying to make it look complicated? How much stuff am I trying to compress in one line?

Everything that optimizes for the number of key strokes is always negligible because we don’t spend most of our time writing, we spend it reading and changing existing code.

Posted in Experience, Programming, Thoughts | Tagged , | Leave a comment

Everything that doesn’t kill you is good for you!

A recurring issue in my philosophical inquiries is an actual biological or more practical a psychological issue.

The question is: Does anything that I know affect what I am doing or will do? Means: do given facts about the world determine somehow my decisions?

  1. Let’s say we will tell a smoker that smoking will kill him
  2. or someone over weighted that that he will get diabetes or heart attacks likely really soon
  3. or a student that the exam next week is important

The typical response would be instant denial without even thinking carefully about the facts. Do I really need to say more to make the point clear?

So the question is why don’t we react like we should, like saying that smoking is stupid and should be banned from this planet?

So the issue lies in the architecture of the human brain. Because the brain has evolved at a time where danger meant something happening instantly right now which could kill you. Like animals attacking you leading to a flight or fight reaction, which means running away or staying and fighting

Let’s say that there is nothing to fight or somewhere to hide?

We must do what we are, which is probably the stupidest thing we could do which is disregarding facts and continuing what we’ve been doing before.

Because – to quote Douglas Crockford about the brain recognition – everything that doesn’t kill you is good for you!.

So next time think if you fall in this trap check if you have the actual freedom to change what you’ve been doing yet, it’s a self brain test.

More about this issue in: The Science of Fear by Danie Gardner

Posted in Thoughts | Leave a comment

We don’t care about your experience just get that degee

Today again was one of those sad days where I recognized the bad influence of industry on the academic landscape.

There is one guy studying with us who seems to be out of place. Even for my relatively high age he seems to be substantially older, like in the mid 40s.

I sometimes speak to that guy but I didn’t really know what he is doing and why the heck he is studying at his age.

I told him that I wanted to start my bachelor thesis soon but I’m not sure about the topic and that I’m still looking for something interesting. He told me that he also wants to write his thesis at the same time so I asked him what his topic is.

I won’t tell what the topic is but it’s related to data structures and he told that it has something to do with his earlier job and that it would be a good match to that because he wants to return to that job.

I found that topic also exiting because it’s theoretical and practical at the same time. I started a conversation and noted that I read two sources from open source projects which do something similar and that I am reading a guy’s blog since a few years which develops this kind of software. I asked him where he wants to put the emphasis in his thesis because many ideas came into my mind going roughly through his topic.

He on the other hand didn’t seem to be as exited as me. He didn’t want to actually go that deep. It seemes that he only wanted to use some enterprise stuff and only make benchmarks and simple data modellung but not really do something algorithmically interesting.

Don’t get me wrong, I probably wouldn’t have chosen that topic because I would expect it to be really hard and that the few months time given to finish a bachelor thesis wouldn’t be enough to do some interesting work in that field.

But he wasn’t even close to be interested in that topic as I was.

However, coming back to the beginning. I wanted to find somehow out why he is still studying at his age so I continued to talk about if he wants to add a master degree after the bachelor degree and I noted that it’s actually pretty pointless unless you want to stay at the university because visiting four additional terms some random lectures won’t make you a better computer scientist except you go for specialization.

He said he wants to get a master degree and he is not really interested in the hard computer science stuff, so he will more focus on his not so technical secondary subject.

I told him that this is really pointless if he wants to return to his technical job and he responded that you don’t need a degree at all if you are working in the programming or technical field at all.

I agreed because people just don’t get that there isn’t a straight line between programming and computer science. But that’s another story.

He said that he could just leave with his bachelor degree but there is a problem. You will only reach a certain point in your career at a company without a master degree, he said. You won’t ever get an manager position.

I thought about it and what kind of strange logic that is. He continued that although he has now 20 years of experience his boss told him that he will only get a job as a manager if he comes back to the company with a master degree.

I was a little stunned at this point. First of all, who the heck wants to be a manager who studie’s computer science. He should have better studied something else in the first place and what kind of strange company is that where your experience doesn’t count. That’s the whole point working at one company for so long, so your experience has a value. Secondly, why does he thinks that he has to work only at that one company as if there are no jobs in Germany in the IT field.

To me it was clear that he is not really a programming geek like me which writes code during his free time, reads book about software development best practices and reads blogs about programming and all that stuff. And he isn’t really a good computer scientist either because he is not a strong mathematician. Why does his boss demands to get a master in computer science at all.

So this all was really weird and it all boiled down for me to these three questions:

  1. Is it unethical to give positions based on degrees rather than on experience?
  2. Was it unethical from his boss to make the offer (even the incentive) to give him a position as a manager if he gets a master degree? At least it takes five years of his life to get there (at his high age, also).
  3. He is clearly not a good programmer or a strong computer scientist. Is it unethical to think that he can command other people how to do their job if he doesn’t know how to do it better? (we talk about IT area)

The short answer to all those is yes.

Posted in Thoughts | Tagged , | Leave a comment

Naive recommendation system approach

Lately I’m reading through AI algorithms and I came across a goody which a lot of developers want to have because everybody uses it all the time and it’s really useful and that is a recommendation system.

Best known through sites like amazon or youtube: You look at A and the website tells you: oh by the way people who looked at A – also looked at B.

So the system relies on data based on the actual behavior of its users. The data comes from the behavior of the users and needs to be aggregated and then evaluated within an endless process.

The algorithms used in this area come from linear algebra and a bunch of stochastics. Typically a set of n-features is represented within an n-dimensional space and to find related entities you compute a clustering of the features or their shortest distance in n-dimensional space.

But let’s don’t go that road yet, because everybody can build a recommendation engine with some very simple ideas.

Let’s don’t care about scalability while doing that because that is a another story because the amount of data and processing time can get really big.

We don’t care about that here. Let’s only focus on some very simple ideas.

We want to build a recommendation system for a shop. We have Users and we have Items.

Each time a user X looks at an item A we want to recommend n items that other users also looked at when they looked at item A because we – of course – want that the users buy more.

1.Step: Track what all users view.

2.Step: Track for each item which users viewed them.

recommend-1

3.Step: Aggregate the users common items with occurrence count.

  1. Look up all n users which looked at the item x.
  2. Look up all items which the users of item x viewed and merge the items into a new data structure while count each items occurrence.
  3. Order the occurrences by descending order.

recommend-2

4.Step: Take the top n results as recommendation.

recommend-3

The good thing about this algorithm is that you can pre-compute the recommendations for item x and you can continuously keep updating them. They don’t have to be perfectly up to date, they only get better if you keep updating them.

But there are a lot of down sides.

  1. Most annoying thing is that you need to remove deleted items from all users x. You can lazily remove them by adding a hash table with delete items and while making a union looking up each item if that item has been marked as deleted and then remove it from the user’s x list.
  2. The computation is simple but needs space and time.

Next time we talk about the space and time complexity and improvements. It depends on its implementation.

Posted in Algorithmns | Tagged , | Leave a comment

Syntax highlighting for kindergarteners

Syntax highlighting makes it easier for kindergarteners to program.
Douglas Crockford

And Crockford has pretty good arguments what he exactly means by that (of course a little joking):

https://plus.google.com/118095276221607585885/posts/XXkzgJEoE9v

The point that he makes is that the current way of syntax highlighting that all IDEs and editors provide don’t add any kind of additional value for the reader of the program except of looking childish and that is exactly right.

He resolves this issue by adding a feature to JSLINT which highlights the scope of the syntax.

Let’s take a look at regular syntax highlighting:

regular-colors

This is how jslint applies highlighting:

jslint-colors

I must say that I am pretty shocked that we haven’t been using this highlighting earlier because for experienced, professional programmers regular syntax highlighting is pretty pointless.

The way that Crockford recommends doing highlighting actually adds real value for the reader.

You can test some code live here.

Posted in Programming | Tagged | Leave a comment

Misleading Interview Question Guides

I saw something really random about programming interview question guides on the web which often completely misses the point of the whole interview question. The problem is that they distract from the essence of the question.

An example:

We have a list of n elements and we have x unknown duplicates within that list: find the duplicate elements.

If a question is so simple as this one then the answer to this is for sure not to come up with a random algorithm but to ask the right questions.

Instead you see average programmers brute forcing tens of different versions to solve this problem in the comments section, on the given website. That is just stupid because every programmer must be able to solve this anyways. That is not the point.

Only the boundaries for this algorithm are interesting which determines the algorithm.

So expect programmers to first ask for boundaries rather than trying to randomly solve this. If a programmer is not suspicious about this question then something is wrong.

Possible boundaries, as always:

  • We have enough CPU time but tiny memory (QuickSort + Binary-Search, or + lineare Search comparing neighbours)
  • We have very little CPU time but huge memory (Counting-Sort)
  • We have in both cases plenty (Counting-Sort)
  • We have both cases very tiny amount available (if n huge probably MergeSort for external devices + blockwise linear neighbour comparison, or b-tree index look up)

That is the actual question: What are the boundaries.

Posted in Thoughts | Tagged , | Leave a comment

Book Review: Maintainable JavaScript

Maintainable JavaScript

I typically read technical books only from people who I trust. And with trust I mean that I have the feeling that what this person says makes sense and is not expressed from a personal point view but the person tries to bring together all faces of the problem and tries to rationally make a decision based completely on arguments with consistent logical structure. In this case I saw a presentation of Nicholas Zakas on Youtube which made a good impression to me.

I think Nicholas Zakas made a pretty good job in this book by bringing together all relevant practices in the professional JavaScript development field. He’s tries to bring together all threads and options and let you decide what’s best for your project. It is focused to be really practical and he’s even going down to the level describing how to write ant build scripts for your JavaScript projects.

Topics are: programming styles, statical code analysis, organizing complete projects, testing, integration with continuous integration with scripts, minification and many more details.

As a more seasoned web programmer I already knew most of it but it was still a good read and gave me new ideas applying best practices in my projects. I wished he would have told more stories from his practical experience which have led to problematic results. Even I have in my relatively young age a lot of stories about stupid behaviours in projects which led to problems.

For web developers I can recommend reading this book especially if you need a compact view of all best practices.

Posted in Allgemein | Tagged , , | Leave a comment

JavaScript Framework Wars Collateral Damage

You can almost calibrate an atom clock hourly by the intervals at which new JavaScript frameworks arrive.

One main reasons is that JavaScript frameworks are easy to write.

The other reason is that web developers are all day long on the web – spamming the web with discussions about what “the” best framework is.

To a certain extend you cannot just close the door and escape from this sphere because you have to constantly educate yourself and keep track of trends.

The downside is that you get constantly hypes to no end by childish web developers who are dancing around their Macs with their Starbucks coffees in their hands.

The web was never constantly hyped that much than in the last years. In the 60s to 70s the big topic was the software crisis. In the 80s object oriented programming was the next big topic which dominated the press. Today we have the web – an endless and constant junk heap of information. Which is dominated by web developers and discussions about JavaScript frameworks and tools. They dominate the complete web due to their overrepresentation – searching always for silver bullets.

I think this is part of a materialistic attitude which only recognizes improvements by expansion. But that’s another story.

Coming back to the topic. The important thing is that you have to trust your own judgement to distinguish between short lived hypes and persistent trends.

But the amount of stuff that get’s into your view makes it more and more difficult to reliably make predictions about the durability of frameworks or any other software or technology.

I just recently experienced it myself. I was writing a project where I programmed the client side code purely in plain JavaScript. After it was getting messy I created in some kind of way my own little framework. After that I wasn’t really happy with that – although it was working pretty fine.

However I tried to rewrite it entirely in Ember.js which was a big mistake. Because the project it relatively new, the api wasn’t really stable and the documentation was for my standards way too shallow and didn’t go really in depth in terms of practicality showing reasonably complex real world examples. Additionally the framework was just too big and somehow intransparent. It pretty much dismissed itself naturally with these factors.

Due to this experience I jumped over to Backbone.js and rewrote the code again. At some point when I was almost done I got pretty angry – while I was using the framework – because the abstractions were just too weak and shallow that it was pretty much pointless to use this framework. It neither had any elegance nor the elaborateness of any good framework. So I wasted another full two days to learn this framework.

At this point I was about to return to my original JavaScript code because it was the most straightforward. Anybody would be able to understand it because it was pretty much what you would expect without the superficial surface that Backbone.js provides distracting you from your actual work.

I used these frameworks because my judgement let me alone. I took the one which were the most hyped frameworks without actually making a proper analysis of the situation. At the other hand I could argue that I only lost probably a week – before I dismissed these framework – whereas others spend month before seeing their mistakes – if the see what they’ve done wrong at all.

After this sobering experience I took a look at a very less hyped – but at this point more mature – framework. I won’t tell you which one because it’s not important. The important thing is that this framework had either a very light abstraction but it had the right abstraction. It just hit it on the spot.

I don’t say that the time I spent on those frameworks was wasted. I think it only will be wasted in the future – if I’m going to make the same mistakes again.

Be always careful with hypes. Especially within the short lived web developer community. Things in this area are exciting because they are very dynamic and evolving fast but it requires a huge amount of experience to judge what is important and what’s not.

Posted in Experience, Programming, Thoughts | Tagged , | 1 Comment

Code Smell: Commenting to the Death

Comments are an art form. Sometimes too much.

// Specifiying length
var length = persons.length;
// Initilizing sum variable
var sum = 0;

Thanks for telling me.

function doIt() {
    // Comment Comment Comment Comment Comment Comment Comment Comment
    // Comment Comment Comment Comment Comment Comment Comment Comment
    // Comment Comment Comment Comment Comment Comment Comment Comment
    // Comment Comment Comment Comment Comment Comment Comment Comment
    // Comment Comment Comment Comment Comment Comment Comment Comment
    ...code

    // Comment Comment Comment Comment Comment Comment Comment Comment
    // Comment Comment Comment Comment Comment Comment Comment Comment
    // Comment Comment Comment Comment Comment Comment Comment Comment
    // Comment Comment Comment Comment Comment Comment Comment Comment
    // Comment Comment Comment Comment Comment Comment Comment Comment
    ...code

    // Comment Comment Comment Comment Comment Comment Comment Comment
    // Comment Comment Comment Comment Comment Comment Comment Comment
    // Comment Comment Comment Comment Comment Comment Comment Comment
    // Comment Comment Comment Comment Comment Comment Comment Comment
    // Comment Comment Comment Comment Comment Comment Comment Comment
    ...code
}

Methods are free. Some don’t know. Maybe.
Objects are free either. Some don’t know. Also maybe.

Posted in Programming | Tagged , , | Leave a comment