

Ask HN: best programming language for a programming book? - Tichy

I wonder which programming language to use for a book about (web) programming. The book is not supposed to be about a specific framework, but about ways to solve common problems. So the programming language should not get in the way of the concepts.<p>Example: "Programming Collective Intelligence" uses examples in Python to explain the data mining algorithm it presents.<p>I am almost tempted to pick JavaScript, as this is the common language every web developer should know anyway.<p>I would like to use Ruby+Rails, but I fear it might be too complicated to explain. I want to spend as little time as possible on framework specifics.<p>I was really impressed by the brevity of the Python examples in the Collective Intelligence book. Unfortunately I don't know Python yet.<p>The publisher who might be interested in publishing the book pointed to PHP as still being among the most popular languages for such tasks (along with Java), but I would like to avoid that.
======
TallGuyShort
>> I am almost tempted to pick JavaScript

I can't phrase that any better - I have this feeling that using JavaScript for
such a project would be evil, but when I stop and think about it - I think
JavaScript might have become the "duct tape" of the internet (yes - I know
perl already claims to be soo).

I integrate JavaScript with my Flex applications all the time. It gives you a
good understanding of HTML, basic programming, and as AJAX becomes more
popular, JavaScript becomes more important.

PHP is another good option. It does have some problems, yes, but it's common,
free, and easy.

------
spooneybarger
Do you wanted the largest target audience?

Pick a 'scripting language'? Then eliminate based on issues...

I would come down to python or ruby being the easiest for most people to look
at and quickly gronk. python being the easiest i would suspect. and i say this
as someone who does 0 programming in python these days.

You don't know python however, so ruby would be fine. If you start doing stuff
with blocks etc, you might want to explain that as some people would find.

File.open( "a_file", "r" ) { | line | puts "this is a line #{line}" }

a little confusing.

of course all this assumes you target audience is imperative, algol steeped
programmers.

~~~
russell
You can "learn" Python in a day or two. Of course, becoming proficient takes
longer, but it has the shallowest learning curve of any language that I have
used. A big plus, it like JavaScript/JSON has literals for arrays and hash
table, allowing easy configuration and data transmission.

------
mbrubeck
Since you know Ruby, you might consider writing examples in Sinatra. Compared
to e.g. Rails or Merb, it's less of a framework and more of a simple DSL for
building web sites/services. It really gets out of the way and keeps the focus
on the content and logic. But the newbie web developer who learns Sinatra will
have a lot that's still useful if they move on to a full-stack framework like
Rails or Django (for example, templating and database models are basically the
same).

~~~
Tichy
Good idea, I had totally forgotten about Sinatra.

------
roshambo
JavaScript, for several reasons:

1) Dynamic typing. The user doesn't have to worry about data types and memory
usage and what-not.

2) Common syntax. It uses somewhat of a C-style syntax (with its conditionals,
curly braces, and so forth) and therefore shares characteristics with many,
many other languages (PHP, Java, Perl, etc.) and will help the reader
translate your teachings to other languages.

3) Ubiquity. As you mention, most of us have or will encounter JavaScript.

4) Ease of use. Everyone has a JavaScript interpreter (via their browsers). To
test code no software installation is necessary.

Many coding-enthusiasts will say Python. While it's a very, very well-designed
language, I recommend avoiding it because it's syntax is so different than
other languages.

------
davidw
Javascript might be a little bit confusing for the casual book-picker-upper:
"wait, is this bit on the server or in the client?"

~~~
Tichy
Maybe, but if that is the only issue, it might be easy to resolve.

I am more worried about talking to a database or generating server side HTML.
Javascript web frameworks exist, but I don't really know them yet (ie Helma).
In theory I would like to be able to do everything in Javascript - why learn
two languages if one could suffice? But I might be too ahead of the time for a
book targeted at the average web developer.

~~~
davidw
Maybe this sort of approach would be better:

Show people a wire dump of what's actually going over the socket, and how
different languages/frameworks create abstractions to handle things like "CGI
variables", "sessions", cookies, and so on and so forth.

~~~
Tichy
Not sure if I could make that work. I envision to make the book as hands
on/getting things done as possible.

