Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: What language do you think in?
22 points by endlessvoid94 on Sept 3, 2009 | hide | past | favorite | 64 comments
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.



I think in English. Whenever I'm thinking about a problem, my solutions are immediately described in my head at a high level. This allows me to rapidly iterate over the solution space without having to venture down into the pseudocode or code level until I've found something I'm convinced will actually work.


I'm trilingual, but I tend to also think primarily in English (not my native language).

Apart from that I prefer to think in images.


I think in English about programming stuff too. I think in either Italian or English depending on the context, but mostly English as that's my native language. Italian is more for things or events that happened in Italy or with Italian speakers (so... actually I do think in it a fair bit, because I live in Italy).

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.


I think in English, but it looks and sounds similar enough to Python anyway. I find this awfully handy.


My native language is spanish but I think in german (my partner is from Switzerland) so I read and speak (not always) in german.

In programming languages I think in Python and then translate according to my needs.


I think in the subdialect of English known as social media stream of consciousness.

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>


It depends on the situation, but I generally think in terms of pure (recursive) functions and types. This then usually provides me with a reasonably quick mapping to my preferred languages (e.g. ML or Haskell), as well as providing a reasonably simple way of mapping back to languages like Java or C or PHP or whatever else I might be called upon to write occasionally.

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.


"It depends on the situation, but I generally think in terms of pure functions and types. "

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.


Well, I think it's reasonably intuitive to think that way. It basically involves asking yourself the questions - "what types of values am I interested in?" "what types of results do I expect?" and finally "how do I get from input to output?"

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).


having worked in... a high-level functional language gives you some mental machinery that doesn't rely on decomposing this thought process into some concrete syntax

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!


I kinda skipped SICP (I had already been programming for a long time before it even occurred to me that there might be texts available that attempted to teach "computational thinking" rather than just individual languages), but having browsed it since, I always recommend it to anyone who wants to learn programming (or HtDP, which also seems to cover similar ground).


Am I the only one who doesn't think in any language at all? I just see little flashes and sort of feel ideas. I realize this is a very sucky explanation, but I've never heard it described. When I think about a program it is again a combination of images and feeling how a given algorithm I am designing will work. I only ever think about words when I sit down to write words, and then it is almost like I am transcribing for a voice in my head that feeds me one word at a time. I very often can't think of a name or the correct word for something, but can describe around it (like I might forget the word 'well' but I can just say in frustration "hole you drill to get water out of").


In a programming or problem-solving context, this is sounds close to how I work in the very early phases of thinking about a problem.


When you are thinking out a problem is language (human or computer) any part of it?

If I understand how most people think (which I most likely don't), they have an internal monologue going, like they are thinking about going to the store and they think in their inner voice, "lets see, what do I need? Some eggs, milk, cheese". I never have any monologue internally, I either see a little picture flash by, or more often my thoughts have no relation to anything I could describe as sensory at all.

For example, I just thought of what I wanted to get to drink because I was really thirsty from gardening. No words were thought, but in quick sucession I percieved in my thoughts the flavor and temperature of tap water, and then the cold sweet syrupyness of coca cola, and I grabbed the coke. I can't describe it really, it's very much a 'now you are breathing manually' thing, once you think about how you think you are changing how you think.


No, in the early stages there is no language attached to my thought processes, though as I mentally interact with the abstract concepts, I generally start to concretise into recursive functions. This conception of 'recursive functions' still has no notation attached to it, it's more that I start to decompose my solution (mentally) into cause and effect.


I think in pseudo-code, then figure out what language is best suited for the task.


When you say "I think in pseudo-code", what are the semantics of this pseudo-code?

'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).


It's perfectly possible to express solutions at a high level without much regard for formal semantics. Knuth's The Art of Computer Programming expresses most of its algorithms in a combination of informal English and ad-hoc pseudocode. It's usually not difficult to translate them into languages with semantics varying from machine code to Haskell.


I didn't say "formal semantics", I said "fixed semantics", as in "something you understand and can apply consistently within a context". Within the context of a single code-fragment, the semantics are not changing. They might change from example to example, but that's perfectly reasonable.

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


For example, if someone asked me to do the fizzbuzz test (http://www.codinghorror.com/blog/archives/000781.html), I might think to myself in pseudocode:

  Loop from 1-100:
    if the current number is a multiple of 3, print "fizz"
    if the current number is a multiple of 5, print "buzz"
    otherwise, print the number
    print newline
Then I might turn that into PHP:

  <?php
    for($i=1;$i<=100;$i++) {
      if($i % 3 == 0) {echo("Fizz");}
      if($i % 5 == 0) {echo("Buzz");}
      if($i % 3 != 0 && $i % 5 != 0) {echo($i);}
      echo("<br />");
    }
  ?>


I take a slightly more abstract approach: I first think of the problem from the user's perspective (and their expectations), then I map out a work flow before diving into pseudo-code and wire-frames.

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.


I still don't think it adequately answers the question. Maybe the question should be rephrased as "What programming paradigm do you think in?"


Yes, perhaps the original question is too open-ended, but without a proper context, all answers will be leaning towards the abstract.

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.


Cypher: ...I...I don't even see the code. All I see is blonde, brunette, red-head. Hey, you uh... want a drink?

-The Matrix 1999


Depends what I'm looking at.

If I'm looking at a website, I think in SQL (cf. dude I can write SO in like 4 minutes ;)

If I'm looking at stats/ML stuff, I try to think in pictures (usually of probability densities being transformed in various ways), and sometimes slip into "pseudomath," which is basically English that sounds like "argmax integral x filtered by f times hessian of g".

If I'm doing information theory I tend to think geometrically or graphically, seeing distributions as points/nodes and then reasoning about what the picture looks like as distances/edges between them grow and shrink.

If I'm looking at an attractive member of the opposite sex, a good bottle of wine, or someone that needs cursing at, I think in French.


I think in whatever language I'm writing unless I've just started it. Then I think about what I'd imagine they'd call it and google around for it.

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++.


It depends on the problem. If it's something algorithmic that fits into a given data structure, I go through a bunch of mental visual representations; graphs, trees, etc. If the model fits, I usually imagine the code in the language I used the structure the most in.

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.


I focus on the semantics first: I try to capture the essence of what I really mean to "say". Then I try to imagine the most idealized language that would let me specify as exactly and easily as possible what I really mean, unambiguously.

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.


I've been coding long enough that most problems don't need thinking about. I just 'know'.

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 :(


First I think visually about object classes and data structures, and how they relate to one another. Then I think in pseudo-code.


This is so funny, because ever since I was first introduced to OOP (about 19 years ago - C++), I've had visuals in my head for objects - not clear ones, but somewhere floating in there is the idea of some shape with sockets and protrusions, switches and dials, representing getters, setters, methods, etc. Again, it's always vague, but the concept always seems to be there. I can tell you, though, that they are an off-white color.


I think is algorithm, state-diagrams and images;and curse in Hindi :)


I tend to think in terms of abstract flowchart of the process/algorithm/structure of what needs to happen.

And then I make it happen.


Interesting. I'm surprised to hear people can effectively think about code in a language at all. Code is an abstraction of an essentially physical process (the computer doing things) so it seems rather odd to think about the problem at one level removed. I don't think in language generally unless I am intending to speak to someone. I tend to think in terms of motion through a physical space. Imagine yourself playing tennis and feeling your motion across the court. The algorithms in my head work the same way. All the pieces are sort of thrown on a table and I feel the paths between them, the 'forces' of contention and flow. The closest I've seen to describing it is when really advanced chess players talk about how they see the chess board as lines of force and weight.


Aha, someone else. I would describe it as sortof pressure and stuff in there, like I'm feeling my way through a dark room and 'seeing' as I work the problem around in my head. All these people who say 'english' or something like that, how do you live? I would go insane after a day of that, it would be so slow and imprecise and completely misleading.

Here is another thing, tell me if this is true of you: I can't understand anything about how to solve a problem if I don't know completely 'understand' the context. In other words, I took several years of experimental physics at University, but it was totally bewildering to me. I understood the experiments perfectly (I mean, they aren't anything complex at that level), I understood the apparatus, I understood the mathematics and so on and on. At some point in every experiment, however, you had to decide whether your data supported or did not support the hypothesis. This is usually pretty obvious, but you were supposed to support it using chi-squared calculations and other statistical measurements of how well the data fits the hypothesis. I hadn't taken any statistics courses, so it seemed totally opaque and impossible to me to do this. I could never figure out what equation to use, or how to do it. I could follow step by step in the workbook and if I did so I would get a fine grade, but I was literally looking at the equations every 3 seconds as I worked the problem out. Anyway, I looked up the stuff in a statistics text, read the proofs and explanations of all the things I needed to understand, and suddenly it all made sense at once and I never had to refer back to anything. Once it 'clicks' everything is clear, like someone turned the light on in a dark room, before it 'clicks' I feel like I am suffocating.


I do feel something similar in that I can't really apply a bunch of rules to something. One of the disadvantages of not thinking in language is that I think it is very difficult to just apply a rule or formula to your thought process when you don't fundamentally understand what the formula is doing at a deeper level. If your models are not being stored in your head as language abstractions, you can't really apply a language abstracted formula to it. Another related problem is that I essentially have no memory for the things other people memorize with ease. I memorize concepts, motions and relationships but I cannot memorize 'labels' at all. I do not know my own phone number for example (2 years with my current one). So yes, I think trivial understanding is difficult with this model because you cannot just catalog a bunch of stock responses and rules for dealing with a certain topic, but deep understanding is far easier because you are not abstracting the underlying principals in a layer of obfuscation, the mental model is a simulation of the system rather than a description. I was useless in calculus until I started visualizing everything in terms of momentum and volume changing over time. Then it started to work. When it was memorize and record, I was useless. But once you have an actual model in your mind instead of a bunch of rules you can just derive the algorithms yourself (or at least get close enough to remember the right one)


As far as I can tell we have the same thing going on in our heads.

Anecdote: In physics class (I was a physics major for awhile, so it was a 'real' physics class) there was what I guess was a very complex problem. The professor posed the problem and asked 'how do we solve this', and I raised my hand and told him the integral. It took me about 10 seconds or so f talking to say the entire equation. It blew everyone's mind, but it was really obvious if you could see it. I don't mean to brag, but if I was trying to think it through like socrates in a dialog I would have taken a week.


I tend to think in terms of workflow.

  1. How would user interaction occur?
  2. What systems are necessary?
  3. How can the problem(s) involved be solved? (what languages/tools/infrastructure)
  4. Pseudo-code
  5. Get crackin' on code
It's a pretty high level list, so I am probably missing some key points.

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.


I used to think in terms of methods and data structures, say about 5 years ago. I was thinking bottom up. I learned (slowly) that I could not sufficiently communicate to the business folks what was happening. Their eyes would just glaze over. They also rejected 90% of my work by the time they got to see it. We were simply out of phase with our communication.

Today I have learned to think in work flows and the visualizations of the UI. This is how the users of the program view it. To users the UI is the program. Now the users accept my work 90% of the time. I seldom think about the methods or data structures anymore until I am actually sitting there typing it in.


I want to have many different ways to think about problems, all linked up with ways to slide between them. (That's a big theme in SICP, the Feynman lectures, Doug Hofstadter, and Minsky's _Society of Mind_.) The languages that come up the most when I think programming thoughts: Haskell/ML (types, pattern matching), Scheme (procedural code, and my main larval-period language), E (OO: roles and responsibilities, message passing, contracts; event-loop concurrency & distribution; promises; capabilities), Python (actually coding most things), C (closer to the metal). Sketches on paper tend to use a Haskelly syntax with a Schemey meaning.


Probably pseudo-code which resembles whichever language I most recently used to solve a similar problem.

As a really low-level example, previously when I needed to make a comma separated list of items I would do something like this:

$result = ""; $sep = ""; for ($items as $key => $val) { $result .= $sep." ".$val; $sep = ", "; }

of course now I just do join (", ", $items);. all languages I currently use have such a join function or method, and that idea is in my head; the exact syntax is not.

This does result in minor annoyances when I for example solved something in my head with a coroutine, only to realize that I'm at work coding in php, which doesn't have them.


Scheme, though I end up having to translate it to Python 9 times out of 10.


I think in messy pictures. Strangely, the pictures are as poorly drawn in my sloppy style as they are on the page. For example, a loop is an ugly circle with a downward facing arrow on the right side and it looks just like something I would have drawn. Object stuff tends to look UML-like and functional stuff tends to look flowchart-like. And they are messy whether in my head or on the paper. When I need words, they usually look like/start to follow the conventions of the language I'm planning to write the code in.


on thinking in code: after doing a rather intense data integration/normalization/clean up project for many hours ending around 5 am or so, i had to take a shower before catching a nap. upon turning on the shower, my tired mind took a minute to organize/process the physical actions required to put myself into the shower - suddenly it wasn't a shower at all, rather, it was an array of droplets i had to somehow JOIN but the query was already running! all of this data was going down the drain - corrupted with no audit trails - but what regex/match would help? there was none... luckily, i snapped out of it and regained the proper level of abstraction conducive to good hygiene. apparently, i only had to step under the water. rest would work itself out with little need for analytic involvement.

after that, with sleep & time to breathe i went back and checked my work from that night because i assumed that a mind so frazzled would be similarly error prone. alas, that mode of thought, while not suited for normal-person-tasks worked well for the project. no bugs (from that night at least) and that single all nighter put the whole thing way ahead of schedule.


Huh. I'm surprised by the responses on this.

I think in "flow". It's hard to describe, but it's not entirely visual -- it isn't like a flow chart in my head. Instead I get an idea of what I want a particular thing to do, and then I "feel" how it gets there, kind of like I'm mentally bouncing through a pinball machine.

I use the same approach for working on engines, circuits, and other complex things.


My pseudo-code looks a lot like a mix of Python and Ruby. One thing I like about Python is the forced indentation, which allows skipping any closing braces or "end"s. But Ruby tends to be closer to the way I think of OOP, and is closer to English.

I've also been known to write out in mostly English sentences as comments, then fill in the code that implements that explanation.


I think in data-structures opposed to one language in particular, if anything I think in markup; everything starts as a list, each item evolves into another list until it eventually ends up as dictionary, which can sometimes spawn another list. . .my thought-process is hopelessly recursive, this is easily my cardinal sin for all my unproductive days.


I would say I think in pseudo-code, using natural language to describe the problem in a way that can be converted to code ("for all of these values in this array/container...", etc). That said, I work a lot in C#, so I usually go right to that pretty quickly, if not right away for commonly-solved problems.


If the problem requires science, I think in English because most of my relevant university education and R&D was/is in English and thus most of the terminology I know. If it's business-related, I think most the time in German. I draw causal diagrams and sketch in Haskellesque pseudo code.


It usually depends on what language I'm working in. These days I've been working in actionscript, so that's how I think. I think this behavior is partly because I sorta loose familiarity with other languages when I'm working in one language for an extended period of time.


Op and I should be best friends. I can't count how many times I've solved a PHP problem using Python. Or generated PHP code using Python (won't go into detail, but it wasn't TDWTF material, I promise). Or simply explained something in a given language in terms of Python.


I used to think in pseudocode, but once I learned Ruby, it turns out I had been thinking in Ruby all along. Ruby just matches up really well with the way my brain already solved programming problems, then I had to translate it to C or Java or whatever else.


I tend to do it visually.


I think in C.

Python 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.


I usually think in math or visually about a programming problem. When thinking about a person I usually think in the language that person speaks.


i think in diagrams.



Depending on the problem domain: either C, mentally compiling into pseudo-ASM, or a sort of blend of Haskell and math notation.


How about thinking in general, say when waiting to fall asleep?


i think in terms of paradigms(mostly FP) in general, and not in a specific languages.


Norwegian


i try not to think.


Often I let my brain work out the problem, and simply wait until it's finished.

For example, last night I awoke about 5 times, every single time with a new solution to a current problem.

But before that, I always try to really relax in the evening, for some hour, preferably in nature (and nothing beats the sea).


I think in the language i'm currently working on




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: