News for hackers. Stuff that matters.
Re:Eloquent JavaScript 3rd Edition (2018) by warent on Sunday April 26, 2020 @08:36PM (#22991742)
I would consider myself pretty close to an expert with JavaScript. I've been using it for 5 years professionally, currently use ES2020. Fairly familiar with Node 12, V8, etc. But I'm always worried about those situations where you dont know what you dont know. This might sound strange, but would anyone recommend any reading material or blogs for someone at my level?
Re:Eloquent JavaScript 3rd Edition (2018) by guruparan18 on Sunday April 26, 2020 @08:40PM (#22991771)
I am not a full blown Javascript developer (backend developer here), but had been using JS and other frameworks for about 10 years now. I subscribed to Dan Abramav's "Just Javascript" [1] email. It is really good to read/follow and has one concept and idea explained well.

[1]: https://justjavascript.com/

Re:Eloquent JavaScript 3rd Edition (2018) by aastronaut on Monday April 27, 2020 @12:01AM (#22992781)
I think the sentiment of "you dont know what you dont know" is especially cumbersome with JS, since its usability is so much defined by its extensions (WebAPIs, runtimes etc.)

Reading into specs (ECMAScript[0], W3C[1]), some more approachable explanations[2] of them and some implementations[3, 4] of embedded engines seem to be my approach.

[0]: https://tc39.es/ecma262/2020/ [1]: https://github.com/w3c [2]: http://dmitrysoshnikov.com/ecmascript/javascript-the-core-2n... [3]: https://bellard.org/quickjs/ [4]: https://v8.dev/docs/embed

Re:Eloquent JavaScript 3rd Edition (2018) by tchaffee on Sunday April 26, 2020 @09:23PM (#22992019)
In addition to the already mentioned 2ality blog and YDKJS books, read Javascript Allonge [1].

[1] https://leanpub.com/javascriptallongesix/read

Re:Eloquent JavaScript 3rd Edition (2018) by varrock on Sunday April 26, 2020 @10:29PM (#22992326)
I decided to read Eloquent JS before exploring Allonge. Can anybody who has read both give their opinions on each? How are they similar/dissimilar?
Re:Eloquent JavaScript 3rd Edition (2018) by Dangeranger on Sunday April 26, 2020 @10:43PM (#22992406)
Eloquent is more of a fundamentals focused book, whereas Allongé is an excellent object-oriented foray, mixed with functional tidbits and examples. Allongé shows that you can get the best of both worlds, object and functional, by applying the right technique in the correct places.
Re:Eloquent JavaScript 3rd Edition (2018) by varrock on Sunday April 26, 2020 @10:55PM (#22992450)
One thing I've struggled with in JavaScript is choosing a more functional or OOP approach in certain situations. I can never tell if I should stick to one or the other. Allonge sounds like it'll really help me figure that out.
Re:Eloquent JavaScript 3rd Edition (2018) by tomxor on Monday April 27, 2020 @08:42AM (#22995250)
> One thing I've struggled with in JavaScript is choosing a more functional or OOP approach in certain situations

A couple key realizations made this much less of a "choice" for me (warning, my opinion):

1. Classes et al, are just a high level pattern which happens to be builtin... functions are far far more rudimentary.

2. If you use a high level pattern "just because you can" without considering the subjective cost vs benefit, it will be a poor fit on average.

What does this mean?

#1 Functions are not the opposites of classes, they are simpler, lower level abstractions which are more generalized - It should be thought of as the default.

#2 Like any pattern, OOP has a cognitive cost - When they don't fit a problem well, they merely obscure relationships between state and function; when they do fit a problem, they will minimize that cost and provide benefits that simplify other code.

If you don't immediately know that classes or prototypes fit the piece of code you are writing... just stick to functions, if later on you find that a collection of functions emerge with a common signature and persistent state being passed back and forth - you might have something that would benefit from a class, but you can simply change them into a class when it emerges. However if you do it preemptively you will probably be wrong and also make poor decisions about what the internal encapsulated state should be (which you want to minimize since you are obscuring it). It's ok to discover that something should be a class, attempting to make the choice up front is usually going to go wrong unless it's very obvious.

I think it's unfortunately a pretty natural path to start out not having an opinion of OOP and then potentially developing a distaste for it later on - not because it's inherently bad (it's probably the most generalized pattern and very useful); but because of it's integration into so many languages... I see it get abused by people all the time who just make a class by default for no apparent reason, which inevitably ends up as a bag of loosely associated state and arbitrary functions mutating one or more of those states. In such cases the class is of no benefit, and worse, it's obscuring all of the unrelated state mutations making it difficult to read and reason about.

Re:Eloquent JavaScript 3rd Edition (2018) by galaxyLogic on Monday April 27, 2020 @12:31AM (#22992901)
One thing I don't get it is people who would say you must choose between objects and functions, or that FP is "better" than OOP.

Objects have function-valued properties called methods. So Objects can't do without functions.

Functions can return either a) atomic values like strings and numbers OR b) Objects. Note that in JavaScript Functions are Objects too.

So I hope no-one is seriously suggesting that FP can do without Objects, by saying that functions should only return atomic values.

Re:Eloquent JavaScript 3rd Edition (2018) by archarios on Monday April 27, 2020 @02:39AM (#22993459)
The problem here is that this conversation is made complicated by the fact that plain objects in JavaScript are not what is really being talked about when people say the term OOP. So to clarify, stateful classes would be what I am talking about when I use that term. The foundation of OOP is based on tying state with functions in what are deemed "Objects". This implicitly makes all methods in an Object that depend on or modify an Object's internal state impure functions. And the purpose of most Objects methods are for the purposes of doing those things. Basically if you use stateful classes that encapsulate state and modify their own internal state with functions you are not doing functional programming. These two paradigms are in fact at odds and not compatible.
Re:Eloquent JavaScript 3rd Edition (2018) by galaxyLogic on Tuesday April 28, 2020 @12:10AM (#23003270)
> This implicitly makes all methods in an Object that depend on or modify an Object's internal state impure functions

Note that you can have methods which do not depend on mutable state. In ES6 you can FREEZE objects, which you could do in the constructor. Freeze the object after having set its "instance variables". Now all methods of that object are "pure functions". So you can choose. Choose to create pure functions or impure.

Creating a new immutable instance really is equivalent to creating a set of immutable ('pure' if you like) functions.

Re:Eloquent JavaScript 3rd Edition (2018) by colordrops on Monday April 27, 2020 @12:34AM (#22992910)
OOP and functional programming aren't mutually exclusive.
Re:Eloquent JavaScript 3rd Edition (2018) by archarios on Monday April 27, 2020 @12:09PM (#22997151)
How do you define object-oriented programming? From my perspective the very core of it is stateful objects with encapsulation and methods on those objects that pretty much always are not pure. If you just start treating objects like collections of functions, I don't really see how that's OOP. As far as I remember, it has been a little bit since I've used OOP everyday, pretty much every facet of the paradigm is centered around mutating state. You can certainly commingle OOP and functional code, but they simply aren't compatible paradigms.
Re:Eloquent JavaScript 3rd Edition (2018) by nivethan on Sunday April 26, 2020 @10:17PM (#22992287)
Thank you the recommendation, it is written quite well and I'm really liking the tone.
Re:Eloquent JavaScript 3rd Edition (2018) by hoorayimhelping on Sunday April 26, 2020 @09:56PM (#22992204)
I've been using JavaScript professionally for about 12 years.

You're going to have to look for talks and really technical posts. Consider whitepapers and source code for JavaScript engines at this point. You'll probably want to start reading up on the things attached to JavaScript, rather than the language itself. Browser rendering, event loop, V8 things, garbage collection, etc.

I'm sure you've seen it, but things like this: https://www.youtube.com/watch?v=8aGhZQkoFbQ, and this: https://www.youtube.com/watch?v=SmE4OwHztCc

It might be time for you to start writing what you know about JavaScript.

Re:Eloquent JavaScript 3rd Edition (2018) by quickthrower2 on Monday April 27, 2020 @02:50AM (#22993517)
I was lucky enough to see this live - https://v8.dev/blog/elements-kinds - but I recommend watching and reading for anyone. Half because is pretty interesting and accessible at the same time. And half because you might use it .

Also Typescript is well worth learning.

Re:Eloquent JavaScript 3rd Edition (2018) by nujabe on Sunday April 26, 2020 @10:37PM (#22992377)
I definitely wouldn't consider the first video 'advanced' material (an excellent talk btw), JavaScript event loop is something beginners should know about and intermediate developers know very well.
Re:Eloquent JavaScript 3rd Edition (2018) by azangru on Monday April 27, 2020 @08:03AM (#22995004)
Ah, but do they know where in the event loop, for example, "microtasks" get executed as opposed to... I forget.. tasks? In other words, how execution of promises is different from the execution of setTimeout?
Re:Eloquent JavaScript 3rd Edition (2018) by mosdl on Monday April 27, 2020 @12:17PM (#22997220)
This. For example, classes are much easier to optimize for than json objects, which really hurts the functional programming and redux crowd.
Re:Eloquent JavaScript 3rd Edition (2018) by jrajav on Sunday April 26, 2020 @09:15PM (#22991978)
Have you ever read through this annotated ES5 spec? Even annotated it's still pretty dense, but it's a nice way to both dive deeper into the language and as a 'minimap' to guide you through the parts you have yet to totally master. It definitely helped me level up more.

https://es5.github.io/

Re:Eloquent JavaScript 3rd Edition (2018) by mrdoob2 on Sunday April 26, 2020 @09:48PM (#22992152)
I would recommend watching Andreas Kling's youtube series where he builds a javascript engine from scratch.

https://www.youtube.com/watch?v=byNwCHc_IIM

Re:Eloquent JavaScript 3rd Edition (2018) by mttyng on Monday April 27, 2020 @12:29AM (#22992893)
Oh, this is great! Thanks!
Re:Eloquent JavaScript 3rd Edition (2018) by weaksauce on Sunday April 26, 2020 @09:24PM (#22992026)
if you can't find something you didn't already know in the free book series "you don't know javascript" then I'd imagine you might not have any gaps in your knowledge. (at least for 99% of it)

(you can buy a hard copy of it if you want but it's open source)

https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/READM...

Re:Eloquent JavaScript 3rd Edition (2018) by colordrops on Monday April 27, 2020 @12:33AM (#22992907)
Are you familiar with various tc39 proposals? Do you understand how JS VMs work?

Knowing the internals of the engine really informs you on performance and resource utilization characteristics of various ways of writing code.

Re:Eloquent JavaScript 3rd Edition (2018) by _hardwaregeek on Sunday April 26, 2020 @10:36PM (#22992370)
Some of the TC39 proposals might be worth looking at. The ES spec too.

If you really want to go all out, you could write a simple JS interpreter. Probably don't want to go full spec compliant but you could implement a decent subset. Especially if you skip the parsing step with Acorn https://github.com/acornjs/acorn

Re:Eloquent JavaScript 3rd Edition (2018) by mpoteat on Sunday April 26, 2020 @08:38PM (#22991753)
I would maybe recommend Typescript if you want to harness the type level power of "proving" correctness for certain aspects of your code.
Re:Eloquent JavaScript 3rd Edition (2018) by leshow on Sunday April 26, 2020 @11:14PM (#22992554)
Big scare quotes there, you can't really 'prove' much in typescript. Don't get me wrong, it's a nice type system they've tacked on to JS, but it's far and away from proofs of correctness. At best, it's an optional type system with escape hatches.
Re:Eloquent JavaScript 3rd Edition (2018) by futureproofd on Monday April 27, 2020 @10:26AM (#22996108)
You can only 'prove' what you expect from your design. This works in most cases and saves a lot of guesswork on big, unfamiliar projects. It's not an integral part of JS though, so I wouldn't recommend learning it as a foundation.
Re:Eloquent JavaScript 3rd Edition (2018) by narak on Sunday April 26, 2020 @08:38PM (#22991754)
Re:Eloquent JavaScript 3rd Edition (2018) by bryanrasmussen on Monday April 27, 2020 @12:57AM (#22993000)
read "you don't know JS" series of books, also second edition https://github.com/getify/You-Dont-Know-JS I find the workshops very helpful as well, which I've watched through my oreilly membership don't know if you can find them elsewhere, I would suggest combine this with reading the specs.

on edit: one reason the specs are not enough is generally specs will tell you what needs to be implemented but a good book, like these ones, will tell you how it has been implemented or what the spec implies for implementation and what all that will mean for you as a user of the language.

Re:Eloquent JavaScript 3rd Edition (2018) by smlckz on Monday April 27, 2020 @01:25AM (#22993118)
try to implement a ES2020 interpreter from scratch (like fabrice bellard's quickjs)

when you're done, you'd have learnt enough on the way and know what you don't know

Re:Eloquent JavaScript 3rd Edition (2018) by iceIX on Sunday April 26, 2020 @08:42PM (#22991786)
Re:Eloquent JavaScript 3rd Edition (2018) by ggregoire on Sunday April 26, 2020 @09:23PM (#22992023)
> But I'm always worried about those situations where you dont know what you dont know. This might sound strange, but would anyone recommend any reading material or blogs for someone at my level?

It's not very clear what you are asking, neither what's your background. In your situation I wouldn't spend more time learning stuff about JavaScript, I would just improve my skills in software engineering (design patterns, code quality, refactoring, etc) and diversify my knowledge (learn other languages (python, go, or some FP language to learn something really different); databases and SQL; web servers and REST; etc).

Re:Eloquent JavaScript 3rd Edition (2018) by LocalPCGuy on Sunday April 26, 2020 @11:15PM (#22992566)
Not sure how it holds up, but Secrets of the Javascript Ninja was the book I read when I felt like that, and it significantly helped me understand a few concepts I had struggled with. By John Resig (created jQuery). But it's a few years old now, so likely won't cover much if any ES6+ stuff. But I'd bet the concept stuff is still very valid.

Also the You Don't Know JS series. And Elliot's Programming Javascript Applications.

I don't know you, so I don't know if this applies or not, but be careful not to fall into the "expert beginner" trap (i.e. Dunning Kruger). Your first sentence starts to feel that way, but the fact you're asking for more resources and aware there are things you don't know are good signs. Always keep learning, the rabbit hole goes ever deeper.

Re:Eloquent JavaScript 3rd Edition (2018) by toohotatopic on Monday April 27, 2020 @01:17AM (#22993082)
At one point, there will be only sourcecode to read. Read what the best programmers actually do use.
Re:Eloquent JavaScript 3rd Edition (2018) by nicoburns on Sunday April 26, 2020 @09:19PM (#22992004)
Re:Eloquent JavaScript 3rd Edition (2018) by emmanueloga_ on Sunday April 26, 2020 @10:10PM (#22992258)
humble opinion: N years of using any language won't make you an expert.

There's knowledge about how to express certain patterns in a given language, more like an application design expertise. There's knowledge and familiarity with the APIs. And then there's the deep language knowledge, the one that pretty much only someone implementing a language VM, parser, compiler and other tools may acquire with time. Also, there are a lot of specifics about every particular JS implementation.

Also, Dunning–Kruger :-)

On the internals of VMs, https://mrale.ph/ has a lot of blog posts on internals/optimizations on V8. https://www.wingolog.org/tags/javascript also has deep JS articles very freqently.