

Ask HN: JavaScript as a first language? - Kraxon

Little background, been working in startups for the last couple of years, mainly in marketing and sales. Recently started my own Magento ecommerce store that&#x27;s essentially sustaining me passively so i&#x27;m looking at spending some time learning to code.<p>Question is, is there any reason not to pick javascript as a first language? Been hearing alot about Node.js and Meteor, any downsides to picking it over something like ruby?<p>Would be great to hear your thoughts.
======
modzilla
Not JavaScript – Prototypal inheritance is interesting and powerful. However,
overall JavaScript does not afford good programming practices and does not
cleanly expose important re-usable programming concepts. Between the good
parts of JavaScript, there are nasty surprises.

I think python is a good first language for a few reasons.

1\. Overall the syntax is clean, concise, and readable in the sense that the
actual code can be close to "sudo" code, or that it is somewhat similar to
what what you might encounter in a mathematics class.

2\. From Wikipedia:

"Python supports multiple programming paradigms, including object-oriented,
imperative and functional programming or procedural styles. It features a
dynamic type system and automatic memory management and has a large and
comprehensive standard library."

All of those programming paradigms are important to understand and few
languages capture all of them as nicely as python. Also, static typing and
memory management are important to understand – yet, mostly distracting while
learning a first language. Python removes the distraction.

3\. Python's strict white space rules will force you maintain a somewhat
consistent code style – something that many new programmers are awful at.

This list is not exhaustive, just some thoughts.

~~~
louisdefunes
FTFY: "sudo" code ==> pseudo-code

~~~
modzilla
Thanks

------
CyberFonic
JavaScript is not even a good second or third language. Of course it is easy
to cut and paste code and hack things. But when it doesn't work right you will
go crazy trying to work out why.

To be good with JavaScript you need a rather substantial and solid grasp of CS
fundamentals and how they are implemented in languages that are stricter about
what they will accept and how.

In JavaScript there are too many situations where it either does something
totally unexpected (well actually totally logical, but you need to know some
pretty arcane stuff to see it that way) or it just fails silently or less
likely with a terse exception.

For a beginning programmer that is very little feedback to help with
overcoming the initial roadblock. Sometimes called the "getting helloworld to
run problem". Trying to learn JS in a browser context is made even more
difficult because you need to grapple with the DOM - it is not easy to grok at
the best of times.

If you decide to ignore the advice in this and the other posts and go ahead
learning JavaScript as the first language, then I suggest getting a very good
introductory book and perhaps using Developer JavaScript Console. The debugger
is good in that you can single step code and watch variables as they change.
You will probably need to take copious notes to understand what is going on.

To be a competent programmer is more than learning a language, it requires a
solid foundation in computer science and software engineering. Whilst these
topics can be learnt from a book, most people need guidance from those who
have acquired such knowledge. Whether they can be bothered answering newbie's
questions is another matter.

~~~
auganov
What you're saying is pretty accurate and I agree. But the problems you
enumerate are ironically the best parts about learning JavaScript at the same
time.

Failing silently - it's nice to have 'incorrect' programs still do stuff when
learning. Who wants to spend hours tracking problems they cannot even
comprehend? Figuring out the DOM - tricky indeed. But it's at least
superficially familiar to everyone. Browsers have great tools to inspect and
play around with it. You have to learn so much more of _insert other language_
to output to the DOM (or other graphical environments).

My advice: Learn underscore. Always refer to Mozilla's docs first (avoid
w3schools). Learn ins and outs of Chrome DevTools (or the FF equivalent).

If you end up wanting to choose a different language - either go lower-level
(Go, Java, Swift, C-family etc) or higher-level (any LISP pretty much).

~~~
CyberFonic
As for DOM I agree. DOM provides a rather rich collection of widgets with
which to create "interesting" output which with most other languages requires
a GUI framework with its own learning curve. The DOM learning process which
worked for me was to :

Write a simple page in HTML, then open it in Dev Tools and understand the
structure, etc.

Then re-create it using document.createElement(), etc.

I've re-read parts of David Flanagan's "Javascript the Definitive Guide" many
times before I became proficient with many essential concepts in JS. I
recommend the book (yes in hardcopy) as a valuable adjunct to Mozilla's docs.

------
DanBC
Look at "hello world" in Javascript and Python. Then look at "ask user for
their name and display "Hello user's name"" in Python and Javascript.

[https://wiki.python.org/moin/SimplePrograms](https://wiki.python.org/moin/SimplePrograms)

    
    
        name = raw_input('What is your name?\n')
        print 'Hi, %s.' % name
    

[http://www.utexas.edu/learn/javascript/example1.html](http://www.utexas.edu/learn/javascript/example1.html)

    
    
        var who = window.prompt("What is your name");
        document.write("Hello " + who);
    
    

The complication in the Javascript example are the window.prompt and
document.write parts which make Javascript harder for beginners to learn.

~~~
CyberFonic
Thanks for the examples, it clearly demonstrates that JS on its own can't even
provide minimal I/O. That is by design, in the ECMA 262 standard, it specifies
the need for additional objects to provide the I/O. The core language is for
scripting the "extension objects".

------
chadkruse
In my experience, the answer to this question largely depends on what your
ultimate goals are.

Want to become a competent programmer and do that for a living? The advice in
this thread is solid (particularly @CyberFonic's).

If you simply want to hack/glue-up/play around with some side projects, I once
heard someone suggest you pick the language your close friends know best and
buy them lots of beer.

In my case, I needed a newbie-friendly prototyping tool and JavaScript/Meteor
has served me well.

So, give us an idea of your goals, and I'm sure the community here will be
able to steer you in the right direction.

------
mahadazad
Well if someone asks me then I would never ever recommend him to pick
javascript as his first language. Actually javascript is a very different
language as compared to other languages, its a prototype based language which
is not easy to swallow at first, I have seen many experienced developers who
have been into web-development for years using either PHP or Rails even .Net
but they are really weak when it comes to javascript. I would recommend you to
pick up either PHP (which is really easy to understand) or ruby.

let see what others say

------
saluki
I would recommend . . . I would start with this progression . . .
HTML->CSS->Javascript then PHP/MySQL then once you have a handle on creating a
simple web app with PHP/MySQL look at either Rails/Ruby or Laravel/PHP . . .
it's tough to understand all the magic going on in Rails/Laravel till you've
created a basic app from scratch Login/Logout/CRUD etc . . .

Railscasts.com and Laracasts.com are great tools for learning those. But get a
decent foundation before moving to a framework . . . then you can add things
like Angular on top of your app.

~~~
dorfuss
In principle I aggree with saluki - I'd just add a little explanation:

JavaScript lets you control HTML elements, so it would be rather hard to begin
with just JavaScript. Styles in CSS are currently indispensable when writing
any HTML unless you want to rely on crude default formatting. That's why it's
HTML -> CSS -> JS and not the other way around.

Moreover you have to understand that JavaScript is a client-side scripting
language, that is to say that your scripts will be downloaded and executed
solely and entirely on your computer. You will not have any way to open, read
and write to files (except for cookies), because your script "lives" only
inside the browser.

If you want your code not to be seen by a visitor of your website, or if you
want the code to be executed before the page is downloaded and displayed in a
browser, you need a server-side scipts like PHP or ASP so that for example the
visitor has only access to the parts of the website you want him/her to read,
or display content depending on the user login and password.

Later you will see that for storing and manipulating larger amounts of data
you'll need a data base server, which makes sorting and managing information
much easier and faster than if you'd accessed files directly from your
servers' hard drive.

PHP and MySQL are for free and therefore they are recommendable for beginners
- alternatives are Microsoft's .Net + MS SQL and many many other, which are
arguably more robust for commercial, enterprise level applications.

Node.js is however a more modern way of doing things on-line, PHP belongs to
the 2000s.

jQuery is good once you realise why plain javascript s*cks a great deal ;)

Staring your journey with online tools such as JS is ok, but it may be
difficult to later jump into more... how should I put it... "serious?"
languages - once you want to build your own standalone application software
that runs outside a browser (not only because you have to use a compiler, but
also because you have to pay attention to more details and plan ahead). For
instance it's not impossible, but it seems that, switching from strong typed
languages like C to weak typed is easier than the other way around.

Please do never underestimate or neglect learning about design patterns, data
structures and algorithms no matter what language you're using or intend to
learn.

------
timmm
Javascript is a fine language to learn. It should teach you the basic elements
that all languages have. That it is asynchronous is the only major thing that
is different than some other languages.

