Live data from Hacker News

How to write X in both Python 3 and JavaScript

sayazamurai.github.io

21–30 of 84 posts

Re: How to write X in both Python 3 and JavaScript

#21

Creator here! Let me know if you have any suggestions.

Add Python 2 and or another language that has a static type system like C.

Either you forgot to mention that this is a personal todo, or you're trolling the author?

Re: How to write X in both Python 3 and JavaScript

#24

Creator here! Let me know if you have any suggestions.

Nice list. Perhabs just personal preference but I'd use for(let element of someList){ console.log(element); } instead of someList.forEach(element => { console.log(element) }) for...of is easier to read and recognize as a loop construct at first glance, and as far as I recall it's also faster nowadays since the body of the loop is inline, whereas forEach requires the runtime to deal with a function object.

Personally I find the method-style syntax significantly more readable.

Re: How to write X in both Python 3 and JavaScript

#29

Creator here! Let me know if you have any suggestions.

Nice list. Perhabs just personal preference but I'd use for(let element of someList){ console.log(element); } instead of someList.forEach(element => { console.log(element) }) for...of is easier to read and recognize as a loop construct at first glance, and as far as I recall it's also faster nowadays since the body of the loop is inline, whereas forEach requires the runtime to deal with a function object.

You can also ‘return’ the outer function from within a ‘for...of’ which is pretty useful imo.

Re: How to write X in both Python 3 and JavaScript

#30
post #17

Earlier quoted context omitted.

Nice list. Perhabs just personal preference but I'd use for(let element of someList){ console.log(element); } instead of someList.forEach(element => { console.log(element) }) for...of is easier to read and recognize as a loop construct at first glance, and as far as I recall it's also faster nowadays since the body of the loop is inline, whereas forEach requires the runtime to deal with a function object.

Makes me wonder if maybe the syntax for mapping, folding and other collection operations should have a similar syntax to for instead of the current method-style syntax popular in most modern languages.

C# has a syntax called Linq Query Syntax that provides keywords in the language to do things like map, filter, and reduce.

Example:

  var queryLondonCustomers = from cust in customers
                             where cust.City == "London"
                             select cust;

I'm not a big fan of it honestly, the function style seems more consistent and easier to read to me.
Post reply on HN