News for hackers. Stuff that matters.
Re:Composing Programs – An introduction to programming in th... by evacchi on Tuesday July 31, 2018 @07:30AM (#17652275)
A friend of mine is approaching programming (very beginner level) through JavaScript. Is there any resource you would suggest in the same vein of this?

EDIT: since people are asking, I agree that JS is not the best language to get started, but let's just say he needs to learn that.

Re:Composing Programs – An introduction to programming in th... by ivan_ah on Tuesday July 31, 2018 @09:35AM (#17652989)
This might be of interest: https://www.comp.nus.edu.sg/~cs1101s/sicp/ (SICP in js)
Re:Composing Programs – An introduction to programming in th... by sciurus on Tuesday July 31, 2018 @12:29PM (#17654560)
Not a direct equivalent, but I've frequently seen people recommend https://eloquentjavascript.net/
Re:Composing Programs – An introduction to programming in th... by invalidOrTaken on Tuesday July 31, 2018 @04:05PM (#17656597)
Seconding this recommendation.
Re:Composing Programs – An introduction to programming in th... by LandR on Tuesday July 31, 2018 @07:48AM (#17652389)
I would suggest absolutely not learning programming via javascript as your first language.
Re:Composing Programs – An introduction to programming in th... by haney on Tuesday July 31, 2018 @10:19AM (#17653320)
I agree that javascript is a bit odd for a beginner in terms of scoping, callbacks, truthiness, etc. However, it's really broadly applicable, JS would be a horrible choice for a university introductory course but might not be a bad choice for a hobbyist who's trying to quickly start doing things that keep them interested in learning.

I would however, strong suggest that javascript shouldn't be someone's only language.

Re:Composing Programs – An introduction to programming in th... by jakear on Tuesday July 31, 2018 @10:30AM (#17653428)
Python has the same scoping as JS. I really don’t get why people complain about this then propose python as an alternative. JS even got past that with let/const.
Re:Composing Programs – An introduction to programming in th... by enitihas on Tuesday July 31, 2018 @10:38AM (#17653500)
In JS, declaring a variable without var gives it a global scope, in python not so.

Also, js is a lot more inconsistent than python. The amount of js gotchas is huge(== weirdness, hasOwnProperty for iterating through object fields, binding of this, only 64 bit doubles as a number type). Python is much less surprising, and gives you much less opportunities to screw up.

Re:Composing Programs – An introduction to programming in th... by jakear on Tuesday July 31, 2018 @12:50PM (#17654742)
As a sibling to my other comment: Python is not less surprising, when programming in a JS style.

`nonlocal` is crazy. That lambdas may only be a single line is annoying. Being unable to print anything out of a map or filter operation without first converting to a list gets tedious quick. And not being able to go in for a quick monkey patch on repr, because builtin classes are magically different than user defined classes in “some way”, which makes modifying them prohibited, is limiting.

Sure, the easy retort is: that’s not what you should be doing anyways, python just enforces it. But I’d personally hate to see such an argument in the comment section of SICP, the pinnacle of programmer freedom.

Edit: and what about mutable default parameters?? I’ve had a fair amount of experience with python and sill been bitten by a mutable default parameter bug (not quite that, but related) in the past couple months. JS gets rid of that entirely by making them just syntactic sugar for what it would do anyways, which is much easier to reason about.

Re:Composing Programs – An introduction to programming in th... by jakear on Tuesday July 31, 2018 @01:01PM (#17654875)
The bug I had was declaring variables in the body of a class without `self.`. Turns out that makes them static. Ironically similar to JS making non prefixed declarations global, except I received no in editor warnings about that, and it wasn’t something beaten into my head from the day I started.

Edit: or was it that I initialized them at time of declaration rather than in the constructor? Not sure. Something along those lines.

Re:Composing Programs – An introduction to programming in th... by hannofcart on Tuesday July 31, 2018 @02:54PM (#17655945)
Most of the issues I find people annoyed with in JS are becoming less of an issue with modern idiomatic JS that is less object oriented, more functional and with ES6 utilities replacing more troublesome legacy idioms. I work on a fairly large app that uses little no classes. Also, I haven't had to use hasOwnProperty in a year! I just use Object.keys()
Re:Composing Programs – An introduction to programming in th... by jakear on Tuesday July 31, 2018 @12:35PM (#17654606)
That’s a strange decision with regard to variable definitions, but not really a “scoping” abnormality. As in: that’s the scope you’d expect from a global variable, but not the syntax you’d expect to get you a global variable. Anyways, a base VS Code installation will throw a warning about that.

The other things are also not scoping. I’m not arguing JS is consistent, I’m just saying people should stop complaining about its scoping then offering python as a solution.

Re:Composing Programs – An introduction to programming in th... by hannofcart on Tuesday July 31, 2018 @12:45PM (#17654695)
As someone who just spent a day hunting down a Heisenbug caused by using a default argument bound to a datetime.now(), I beg to differ.

Honestly, all languages have quirks. When pummeling a language for gotchas, may he whose favourite language is without quirks cast the first stone.

Re:Composing Programs – An introduction to programming in th... by kungtotte on Tuesday July 31, 2018 @02:03PM (#17655473)
I don't think anyone is making a case for any given language being without quirks, but I think it's highly relevant how easy it is to stumble upon them.

If the quirks reside mostly in parts of the language only touched in really advanced expert use, it's generally not a problem because the people who venture there will know what to look out for. If your language has a quirky while statement on the other hand, it's something everyone will trip over.

E.g. Python's default mutable argument thing is fairly common to trip over (but on the other hand the behaviour is consistent and predictable once you know it), but monkey-patching builtins is not quite as common and definitely in the realm of "don't touch unless you know what you're doing".

Re:Composing Programs – An introduction to programming in th... by jakear on Tuesday July 31, 2018 @03:28PM (#17656268)
The issue isn’t that it’s “don’t touch if you don’t know what you’re doing”, it’s “you can’t touch this at all, even if you might know what you’re doing or be willing to accept the consequences of your experimentations”
Re:Composing Programs – An introduction to programming in th... by evacchi on Tuesday July 31, 2018 @12:17PM (#17654470)
I agree with everything
Re:Composing Programs – An introduction to programming in th... by freetonik on Tuesday July 31, 2018 @09:47PM (#17658984)
May I suggest my course on the fundamentals of programming with JavaScript ES6 https://www.youtube.com/playlist?list=PL-xu4i_QDSxcoDNeh8rx5...

It is heavily inspired by SICP and covers important topics like recursion, iteration, static vs. dynamic typing, testing and more.

Each video is accompanied by a text version, a quiz and an interactive programming exercise (links are in video descriptions). The course is completely free of charge and I’ll be happy to answer any questions and help your friend solve problems if he or she decides to do the exercises on our site.

Re:Composing Programs – An introduction to programming in th... by anarchyrucks on Tuesday July 31, 2018 @07:38AM (#17652326)
Why is JavaScript an absolute requirement? I guess he can learn python as his first programming language which I personally think will be easier to setup/run in the machine instead of installing node.
Re:Composing Programs – An introduction to programming in th... by reacweb on Tuesday July 31, 2018 @08:23AM (#17652560)
Yes. And for beginners, https://py3.codeskulptor.org/ is fantastic.
Re:Composing Programs – An introduction to programming in th... by bogomipz on Tuesday July 31, 2018 @10:31AM (#17653436)
And also Python Tutor:

http://pythontutor.com/

Re:Composing Programs – An introduction to programming in th... by QML on Tuesday July 31, 2018 @08:57PM (#17658758)
A great complement to that would also be to use Jupyter, whose notebooks are similarly interactive and not dead like typing into a blank terminal or IDE.
Re:Composing Programs – An introduction to programming in th... by martalist on Tuesday July 31, 2018 @09:24AM (#17652906)
freecodecamp.org is pretty good at taking a practical approach to learning programming, primarily with JavaScript. But if your friend wants to also understand the basics of computer science it's worth considering doing both.
Re:Composing Programs – An introduction to programming in th... by e12e on Tuesday July 31, 2018 @12:49PM (#17654732)
I guess I struggle to see why it has to be Javascript exactly (even if js6 isn't all bad). How about reasonml or clojure(script)?