28 comments

[ 3.4 ms ] story [ 63.3 ms ] thread
Do you guys know a good tutorial for focused on server side js (node, express, etc) Whats the best resource to learn node? Thanks in advance
Wes Bos has a paid course that covers a whole bunch of things over at https://learnnode.com/ - it's relatively recent I believe, so should cover some ES6 goodness.
http://expressjs.com/en/guide/routing.html

Expressjs official guide (there are more guides after routing)

https://github.com/sahat/hackathon-starter/blob/master/READM...

git clone this and add a feature or convert it into a small prototype of an app. If you're out of ideas, switch out mongodb for postgre. Does the tests still work? If you can add something interesting, send a PR. Read the entire readme.

https://blog.feathersjs.com/a-real-time-chat-frontend-with-p...

Make a chat room with feathersjs.

https://stackoverflow.com/questions/2353818/how-do-i-get-sta...

More resources

Not free (some of the intro videos are free, but most are not), but egghead.io puts out some excellent material. I am pretty good at js stuff, but I keep my membership as the newer content is kind of a discovery thing (learn about things I might not have otherwise seen because a series of videos popped up on egghead).
This is the source for the website at https://javascript.info/ . It's actually quite good - I'm reading about garbage collection at the moment. Looking forward to the inheritance/prototype section, something that's never quite stuck for me.
> Looking forward to the inheritance/prototype section, something that's never quite stuck for me.

I glanced through the section and I don't know how much it's going to help.

What helped me was to stop thinking that JS had inheritance at all. Inheritance implies some sort of copying and combining of object behavior. In a language with classical inheritance, a child class has all the methods of a parent class. A instance object of a class has all its methods plus all of its parent's methods directly on it.

JS doesn't do that. When you create an object that has a parent, you're creating two objects (the parent and the new child). When you call a method on the child that comes from the parent, the child doesn't hold that method, the parent does, so it delegates to the parent.

So, I think when people ask you in an interview whether JS has classical inheritance or prototypal inheritance, you should say neither--it has behavior delegation.

Please let me know if that makes sense.

Isn't delegating to the parent object prototypical inheritance?
Yes, that's what we call prototypal inheritance. What I'm saying is that I don't think it's a good name for what's going on, since it clearly causes a lot of confusion.
Eh, I think that's debateable.

Agreed that delegation is more clear though.

Question:

I started a JS project lately, I tried to write it as modernly as possible (using as many ES6 features[1] as I could), and yet I stumbled on difficulties that I blame to the lack of type system and polymorphism.

I'm considering writing my project in a typed language that compiles to JS, such as Scala or Haskell. But I would have to learn that language basically from the start.

Is it a good idea and if so which language would you recommend?

Kotlin
Never heard of it. Definitely intriguing. Thanks.
Any tutorials or starter boilerplates on using kotlinjs or bucklescript with vuejs would be much appreciated.
Have you tried using typescript? That would be the closest you can get to a language that feels like JavaScript(it's a superset) and it has good tooling, types, and inter-op with JavaScript.

If you still want to try a language that compiles to JavaScript, I'd suggest taking a look at elm too. It has good documentation. It might lack some features from Haskell but in my opinion it is still a fun interesting language to learn.

I mainly use JavaScript at work but have now began to move to TypeScript. I like it because I'm most familiar with JS and can reuse most of that knowledge, but I have the advantage of types (amount other things) and I still get JS in the end.
> difficulties that I blame to the lack of type system

What are they exactly?

Have a look at OCaml. There's a project called BuckleScript that provides an OCaml to JavaScript compiler that maps OCaml quite cleanly to Javascript. Because BuckleScript is written in OCaml, it can also compile itself, resulting in the demo at [0]. Playing with that demo and looking at the output convinced me to give OCaml with BuckleScript a chance.

I was completely disillusioned with with JS. Thinking that types were the solution I tried TypeScript and found that I wanted it to be something it was never meant to be and just went back to JS. So far I've successfully used OCaml+BuckleScript with Mithril for a few personal projects and it's been really fun. I felt able to predict my productivity after only about 20 hours of use. If you do have any JS libraries that you can't write BuckleScript bindings for, or you can't figure out how to write bindings for them, you can always write a small JS shim that you can easily write bindings for.

OCaml isn't as dogmatic about purity as Haskell and unlike Haskell you're not encouraged to write type signatures for most functions. There's also far less of OCaml to learn than Haskell or Scala. All round it's a really good general purpose language.

There are two incompatible attempts at better standard libraries (core and batteries) and each encourage you to write OCaml in a style that does not have the feel of OCaml. The OCaml standard library itself is a collection of datatypes and depending on what you're doing may well be good enough.

There's also Reason [1], an alternative syntax for OCaml. Reason is undergoing heavy development at the moment and it appears that syntax changes are coming.

[0] https://bucklescript.github.io/bucklescript-playground

[1] https://reasonml.github.io/guide/what-and-why

Would you elaborate on the issue? JavaScript actually does have a type system, it's just not very transparent. Using triple equals will not coerce types when comparing, whereas double equals will.
Well, it does have a type system, but it's arguably the weakest kind of typing among all mainstream languages.
does Bash count as a mainstream language? :P (just kidding)
Yes. SQL too.

Neither are intended to be general purpose languages though.

What kind of project is it?
You don't have to use all the syntax sugar, eg. array.concat vs ...spread And I guess its hard to stop thinking about types. its probably easier to go from assembly to JS, then from Java to JS ... In JS you just have to know string or number ... Although I'm no fan of it, you can annotate the variables like sName, nAge, sAddress, nCount, nId, sComment, nCommentId, etc. Or use - - (minus minus) when doing addition. Most other bugs will result in syntax errors or the classic "undefied is not a function" when trying to call push on an object that is not an array object.