this post was submitted on 02 Nov 2024
270 points (98.2% liked)

Python

6684 readers
42 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS
(page 2) 38 comments
sorted by: hot top controversial new old
[โ€“] [email protected] 5 points 3 months ago (5 children)

Every time I open a js file from some project I have to tweak to use on my website, I get a brain aneurysm. that shit should never have been invented. python in the browser is the dream we are not allowed to have.

ps: I am just a hobbyist ! so take it lightly.

[โ€“] [email protected] 7 points 3 months ago (2 children)

Somebody should write a python to javascript transpiler for the web...

(please don't actually do that)

[โ€“] [email protected] 12 points 3 months ago (4 children)

There's a Python WASM runtime, if you really want to run python in a browser for some reason...

https://github.com/wasmerio/wasmer-python

load more comments (4 replies)
load more comments (1 replies)
load more comments (4 replies)
[โ€“] [email protected] 1 points 3 months ago

This plus Mojo has me feeling better about just wanting to stick to python. I gotta dable in go and rust because not everything is my project (thank God), but I can't wait till performance python syntax is the norm

[โ€“] [email protected] 66 points 3 months ago (1 children)

Ok after reading the article this is bullshit. It's only because they are counting JavaScript and Typescript separately.

[โ€“] [email protected] 22 points 3 months ago (3 children)

Typescript being that popular is great news onto itself.

load more comments (3 replies)
[โ€“] [email protected] 7 points 3 months ago

Yeah I really would love to use Python instead on JavaScript natively for the same use case.

[โ€“] [email protected] 4 points 3 months ago

Yeesh on both counts.

[โ€“] [email protected] 16 points 3 months ago* (last edited 3 months ago)

Also some projects are using web assembly to make frontend python frameworks such as this one https://github.com/kkinder/puepy

Edit: wrong project

[โ€“] [email protected] 12 points 3 months ago (1 children)
[โ€“] [email protected] 25 points 3 months ago* (last edited 3 months ago) (4 children)

Thank god, Javascript is a mess.

Iโ€™ll still plug Scala for having the beauty of Python, the ecosystem of Java, the correctness of Rust, the concurrency of Go, and the power of Lisp.

[โ€“] [email protected] 4 points 3 months ago (3 children)

Typescript is far nicer than Python though. Well I will give Python one point: arbitrary precision integers was absolutely the right decision. Dealing with u64s in Typescript is a right pain.

But apart from that it's difficult to see a single point on which Python is clearly better than Typescript:

  • Static typing. Pyright is great but it's entirely optional and rarely used. Typescript obviously wins here.
  • Tooling. Deno is fantastic but even if we regress to Node/NPM it's still a million miles better than the absolute dog shit pile of vomit that is Pip & venv. Sorry Python but admit your flaws. uv is a shining beacon of light here but I have little hope that the upstream Python devs will recognise that they need to immediately ditch pip in favour of officially endorsing uv. No. They'll keep it on the sidelines until the uv devs run out of hope and money and give up.
  • Performance. Well I don't need to say more.
  • Language sanity. They're pretty on par here I think - both so-so. JavaScript has big warts (the whole prototype system was clearly a dumb idea) but you can easily avoid them, especially with ESLint. But Python has equally but warts that Pylint will tell you about, e.g. having to tediously specify the encoding for every file access.
  • Libraries & ecosystem. Again I would say there's no much in it. You'd obviously be insane to use Python for anything web related (unless it's for Django which is admittedly decent). On the other hand Python clearly dominates in AI, at least if you don't care about actually deploying anything.
[โ€“] [email protected] 3 points 3 months ago* (last edited 3 months ago) (6 children)

What is so bad about virtual environments? I found them to be really nice and useful when I developed in Python over about 5-ish years. It was really nice being able to have separate clean environments for installing libraries and executing things.

Granted, I only used Python as a solo developer, so if there are shortcomings that emerge when working with other developers, then I would not be aware of them....

Edit: also, performance is a bit more of a subtle topic. For numerical logic, Python actually is (probably) much better than a lot of its competitors thanks to numpy and numexpr. For conditional logic, I would agree that it's not the best, but when you consider developer velocity, it's a clearly worthwhile tradeoff since frameworks like Django are so popular.

load more comments (6 replies)
[โ€“] [email protected] 7 points 3 months ago (1 children)

Language sanity. Theyโ€™re pretty on par here I think

[1] + [2]
"12"

A sane language, you say.

const foo = 'hello' 
const bar = { foo: 'world'}
console.log(bar)
// { "foo": "world" }

the absolute dog shit pile of vomit that is Pip & venv

I've worked professionally in python for several years and I don't think it's ever caused a serious problem. Everything's in docker so you don't even use venv.

[โ€“] [email protected] 6 points 3 months ago (1 children)

A sane language, you say.

Yes:

Operator '+' cannot be applied to types 'number[]' and 'number[]'.

We're talking about Typescript here. Also I did say that it has some big warts, but you can mostly avoid them with ESLint (and Typescript of course).

Let's not pretend Python doesn't have similar warts:

>>> x = -5
>>> y = -5
>>> x is y
True
>>> x = -6
>>> y = -6
>>> x is y
False
>>> x = -6; y = -6; x is y
True
>>> isinstance(False, int)
True
>>> [f() for f in [lambda: i for i in range(10)]]
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9]

There's a whole very long list here. Don't get be wrong, Python does a decent job of not being crazy. But so does Typescript+ESLint.

Iโ€™ve worked professionally in python for several years and I donโ€™t think itโ€™s ever caused a serious problem. Everythingโ€™s in docker so you donโ€™t even use venv.

"It's so bad I have resorted to using Docker whenever I use Python."

[โ€“] [email protected] 3 points 3 months ago (1 children)

Why would you use the is operator like that?

The lambda thing is from late binding, which I've had come up at work once. https://docs.python-guide.org/writing/gotchas/#late-binding-closures.

โ€œItโ€™s so bad I have resorted to using Docker whenever I use Python.โ€

Do you not use containers when you deploy ? Everywhere I've worked in the past like 10 years has moved to containers.

Also this is the same energy as "JavaScript is so bad you've resorted to using a whole other language: Typescript"

To your point, typescript does solve a lot of problems. But the language it's built on top of it is extremely warty. Maybe we agree on that.

[โ€“] [email protected] 2 points 3 months ago (2 children)

Why would you use the is operator like that?

Why would you add two arrays like that?

Do you not use containers when you deploy

No because I am not using Python to make a web app. That's not the only thing people write you know...

JavaScript is so bad youโ€™ve resorted to using a whole other language: Typescript

Well yeah. Typescript isn't really a new language. It's just type annotations for JavaScript (except for enums; long story). But yes JavaScript is pretty bad without Typescript.

But Typescript isn't a cop-out like Docker is.

But the language itโ€™s built on top of it is extremely warty. Maybe we agree on that.

Yeah definitely. You need to ban the warts but Typescript & ESLint do a pretty good job of that.

I mean I would still much rather write Dart or Rust but if I had to pick between Typescript and Python there's absolutely no way I'd pick Python (unless it was for AI).

load more comments (2 replies)
[โ€“] [email protected] 7 points 3 months ago* (last edited 3 months ago)

I write mostly Python for 5 years and uv is indeed the best thing that happened to the Python landscape during this period.

I disagree that typescript is far nicer; even syntax-wise, type annotated Python seems much easier to read, write, and refactor; but I'll give that Python needs to ditch pip and "requirements.txt" for good.

[โ€“] [email protected] 1 points 3 months ago (1 children)

The only problem is that it also has the complexity of C++.

[โ€“] [email protected] 4 points 3 months ago* (last edited 3 months ago) (1 children)

Not the foot-shooting complexity though, just the extra-power complexity

[โ€“] [email protected] 1 points 3 months ago

You can enable the foot-shooting complexity by writing modules for Python in C++, since it's very easy to do. Why do I know this? Well...

[โ€“] [email protected] 2 points 3 months ago* (last edited 3 months ago)

Scala does look nice. Just a quick syntax view makes me want to give it a whirl when I want an alternative to Python. I used to code in C++, and C#. I use G'MIC (DSL) as my main. Scala seems right up my alley.

[โ€“] [email protected] 65 points 3 months ago (9 children)

I code both typescript and python professionally, and python is almost as much of a mess, just a different kind of mess. The package manager ecosystem is all over the place, nobody is agreeing on a build system, and the type system is still unable to represent fairly simple concepts when it comes to function typing. Also tons of libraries just ignore types altogether. I love it, but as a competitor to JavaScript in the messiness department it's not a good horse.

[โ€“] [email protected] 2 points 3 months ago (1 children)

the type system is still unable to represent fairly simple concepts when it comes to function typing

what do you mean by this?

[โ€“] [email protected] 1 points 3 months ago (3 children)

My biggest pet peeve is the complete inability to annotate a set of known exceptions that a function raises in a machine readable way. The discussion about it is quite heated.

[โ€“] [email protected] 4 points 3 months ago

In fairness that approach hasn't really worked in other languages. It was so unpopular in C++ that they actually removed the feature, which is almost unheard of. Java supports it too but it's pretty rarely used in my experience. The only place I've seen it used is in Android. It's unpopular enough there that Kotlin doesn't support it.

load more comments (2 replies)
[โ€“] [email protected] 3 points 3 months ago (2 children)

types are always ignored at runtime, they're only useful when developing

[โ€“] [email protected] 6 points 3 months ago (2 children)

Yeah, they're useful when developing, which is why it's so frustrating when libraries don't implement types. I'm developing and I'm trying to use a tool that supposedly fits a use case I have, but the tool didn't come with instructions so it's practically useless to me. I could open the tool up and look at its guts to figure it out but are you kidding me no, I'm not going back to the stone age for your tool.

load more comments (2 replies)
load more comments (1 replies)
[โ€“] [email protected] 15 points 3 months ago* (last edited 3 months ago) (1 children)

They ignore types all together because typing is optional in python.

[โ€“] [email protected] 13 points 3 months ago (1 children)

All documentation is optional and ignored at runtime, that doesn't mean you shouldn't do it. If your library doesn't have type hints I'm just not gonna use it, I don't have the time to figure out what you accept or return.

[โ€“] [email protected] -2 points 3 months ago (1 children)

It means they have the option to do it or not do it and you have the option to not use it, which clearly your exercising. I've personally never had a situation where a lack of type hints slowed me down even a little.

[โ€“] [email protected] 6 points 3 months ago (1 children)

I dunno if you're being deliberately obtuse, but just in case you really did miss his point: the fact that type hints are optional (and not especially popular) means many libraries don't have them. It's much more painful to use a library without type hints because you lose all of their many benefits.

This obviously isn't a problem in languages that require static types (Go, Rust, Java, etc..) and it isn't a problem with Typescript because static types are far more popular in JavaScript/Typescript land so it's fairly rare to run into a library that doesn't have them.

And yeah you can just not use the library at all but that's just ignoring the problem.

[โ€“] [email protected] 1 points 3 months ago (1 children)

True, but if you're looking at a Python library that doesn't have type hints in 2024, then chances are that it's not very good and/or not very well maintained.

[โ€“] [email protected] 1 points 3 months ago

Well, indeed. Unfortunately there are still a fair number of them. The situation is definitely improving at least.

load more comments (5 replies)
load more comments
view more: โ€น prev next โ€บ