News for hackers. Stuff that matters.
Re:Ask HN: What language do you think in? by byoung2 on Thursday September 03, 2009 @10:18AM (#802503)
I think in pseudo-code, then figure out what language is best suited for the task.
Re:Ask HN: What language do you think in? by gdp on Thursday September 03, 2009 @11:15AM (#802635)
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).

Re:Ask HN: What language do you think in? by mbrubeck on Thursday September 03, 2009 @12:07PM (#802747)
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.
Re:Ask HN: What language do you think in? by gdp on Thursday September 03, 2009 @12:23PM (#802798)
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

Re:Ask HN: What language do you think in? by byoung2 on Thursday September 03, 2009 @12:25PM (#802803)
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 />");
    }
  ?>
Re:Ask HN: What language do you think in? by fake_pg on Thursday September 03, 2009 @11:20AM (#802649)
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.

Re:Ask HN: What language do you think in? by doki_pen on Thursday September 03, 2009 @11:29AM (#802660)
I still don't think it adequately answers the question. Maybe the question should be rephrased as "What programming paradigm do you think in?"
Re:Ask HN: What language do you think in? by fake_pg on Thursday September 03, 2009 @12:35PM (#802830)
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.