Earlier quoted context omitted.
> the complaint (which is extremely common) is that functions that contain statements are not expressions in Python, so functional coding styles using things like .map() and .reduce() end up fragmented You mean these critics find >>> map(lambda x: x**2, filter(lambda x: not x % 2, range(11))) preferable to the "fragmented": def square(x): return x ** 2 def is_even(x): return not x % 2 >>> (square(x) for x in range(11…
But your lambda example would be more clear if collections functions supported chaining. You can add a small comment if you want to be explicit. This way the code reads linearly, you don't have to wonder why a "square" function and "is_even" function are defined before you see how they are used. # square even numbers range(11) .filter(lambda x: not x % 2) .map(lambda x: x ** 2) However such a chaining API is not prac…
Leaving Python for JavaScript
71–80 of 112 posts
Re: Leaving Python for JavaScript
#72> there's no acceptable way to pass a function body to another in Python. There are sentences which are telling a huge incompetence about the person using these. This sounds the same story to me as "We used tech X, but X is shit/can't do something so we switched to Y, and Y is awesome and fast." Where the person switching was just incompetent with X but it would have been perfectly solvable and they just do a totally…
No one likes callback hell but I believe they meant that you can just pass a function expression directly. No need to define a named function. It's the difference between: let doubled = nums.map(x => x * 2) and this: def double(x): return x * 2 doubled = map(double, nums) (my Python is pretty rusty so maybe there's a better way of doing that)
Typically in programming you don't often encounter the need to pass a multiline anonymous function into another function, it leads to confusing code. Async/await gets rid of this bs all together which is the pythonic way to do async.
btw pythonic code for maps or filters is to use list comprehensions so
doubled = [x2 for x in nums]
or if you want to use a anon function:
doubled = [(lambda y: y2)(x) for x in nums]
Re: Leaving Python for JavaScript
#73Why is all the actual content on the far right side of the page? Even more interesting given that you specialize in UI/UX.
Hi, it's just a blog, not a paid job. Not a lot of effort went into it. I'll take a look when I have a chance (it looks fine on my MBP and several others).
Re: Leaving Python for JavaScript
#74Earlier quoted context omitted.
I have been in your position about a year ago. The approached that helped me, was to not worry about all this. Just start somewhere; and in a month or two, you would mostly know which libraries you need to add to your project. The best way to go about it, is to check a few popular open source projects; what libraries they typically use. > I am also asking if any of those libraries will be around in a year? You can ch…
I mean no offense, but the "just use it you'll get used to it" strategy seems the antithesis of the goal of engineering as a discipline. A materials engineer simply cannot afford to pick concrete unless she knows the specific load and weathering characteristics of it. The same should be true for software projects. You shouldn't use cheerio because everyone uses it in their project, but because you've looked through t…
Re: Leaving Python for JavaScript
#75Poor misguided person
Re: Leaving Python for JavaScript
#76So a person who writes web apps prefers JS over Python. Cool. Pick the right tool for the job. If your job is writing client-side-heavy web apps that share code between the client and server, then JS might be a better choice than Python. Look, writing programs that respond to HTTP requests with HTML is not rocket science. You can do it in JS, Python or Ruby and be very productive. If you hate yourself, you can do it…
Re: Leaving Python for JavaScript
#77> there's no acceptable way to pass a function body to another in Python. There are sentences which are telling a huge incompetence about the person using these. This sounds the same story to me as "We used tech X, but X is shit/can't do something so we switched to Y, and Y is awesome and fast." Where the person switching was just incompetent with X but it would have been perfectly solvable and they just do a totally…
JS:
doThing(function(){
blah();
de();
blah();
});
Python: def thing_doer():
blah()
de()
blah()
doThing(thing_doer)Re: Leaving Python for JavaScript
#78I'm probably being overly optimistic, but I look forward to a future where a "naked JS" movement rises up, similar to "vanilla JS", but rebelling against tooling complexity instead of jQuery bloat, in which your website's /js/ folder contains pretty much exactly what's in git.
Re: Leaving Python for JavaScript
#79Earlier quoted context omitted.
You can do the exact same thing in Python, and this is not any new feature: doubled = map(lambda x: x * 2, nums) JS it's just not as explicit with what you're exactly doing.
The pythonic way is to use a list comprehension for maps and filters.
Re: Leaving Python for JavaScript
#80Earlier quoted context omitted.
No one likes callback hell but I believe they meant that you can just pass a function expression directly. No need to define a named function. It's the difference between: let doubled = nums.map(x => x * 2) and this: def double(x): return x * 2 doubled = map(double, nums) (my Python is pretty rusty so maybe there's a better way of doing that)
It's true js is better with anonymous functions. But the design of js (node esp.) requires you to constantly pass these callbacks to do async. Critics of JS are basically claiming that a programming style that overuses anonymous functions as parameters into other functions leads to unreadable and overcomplicated code... hence why python restricts anonymous functions from being over one line long. Typically in program…
In my experience (I write mostly JS but also a lot of C# and, not as much, Rust), passing functions around is very easy to read and reason about. Functional programming "Just Makes Sense™" to me. I think it's just an exposure thing. Many people find Python's significant whitespace cleaner. I disagree but I promise you it's because I haven't spend much time with it. If I wrote a lot more Python, I'd probably grow to like it.