Skip to content

Comment on You Don't Want to Think Like a Programmer

Comments

I think the article stretches too far away the "think like a programmer" motto by including design patterns and TDD in there. You will have trouble learning if you do not think like a programmer, as in basic CS 101.

Thinking like a programmer is really near to mathematical thinking, just the basic stuff: logic, invariants and program correctness, in paper, and using pseudo-code. After a year one will be ready to throw that stuff through the window, not because it is not useful, but because it is already engraved on your brain and somehow, even if you do not use assertions at the start of your functions or do not write an invariant down for each loop, it will be there and will make your code cleaner and free of copy-pasted code.

I guess you like math much, am i correct? Programming is in some wayslike math. Programming is in other ways more about organisation, expression and language skills.

But the real truth is that people are different. Some people are mechanics in the head, they like to optimize small functions and break systems and loved the assembly c time. Some people see the world as states and attribute facts to static objects, these people love OO, its an entire paradigm that complies to their though process! Some people are rigours about how the world moves, they like Haskell and logic programming and always bring these aspects to their code base.

Some people are dynamic and see the world as a continuous flow of time (not pinning attributes to things, seance a thing can change along its time line, thus brining focus on the core of things and ones purpose), they like languages like lisp where transformations of data is the center, not classes with fixed static attributes, that is contrary to their irl thought processes. These are the people who develops non-deterministic programming, because the focus is on time not space. They like macros and other efficient expressive tools because it allows you to express your solution in a better language and automate transformations.

tl;dr / Summary People think differently and programming is merely a means to express yourself, ergo your view of programming will be a view of how you like to think and function, and to say that your own definition is the universal truth is arrogant, narrow-minded and wrong.

http://wikisocion.org/en/index.php?title=Statics_and_dynamic...

Maybe I am wrong, and I am confusing programming with programming for maths. Now again, on the low level, it's really easy to find maths everywhere, while on the high level, one just interacts with development libraries.

As a note, maths are not a field I am really strong on, and had a hard time with them at the university. But, even when it was hard, it helped wrap my brain around programming and provided me with elemental tools. Yes, programming might be drawing pixels in a grid, or could be just throwing words at the computer until the output is what you want.

I do not consider myself a proficient programmer and yet, I pity the programmers that look confused at a chunk of code in Eclipse and just add whatever a set of libraries provide to get something to work, which often ends up with larger chunks of code that basically do nothing, but are there just because (with an special guest, more chunks of commented code that are waiting for someone to delete them). I experienced this feeling the first time I programmed something for Android. And no, in this case there's no 'some people might have a different view on the issue'. There's people who code that have no clue of what is happening, and that is saddening (and I guess, stressful to them).

As an exercise on what I am referring with basic tools let's see the simplest example I can think of: define a function that returns the factorial of a number. We know the answer already, but instead of doing that, let's think first, and generate the code later [∗]

What defines a factorial?

    n! = 1 * 2 * 3 * ... * n-1 * n
Any particular case?
    0! = 1
Let's pick an strategy for our loop:
    - At each iteration, we will mantain that f = i!

    - For all iterations, i ≤ n
The program finishes when i = n

Ok, now code

    // Pre: n ≤ 0
    // Post: returns n!
    int factorial(int n):
        int i = 0
        int f = 1
        // inv: f = i! and 0 ≤ i ≤ n
        while(i < n):
            i = i + 1
            f = f * i
        return f
[∗] = And that's for me the main reason this works. This is a silly example, nobody would think of invariants when you are iterating through a set of records from a database to calculate the median age of your employees, but at least it has trained you to think before cracking code. And this is just the first step on the path.

It is not "the universal truth of programming", and there are many many different "states of mind" that one will need to learn in order to do something (OpenGL and state machines, SQL and declarative languages, etc). But before learning something (unless you are really talented, I guess), one must learn to learn.

I am having a hard time how one could have gotten that impression if one has worked in ecommerce or business software, i promise you that mayor ecommerce site is just not interacting with development libraries.

I really can't see the point of your third paragraph, what are you arguing for? That the people who threw code was people who didn't share your view on programming? Or is the paragraf to be interpreted that anyone who try to use leverage in code is a fool? And also how are inexperienced untrained programmers skill really relevant to different views on programming?

Let me give an exercise in return. Add to the code base a module that allows the skin of the site to be changed depending on the users device in a way that it is easy to add skins and also capability to random give users different skins. How much math do you really need beyond Math.rand(0,100)?

This instead is task that is solved by being able to formulate an expression that is general enough and can communicate with the existing system and fit the existing organization without breaking the big structure. No computations is really taking place ( in the seance we want to get some mathematical result from different values ) it's only flag checking at the bottom line.

You learn to learn when you grow up. The things you mention are different ways to look at problem and thus different ways to express solutions.

I do not think our views on the issue contradict at all.

Maths may not relate on how you structure code, but (as I see it) an early start with a little dose of maths on understanding algorithms, may make your brain understand the elementary stuff easily, and make you think like a programmer. Are there any other introductory ways to get there? Sure, why not.

My third paragraph was referring to what I have seen on the people that do not think as programmers. Not as a matter on how they got there, but as how they never got there.

>Thinking like a programmer is really near to mathematical thinking

Some people say that but I've never understood it myself. To me, programming is nothing like mathematical thinking, especially at an intro level. It's more about giving super precise instructions to a stupid machine that has to be told every little thing. There are lots and lots of successful, competent programmer who don't know much math or logic as academic fields.

Edit; maybe a more relevant discussion would be talk about what is meant by 'mathematical thinking'.

I would argue that giving many super precise instructions is exactly an example of mathematical thinking. It's like the old algebra problem of "Prove 23=6". It's blatantly obvious to everyone over the age of two, but the proof is quite long and tedious.

    2*3=(1+1)*3  |  Definition of 2
    2*3=1*3+1*3  |  Distributive property
    2*3=3+1*3  |  Identity of Multiplication
    2*3=3+3  |  Identity of Multiplication
    2*3=3+(2+1)  |  Definition of 3
    2*3=3+(1+2)  |  Commutativity of Addition
    2*3=3+1+2  |  Associativity of Addition
    2*3=(3+1)+2  |  Associativity of Addition
    2*3=4+2  |  Associativity of Addition
    2*3=4+(1+1)  |  Definition of 2
    2*3=4+1+1  |  Associativity of Addition
    2*3=(4+1)+1  |  Associativity of Addition
    2*3=5+1  |  Definition of 5
    2*3=6  |  Definition of 6
It's the exact same set of logical skills to take a fixed set of tools and see how those tools can take you from where you are to where you want to be. It's not that programmers need Category Theory and Partial Differential Equations (however fun and useful they can be), but rather that someone who can't prove that 23=6 probably can't code.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.