Live data from Hacker News

Leaving Python for JavaScript

hire.jonasgalvez.com.br

11–20 of 112 posts

Re: Leaving Python for JavaScript

#12
post #9
post #2

> there's no acceptable way to pass a function body to another in Python. What. Why would you ever want a function body as a string? What kind of vile sorcery are you doing? One can use inspect.getsourcelines in python if really pressed to, but I find it horrifying that javascript developers actually seem to require this functionality often.

The author did not say "as a string" and I am extremly confused as to how you read it like that... what? Essentially, 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 (and you are horribly tempted to play extremely insane tricks with decorators to build something that…

Well truth be told it was hard for me to understand what the author meant. Thanks for clarification.

Re: Leaving Python for JavaScript

#13
post #9
post #2

> there's no acceptable way to pass a function body to another in Python. What. Why would you ever want a function body as a string? What kind of vile sorcery are you doing? One can use inspect.getsourcelines in python if really pressed to, but I find it horrifying that javascript developers actually seem to require this functionality often.

The author did not say "as a string" and I am extremly confused as to how you read it like that... what? Essentially, 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 (and you are horribly tempted to play extremely insane tricks with decorators to build something that…

[deleted]

Re: Leaving Python for JavaScript

#14
post #2

> there's no acceptable way to pass a function body to another in Python. What. Why would you ever want a function body as a string? What kind of vile sorcery are you doing? One can use inspect.getsourcelines in python if really pressed to, but I find it horrifying that javascript developers actually seem to require this functionality often.

Higher order functions maybe? Though python has them. Spread operator can be done as unpacking a list. Destructuring assignment can also be done. Map is already there while reduce is in functools stdlib. So are all the other functional stuff. Async is in python 3.

Can't say what python lacked except being able use same language on front end and back end. Except if he still uses python 2 which hasn't any new features in years.

Re: Leaving Python for JavaScript

#15
I started programming in JS then moved to Python. It seems like JS has become very, very complicated. I look at his post and I am lost... I remember Knockout.js and Node in the v0.8 days.

I mean look at this:

  dotenv (lets you load the environment from an .env file), axios 
  (HTTP client library), cheerio (HTML parsing library), bcrypt 
  (password hashing), co-body (HTTP body parser), co-busboy (HTTP 
  multipart parser), jsonwebtoken (JWT generator), koa-jwt (JWT 
  middleware), koa-router, koa-sslify, vue-no-ssr and source-map.
What the hell is all that? I am not saying he is wrong... I am just saying that I don't have the capacity to play in that playground. I am also asking if any of those libraries will be around in a year?

Re: Leaving Python for JavaScript

#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 different thing with Y.

In the specific "passing a function" case, yes, it's impossible to pass only a function body, but I think it's impossible to do in JavaScript also? (correct me if I'm wrong), because you pass in function. You can do the same in Python by defining a function in the same scope and passing that in. If you don't like that, it's just one opinion, not necessarily good or bad. For example, I find it ugly and difficult to handle nesting this multiple times (defining another anonymous function inside an anonymous function) which is called "callback hell" if I understand right, but that's just my opinion also, because people seem to able to accept this hell. :)

Re: Leaving Python for JavaScript

#19
I did the move but to GOLANG instead.

I think what is more important than the language it self, is the toolings and standard library.

every now and then you hear about a new framework, a lot of hype, which is not for big projects.

I think the wise thing is to move to golang

Re: Leaving Python for JavaScript

#20
post #9
post #2

> there's no acceptable way to pass a function body to another in Python. What. Why would you ever want a function body as a string? What kind of vile sorcery are you doing? One can use inspect.getsourcelines in python if really pressed to, but I find it horrifying that javascript developers actually seem to require this functionality often.

The author did not say "as a string" and I am extremly confused as to how you read it like that... what? Essentially, 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 (and you are horribly tempted to play extremely insane tricks with decorators to build something that…

> 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) if is_even(x))
Both result in the same lazy iteration (to see results below - requires materialization with a constructor like list or tuple), but I find the "fragmented" approach much more readable (so long as the functions do what their name says they do - I have seen Python where they actually did the opposite...)

    >>> list((square(x) for x in range(11) if is_even(x)))
    [0, 4, 16, 36, 64, 100]
    >>> list(map(lambda x: x**2, filter(lambda x: not x % 2, range(11))))
    [0, 4, 16, 36, 64, 100]
Post reply on HN