Ask HN: What language do you think in?
Whenever I'm thinking about a problem, my solutions are immediately prototyped in my head in python.
I'm curious to see if anyone has an interesting languages that are not really popular that they attack problems with first.
67 comments
[ 8.5 ms ] story [ 668 ms ] threadPython is a fairly straight-forward mental translation and functional languages I tend to need to spend more energy thinking about unless the problem is embarrassingly recursive.
Interestingly, I've spent a some extended blocks of time working inside theorem provers. I find that it requires me a bit of time to switch to and from that style of thinking.
This resonates. I think in a weird pseudocode myself and after getting a grip on type theory I find I think in typed weird pseudocode.
I think most programmers probably think it reasonably similar terms - it's just that having working in STLC or a high-level functional language gives you some mental machinery that doesn't rely on decomposing this thought process into some concrete syntax from a programming language.
(incidentally, this is one of the reasons why I think there is a lot of value in learning the Lambda calculus early in a computer science education).
This is what we are really talking about when we claim that reading, e.g., SICP will make you a better programmer even if you don't work in Lisp.
SICP is not a book about Scheme. It's a book about computation that happens to use Scheme. And it is resolutely abstract, encouraging you to think in non-linguistic terms. One of the bits I remember best was near the beginning, when they talk about the shapes of computational processes -- iterative processes have a different shape from recursive processes. Now I use that sort of mental picture all the time.
The goal is to think about software like a mathematician thinks about math. If you're thinking in a language, it's like the way I thought about math when I was nine years old -- to the extent that I knew what a mathematician was, I thought it was someone who was really really good at the long division algorithm. Someone who could subtract really fast!
'cause it's actually a bit of a non-answer, when you think about it. Saying 'pseudo code' means that the language you think in has some informality in its syntax - but presumably you still have some fixed understanding of what it does?
If it has no fixed syntax and no fixed semantics, then is it actually helpful as a mental model? I would argue that it is not.
(Note: I'm not just being antagonistic here, I'm genuinely curious. I don't think in terms of "syntax", so this is all a bit alien to me).
My assertion is that when people say "I think in pseudo-code", they actually mean "an idealised version of language X", where language X is some paradigm or language they understand well.
I just wrote a blog post about this very subject, based on the flood of comments (shameless self-promotion follows):
http://news.ycombinator.org/item?id=802780
Overall, I agree with the parent because before you can dive into coding, you have to think of the problem and solution abstractly.
But which language is used for writing out the solution? Whichever is the best tool for that particular problem.
While I may express the solution in Objective-C, PHP or Python, I always think of the solution in terms of logic.
Also, if you have experience in multiple languages (and environments), then you're less likely to be constrained by a single mindset.
Apart from that I prefer to think in images.
This can make it weird working on programming stuff with Italians, as English really is where my brain wants to be for programming. It's not about knowing the terminology (I do), it's just that English is really what I want to use to reason about programming.
Incidentally, trying to think in another language about what's going on is a great way of practicing it if you're learning it.
In programming languages I think in Python and then translate according to my needs.
-The Matrix 1999
Ask Lazyweb about my blog's new design... that's like using the crowd as a source of wisdom... crowdsourcing... OMG I invented a new word wait check urbandictionary... oh cool I'm getting answers... upvote... hmm this submission is tangentially related to my blog, i'll promote it in the comments... upvote... hmm should I change my profile from 'social media expert' to 'social media genius'? Too forward? Oooh one of my older tweets is getting retweeted... Follower count... damn, just got rickrolled again! Hmm the world is moving to Twitter... it's a killer of something... subscriptions... RSS... hmm there's a photo of me that isn't tagged, let's come up with a clever nickname for myself in that tag... RSS Killer... means RSS is dead... Email alert... new follower! w00t fellow social media expert... I'll follow her too... doesn't seem as smart as me though... oh shit, it's Follow Friday! who's mentioned me? who's mentioned me? hmm I need a "10 Things" post to submit to Digg... 10 Things I like about you... funny movie, who was that actress? check imdb... is it in my Netflix queue? Oooh shiny funny new failblog post... I wonder what's new in the app store...
</satire>
If it's about something I don't know much, I'll go through pseudo-code and/or a list of tasks the code has to perform and then imagine it in the best-suited language for it.
If it's more about organizing concerns or how should a larger problem be split up, I'll take a sheet of paper and draw components and tasks, then linking them with arrows until it makes sense and it's clean. I then try to fit that in the language best suited for it; usually for that kind of splitting, actor-based languages do the best job. It's probably why I like Erlang/OTP so much; they provided actual design patterns for higher-level representations such as Client-Server relationships, Finite State Machines, Event handlers (such as loggers and whatnot) that make it really easy to turn a visual representation into an actual application with minimal boilerplate code.
And then I make it happen.
I tend to spend a fair amount of time just thinking and pondering the problem; once I reached some indeterminate threshold, I start typing up point-form notes. As I think more to gain more definition of the problem and potential solutions I add new, revise existing and remove obsolete notes.
And to actually answer the question "Which language do I think in?", it depends on my answers to #3.
However, I've been alive long enough that if I don't 'know' the solution I need a whiteboard. I can't think without a whiteboard.
Age brings wisdom and experience but it certainly has dulled my brain quite a bit :(
If I have access to such a language, I use it. If I don't, but know how to implement it, I might do just that if I think it's worth it in terms of time and effort. Otherwise, I try to think of the next best language that could represent what I mean and that I can use or implement more easily. At some point I get to "really low-level" abstractions like Common Lisp objects, closures and macros...
It's a surprisingly high-quality and slow way to program. I figure at some point I'll have accreted so much language implementation knowledge and infrastructure that I'll be unstoppable because I'll almost always be able to make a good approximation of the best tool for the job quickly.
Translation from one language to another is just another layer of indirection and makes you slower. It's easiest and best just to learn languages from scratch or near-scratch, IMHO. If you get used to learning in that way, it's easy to keep doing it.
Caveat: I think in C when I'm coding C++.