Live data from Hacker News

Leaving Python for JavaScript

hire.jonasgalvez.com.br

71–80 of 112 posts

Re: Leaving Python for JavaScript

#71
post #47

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…

Long method chains are impractical in Python because of the line continuation rules. That's orthogonal to the question of whether complex functions should be required to have names.

Re: Leaving Python for JavaScript

#72
post #18

> 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)

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 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

#73
post #48

Why 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).

I don't think it's broken. It just looks pretty cramped and weird if you've got your browser in a portrait orientation.

Re: Leaving Python for JavaScript

#74
post #21

Earlier 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…

If you're building in cement, you need to know the cement is strong enough. If you're building in tofu, choosing extra firm over silken isn't really going to help.

Re: Leaving Python for JavaScript

#75
post #3

Poor misguided person

I use to read hacker news and feel that all the articles were by people infinitely smarter than me. Nowadays I occasionally hit something like this. The fact that this makes it to the front page means many programmers are equally misguided...

Re: Leaving Python for JavaScript

#76

So 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…

Right? When I read these kind of posts I always imagine a carpenter saying the equivalent "After over 10 years using a hammer as my main tool, I have moved on to the screwdriver." Which is nonsense.

Re: Leaving Python for JavaScript

#77
post #18

> 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…

I think he's complaining about the fact that lambdas in Python can't be multiline. The equivalent in Javascript can be as big as you want. That means in Python you have to separately define your function and then refer to it, whereas in JS you can just give it all in one go.

JS:

  doThing(function(){
    blah();
    de();
    blah();
  });
Python:

  def thing_doer():
    blah()
    de()
    blah()

  doThing(thing_doer)

Re: Leaving Python for JavaScript

#78
With async/await now landing in mainstream engines, Koa instead of Express, the new Turbofan+Ignition optimization pipeline "evening out" V8's performance characteristics, and ES6 enjoying reasonably broad support, I feel like JS is now crossing a threshold into being not a completely sucky programming experience, which is a sentiment this article echoes.

I'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

#79
post #32

Earlier 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.

yes, but we were talking about passing an anonymous function as an argument and that was the example used.

Re: Leaving Python for JavaScript

#80

Earlier 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…

I'd say that anyone who's complaining about callback hell isn't up-to-date with the JS world. Promises have fixed this problem and, as you pointed out, async/await make it even nicer.

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.

Post reply on HN