3 ms·
reads a bit like javascript now. You might want to consider switching languages
by master-lincoln 3y ago
reads a bit like javascript now. You might want to consider switching languages
- contravariant 3y agoHonestly I'm jealous of JavaScript's arrow syntax. I don't really need anything else but the arrows are nice (and Turing complete).
- maegul 3y agoI always figured that once Python got the walrus operator it would be a matter of time until arrow functions of some sort made more and more sense on Python.
- Spivak 3y agoI really hope not tbh, once you break that seal it will consume the entire language into nested anonymous function soup without all the facilities JS has accumulated over the years to mitigate it. Python is an iterator based language and it leads to some very nice code if you design with that in mind. It's really incredible how much such a small feature in the grand scheme of things `(function() { })()` influences all API and library design. Right now passing around functions in Python is ugly and reads as such which is enough of a deterrent for most people.
- mst 3y agoI really wish python would steal 'let' from JS, specifically in a block scoped form - coming from perl's 'my' as a way of life, python's (and ruby's) function level scoping and "surprise! variable just popped into existence on assignment!" behaviour really messed me up.
- boppo1 3y agoCan you tell me more about the usefulness of 'let'? I'm an intermediate(?) programmer but I've worked mostly in Python, C and C++. I did one JS project and everything I saw about 'let' seemed redundant.
- mst 3y agoFirstly (compared to python at least) there's the obvious 'typo in variable name barfs early' advantage, which honestly is not to be sniffed at on its own. But my big thing is about being able to scope values to the specific block where they belong: ... let foo; { let x = blah(); let y = frob(x); foo = munge(y); } and the temporaries 'x' and 'y' have gone away as soon as the } happens. also, if you've ever had "fun" trying to capture a loop variable, for (let val of things) { callbacks.push(() => val.finish()); } has a different 'val' for each iteration of the loop so you can do that safely without requiring some sort of copying or an intermediate function invocation to create an extra scope. Oh, and it also renders impossible certain weird constructs like if <test>: some_name = ... where now whether the some_name variable even -exists- after that if block is indeterminate without knowing which way the <test> went. I also like being able to do e.g. for (let thing of things) { let blah = thing.blah; callbacks.push(() => blah.doThing()); } Without 'let' you'd have to write (for the first 'for' example) for (var val of things) { callbacks.push(((val) => { return () => { val.finish() } })(val)); } to perpetrate let-over-lambda to get a separate scope for the callback function. This is not my favourite thing to write, and -very- far from my favourite thing to read later. Hopefully that gives you a better idea of why I, at least, prefer having 'let' available.
- saagarjha 3y agoOh it definitely does. The reason I stick with Python is that it has a somewhat decent standard library, and IMO fewer surprises (I don’t know Python or JavaScript all that well, since I basically never use it professionally, so I need to reduce footguns for myself).
- djxfade 3y agoType cohersion and type juggling can bring a few surprises. But usually only when you do something weird to hit those edge cases. Otherwise, it's standard library is actually very decent now. Especially when working with arrays. You have all the nice to have methods, like, split, find, filter, map, reduce, every, some, etc... Which makes it a really nice language for these kind of tasks. The example above would like this in modern javascript: str.split(',').map(char => Number(char)).filter(num => num > 5).length
- worksonmine 3y agoOr if you like to live dangerously: str.split(',').filter(n => +n > 5).length
- dumbo-octopus 3y agoNot all that dangerous, tbh. My main concern would be NaN potentially cascading through, but not only is `NaN > 5` false, `!!NaN` is too.
- saagarjha 3y agoTo be clear by “standard library” I mean that Python has like actual data structures that are useful. Also while not part of the standard library arbitrary precision integers and associated functions (e.g. modular pow) can be quite helpful.
- recursive 3y agoJavascript now has Map, Set, and bigint. But no powmod.