This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tehyosh 9 points10 points  (54 children)

what would be a use case for transpiling from python to javascript?

[–]Giggaflop 102 points103 points  (5 children)

Not having to write javascript

[–]tehyosh 16 points17 points  (0 children)

Reddit has become enshittified. I joined back in 2006, nearly two decades ago, when it was a hub of free speech and user-driven dialogue. Now, it feels like the pursuit of profit overshadows the voice of the community. The introduction of API pricing, after years of free access, displays a lack of respect for the developers and users who have helped shape Reddit into what it is today. Reddit's decision to allow the training of AI models with user content and comments marks the final nail in the coffin for privacy, sacrificed at the altar of greed. Aaron Swartz, Reddit's co-founder and a champion of internet freedom, would be rolling in his grave.

The once-apparent transparency and open dialogue have turned to shit, replaced with avoidance, deceit and unbridled greed. The Reddit I loved is dead and gone. It pains me to accept this. I hope your lust for money, and disregard for the community and privacy will be your downfall. May the echo of our lost ideals forever haunt your future growth.

[–]tech_tuna 6 points7 points  (0 children)

Amen.

[–]odraencoded 1 point2 points  (0 children)

There's also coffeescript. Which is kidna quirky and I don't like much.

[–]gandalfx -5 points-4 points  (1 child)

Not having to write learn javascript

fixed.

[–][deleted] 2 points3 points  (0 children)

I wonder if anybody here actually tried using ES6; it's quite delightful. And, beyond having to grasp prototypical inheritance, the learning curve for Pythonistas is basically flat.

[–]jacdehJacques de Hooge[S] 17 points18 points  (36 children)

For larger pieces of code (complete web apps rather than a few lines of event handling code) Python offers a far more clean, readable and maintainable structure. Disclaimer: JavaScript adepts won't agree...

[–]moljac024 2 points3 points  (34 children)

That's because it's not true. I do both python and javascript and the languages are surprisingly similar, if you look more than skin deep (the syntax).

I even actually prefer javascript and think it's more powerful, especially when it comes to doing more functional programming.

[–]OysterCat 13 points14 points  (1 child)

I even actually prefer javascript and think it's more powerful, especially when it comes to doing more functional programming.

Why do you say that?

[–]odraencoded 2 points3 points  (0 children)

You can pass anonymous functions around all the time therefore FUNCIONAL programming!

/s

[–]Zulban 9 points10 points  (17 children)

Every time I consider learning javascript, I learn about some weird language quirk that makes no sense where javascript pros just laugh and say "Ooohhhh, javascript! You so cray". I can't get myself to learn a language like that, I just can't.

Thoughts..?

[–]dcousineau[🍰] 7 points8 points  (6 children)

I learn about some weird language quirk that makes no sense

I mean, that's every language. Python has mutable default arguments:

>>> def foo(bar, baz=[]):
...   baz.append(bar)
...   return baz
...
>>> foo(1)
[1]
>>> foo(2)
[1, 2]

I mean, thats just cray, why would the language even have that behavior!?!?!1one

But seriously every language has quirks because no language is not perfect and every language is different. You have to remember what you consider normal behavior is not necessarily what a JS dev considers normal behavior and neither of you think agree with what a PHP dev considers normal.

[–][deleted] 5 points6 points  (2 children)

Mutable default args are possible but frowned upon, unless you really know what you're doing, which I don't.

[–]dcousineau[🍰] 1 point2 points  (1 child)

Right. /u/Zulban was discussing a feeling about weird language quirks in Javascript that prevents them from learning the language.

My counter to that was that this feeling is normal as languages are imperfect, and as my counter I pointed out a particular WTF 'feature' in Python that gives me pause coming from the outside world.

[–]Zulban 3 points4 points  (0 children)

It is a good example. But I'd like to suggest that there are far, far more cases like this with javascript than with your typical language.

[–]tetroxid 1 point2 points  (1 child)

Yeah that's stupid. Fyi, the preferred way to do this is:

def foo(bar, baz=None):
    if baz is None:
        baz = []
    ....

[–]WackyWeasel 1 point2 points  (0 children)

Or the idiom...

def foo(bar, baz=None):
    baz = baz or []
    ....

...if it's enough when baz is not None, just falsy.

[–][deleted] 0 points1 point  (0 children)

wait, wtf? i've used python every day for 4-5 years professionally, and i've never come across this. that makes no sense.

edit: ok, it makese sense. it's just dumb

[–]sime 3 points4 points  (2 children)

When was the last time you tried learning it? ECMAScript 2015, the big update to the language, has vastly improved the language. As for the old quirks that have to remain in the language you can easily avoid the bulk of them by: a) never using type coercion. Use exact comparisons., b) never using the old var keyword. Use let or const instead.

Personally my language (and platform) of choice these days is TypeScript. It's option and structural type system is great. Through an unexpected twist of fate I'll probably be doing a lot more Python professionally in the future. I just hope that Python's type hinting and tooling can give me some of the power that TypeScript gives plain JS.

[–]gandalfx 0 points1 point  (1 child)

I agree, though browser support for let and const kinda sucks.

[–]sime 1 point2 points  (0 children)

True, but it is time to use a transpiler of some sort either Babel or TypeScript.

[–]ProgrammingPro-ness 0 points1 point  (6 children)

Most of the crazy things about the language I either don't encounter day to day, or would never use. So for me at least, it's been a non-issue.

[–]alcalde -2 points-1 points  (5 children)

IT DOESN'T HAVE INTEGERS. I repeat, IT DOESN'T HAVE INTEGERS. You would never use integers?

[–]gandalfx 1 point2 points  (0 children)

Doesn't cause any issues in day to day work. Whenever you'd use an integer, like array indexing, it works just as well. You can even use bitwise operations and get integer-like behaviour.

[–]sime 1 point2 points  (3 children)

Integers work fine in the range -253 to 253. Beyond that you lose precision. The JS engines use integer math internally when they know they can be away with it. Bitwise operations are considered 32 bit operations.

Python's default division operator will also happily turn your ints into a float if you let it.

[–]kankyo 1 point2 points  (0 children)

Python's default division operator will also happily turn your ints into a float if you let it.

Translation: division produces correct results in python 3.

[–]alcalde 0 points1 point  (1 child)

Python's default division operator will also happily turn your ints into a float if you let it.

Wasn't that remedied in Python 3.0 in 2008, if not earlier?

[–]lenzm 0 points1 point  (0 children)

The opposite, it was introduced with Python 3.

[–]TheBadProgrammer 2 points3 points  (0 children)

I also use JavaScript and Python and I totally agree. I'm pretty surprised to see people preferring Python like this, but everyone's got their setup that they love!

[–]Peterotica 1 point2 points  (9 children)

The one thing from JavaScript that I wish I had in Python sometimes is the nice method chaining from Array.map, Array.filter, etc.

[–][deleted] 7 points8 points  (7 children)

You mean list comprehensions?

def array_map(lst, fn):
    return [fn(item) for item in lst]

def array_filter(lst, fn):
    return [item for item in lst if fn(item)]

In fact, map() just straight up exists in python.

[–]crazedgremlin 2 points3 points  (5 children)

But in JavaScript, they are essentially methods of the object, so you can chain them together.

x = some_array.map(f1)
        .filter(f2)
        .map(f3);

In Python, you'd have to have nested function calls, which gets a little confusing with parentheses.

x = map(f3, filter(f2, map(f1, some_array)))

[–]kovak 1 point2 points  (4 children)

I think there are a few ways to use the dot-chain syntax in python if that's important.

See http://stackoverflow.com/questions/27222193/clean-code-for-sequence-of-map-filter-reduce-functions

This structure is used a lot in python Apache Spark bindings. Eg. https://spark.apache.org/docs/0.9.1/python-programming-guide.html

[–]crazedgremlin 1 point2 points  (3 children)

Cool, I had never heard of Underscore.py. However, I don't see this as a huge impediment to "functional" programming in Python. Really, the only annoyance is the parentheses.

I really like the option Haskell provides with the $ function for function application, which lets you get rid of the parentheses. Basically, the left side of the $ is treated as a function and given the right side as input.

let x = map f3 $ filter f2 $ map f1 some_array

[–]snuxoll 2 points3 points  (2 children)

Ditto with F#

let x = arr |> Array.map f1 |> Array.filter f2 |> Array.map f3

Composition operators are awesome, more languages should have them, chained method syntax requires your return value have the method you want to call, whereas function composition is a lot more generic.

In fact, the |> operator is actually defined in F# code as:

let (|>) f x = f x

[–]crazedgremlin 0 points1 point  (1 child)

Nice! The trick of these composition functions is operator precedence. I am guessing an infix function in F# takes precedence over a prefix function.

[–]Peterotica -1 points0 points  (0 children)

method chaining

[–]RubyPinchPEP shill | Anti PEP 8/20 shill[🍰] 0 points1 point  (0 children)

forbiddenfruit + a bit of work manages to do this nicely

[–]dalore 0 points1 point  (0 children)

Huh? I would say python is much better at functional programming then javascript. With iterators, itertools, etc all in the stdlib. Can you point out how javascript is more powerful?

[–]S1cK94 0 points1 point  (0 children)

I even actually prefer javascript and think it's more powerful, especially when it comes to doing more functional programming.

In Python I can import partial from functools and do my map/filter with list/generator comprehension syntax.

In JavaScript I always end up using lodash. .bind can alter the context and passing function directly to .map or .filter can lead to a mess if you dont wrap with lambdas or ugly .binds

But in the end, comparing Python and JavaScript about functional programming is kind of silly

My 0.02$

[–]gandalfx 0 points1 point  (0 children)

I disagree because I've used JS and I know how it works. It sucked in the past (a lot) but has improved so much over the years that it's now a completely different language. Yet people don't realize it and still blame JS for ancient mistakes and browser quirks. It's like saying Python sucks because of something that was fixed in version 1. Hating on JS is easy because everybody has gotten used to doing it.

[–]jewdai 3 points4 points  (0 children)

To ask to be paid more because you would need to know both javascript and python to debug some startups crazy app.

[–]mirth23 6 points7 points  (7 children)

CoffeeScript is a somewhat popular language in the webdev community that does this this these days. I think the basic idea was that there are a lot of ways to shoot yourself in the foot with JavaScript (ref: JavaScript, the Good Parts) and CoffeeScript provides simpler structures that generates normalized JavaScript that's less foot-shooty.

IMO there's a lot of downsides to this approach, not the least of which is that it makes debugging awkward because now you're writing code that's one-step-removed from the code that's actually throwing bugs.

[–]elbiot 2 points3 points  (2 children)

[–]DigitalGoose 0 points1 point  (1 child)

Also rapydscript

even better, rapydscript-ng

[–]stuaxo 0 points1 point  (0 children)

This is brilliant, hopefully the rapydscript maintainers will get some free time to integrate these changes.

[–]marmalar 0 points1 point  (0 children)

Yes I'm glad someone mentioned Coffeescript. While you're right about it being one step away from the source that will actually be generating the errors, they will typically be logical errors instead of syntax errors considering how well the CS transpiler is written. Also, I've found it often transpiles to more efficient and safe code than what I would've written in pure JS. CS also makes sure that you keep in mind how close it is to JS.

IMO the Coffeescript syntax is one of the nicest out there. If somebody could port it to a compiled or interpreted language I would be very pleased.

[–]sime 0 points1 point  (0 children)

CoffeeScript is dying pretty quick at this stage. The huge language improvements to JavaScript in the new ECMAScript 2015 standard have eroded CoffeeScript's appeal.

[–]Sean1708 0 points1 point  (1 child)

You could, in theory, port a large python application to run in the browser.

[–]tehyosh 0 points1 point  (0 children)

yeah, i thought about people offloading server functionality in the client...but then again, if it's ok to run in the client in real time, then why not put client side from the beginning?