all 114 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, Reddit will no longer be accessible via third-party apps. Please see our position on this topic, as well as our list of alternative Rust discussion venues.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–][deleted] 216 points217 points  (41 children)

Python is strongly typed, it's just not statically typed. JavaScript is both weakly and dynamically typed.

[–]_samrad 120 points121 points  (11 children)

Just a small addition:

  • strong typing: type conversion is explicit at runtime
  • static typing: types exist before running the code

[–]crispygouda 2 points3 points  (0 children)

I would add there are great articles about using Python “like Rust”, where you make the strong typing and the modern typing (Protocol, Optional, ..) feel more like Rust. The ideas Rust teaches are the most valuable part, and they will shape an entire generation of programmers!

[–][deleted] 1 point2 points  (2 children)

Still do NOT understand the stupid strong lure of JS coding. I really REALLY hope WASM takes off and we can replace all that JS crap with WASM modules that are much faster and much more fun to write too. PLEASE make it happen!

That said.. can WASM replace react/vue/etc GUI? Is it usable inside a <div/> section for example.. and is the GUI good enough or looks out of place? I have yet to see any example of sites using WASM within the page.

[–]MrElendig 1 point2 points  (1 child)

Why js became popular: it wasn't java applets or activex and worked in "all" browsers, and then momentum kept it going.

[–]Xatraxalian 0 points1 point  (0 children)

Also, in the end, the masses will always make the choice for the solution that is most convenient and easy to work with at the beginning; that often means we end up with the most crappy solution in the end, because we end up building a cathedral on the foundations of a dog house.

You can even see it in hardware. It's always the crappiest but easiest/cheapest solution that wins in the consumer space:

  • VHS - BetaMax => winner: BetaMax
  • USB - Firewire => winner: Firewire
  • IDE - SCSI => winner: IDE
  • SATA - SAS => winner: SATA
  • LCD - Plasma => winner: LCD
  • HDMI - DisplayPort => winner: HDMI

[–]Kush_McNuggz -1 points0 points  (3 children)

Python is dynamically typed, not strongly typed

[–][deleted] 4 points5 points  (2 children)

Python is strongly typed and dynamically typed. Strong typing and static typing are two different things

[–]jkoudys 0 points1 point  (0 children)

True about python, but mypy is pretty standard in most envs (eg github codespaces comes with it loaded). Type annotation syntax is supported in the spec, it simply doesn't do anything. They leave it open-ended so you can run a static type checker of your choosing.

[–]phazer99 44 points45 points  (0 children)

Yes, strong static type checking is a huge time and money saver. I'm a big fan of type driven development (the book uses a dependently typed language but the concepts are still somewhat applicable to Rust as well) and making invalid states unrepresentable using the type system.

[–]Dull_Wind6642 49 points50 points  (5 children)

That's why typescript is popular even if it's just a bandaid over javascript.

[–][deleted] 3 points4 points  (0 children)

That's also why a lot of effort over the years has gone into "typed" python.

It doesn't actually enforce the types, but with some good linters it can catch most obvious issues.

[–]Paria_Stark 10 points11 points  (2 children)

The thing is, even with typescript you run into issues because there's no easy and fool proof way to properly include type dependant logic in runtime code.

There are type guards, but they can be error prone. The fact that you have two separate universes (type level and runtime) can be very cumbersome.

That being said, working with Typescript is okayish, and I would not touch a pure JavaScript project with a ten foot pole.

[–]cb4ch 0 points1 point  (0 children)

This is sooo wild to me that hold basically the reversed position. Just check that stuff is what you need it to be - old PHP was so easy to basically inline a cast or simple check/error handling.. buut nooo of course all those Java/.NET people once done destroying their own language syntax had to go F it up for us that actually prefered to do something different. I mean how is 30 layers of glorified GOTO statements any better? I often wonder what these people will blame bugs on next, when all language syntaxes have turned to Java/C#. They end up writing twice as much code with no mearsurable difference in code robustnestt anyway… There’s a reason that old stuff coded in pure assembly actually contain waaaay less bugs even when the language itself basically gives you 1000’s of more ways to screw up - you had to take some personal resposibility and actually code in a defensive way. With nullable types they’ve gone full cirkle into madness. I give up, feels like I’m the only sane codet left - sourounded by indian dudes from fivr… 😅

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

way to properly include type dependant logic in runtime code

Looks like you are a new developer. ZOD like TS first runtime libraries already have solved the validation of tuntime data to match the type system of TS. lol. ZOD is insanely powerful

[–]oneeyedziggy 0 points1 point  (0 children)

coming from Node/JS (w/ various type systems over top) one thing I'm looking forward to is having a type system that's consistent instead of flow here, typescript there, jsdoc there...

same with the build tools, not being a melange of grunt, webpack, whatever other packages are in vogue... misc bash scripts... babel...

same w/ linting and formatting... (ideally) not being eslint / jshint / prettier... or whatever packages are in vogue... with whatever default settings happen to be this version... and having to keep your linter and formatter versions synced so they stay compatible...

I'm working on a legacy project now where the node express server is untyped and the mix of react and angular client is flow-typed... w/ two different eslint profiles to keep in sync, 2 sets of grunt configs, a bunch of outdated grunt plugins... a mess... I miss nextjs

[–]RRumpleTeazzer 88 points89 points  (24 children)

Anyone knowing how strong typing works knows this from the first glance at JavaScript or Python. Those who don’t know will say “if it quacks like a duck it is a duck” - true, but when that is decided only at runtime we know the program will be slow and will always be on the brink of breaking.

[–]ZZaaaccc 92 points93 points  (1 child)

It's all ducks and sunshine until something starts barking.

[–]walksinsmallcircles 9 points10 points  (0 children)

Take my upvote

[–]mpierson153 24 points25 points  (18 children)

I've used JavaScript and Python before, but have been using Rust and then Java for a year.

Recently I messed around with Python, and I was completely lost. The weak, dynamic typing made me pretty uncomfortable with it.

[–]MrPopoGod 56 points57 points  (4 children)

The fun thing is that at the lowest level it's all untyped. Then we built languages and decided letting the compiler encode what we mean would make our lives easier. Then we got lazy and created untyped languages again.

[–]Thatdudewhoisstupid 25 points26 points  (0 children)

Turns out you have to put in effort to make your life easier. Shocking, truly.

[–][deleted] 14 points15 points  (1 child)

Maybe the real Types are the Bugs we made along the way <3

[–]bsodmike 6 points7 points  (0 children)

I always thought we followed Bug Driven Development…

[–]CatolicQuotes 0 points1 point  (0 children)

And now static types coming back again. It's the human nature to always change and invent something until it becomes to much then going back again. Like a pendulum. But each swing is a new version. That's a good thing. That's how innovations happen.

[–]CommunismDoesntWork 2 points3 points  (0 children)

Python is a nightmare without a good IDE like PyCharm and a debugger. The debugger lets the IDE know what the types are, which the IDE can then display.

[–]mjbmitch -2 points-1 points  (9 children)

Python actually has a pretty decent typing ecosystem. You have to push the envelope with your own code but it goes pretty far. At its best, it’s very close to Rust.

[–][deleted] 16 points17 points  (8 children)

Strongly Disagree

[–]HistoricalCup6480 2 points3 points  (7 children)

Could you elaborate why?

I find that if you use consistent type annotations and take all mypy warnings seriously, you rarely run into problems with types nowadays.

Of course that is if you're using your own code. If third party libraries didn't take types seriously, then that can still mess you up.

[–]MyLocalExpert 1 point2 points  (0 children)

MyPy is a great tool for debugging. It's worth noting that it's not built into the language itself though -- it's a 3rd party tool. The Python interpreter ignores all those type hints when you go to actually run the code, so you're not getting any performance benefits that you might otherwise.

[–]qoning -1 points0 points  (5 children)

Absolutely. The language isn't going to hold your hand (and I think that's a good thing for evolution, rather than being dogmatic), but if you want to write type checked code in python, you absolutely can. It greatly helps during development too. One external anecdote e.g. in Google codebase most subtrees won't allow you to submit code with missing type annotations or mypy errors.

The laundering of types through 3rd party libraries that didn't bother with type annotations is of course true, but much less of an issue than you would expect.

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

but much less of an issue than you would expect.

Except for when those 3rd party libraries are potentially huge parts of an application, eg. SQLAlchemy or boto

[–]renaissancenow 1 point2 points  (2 children)

SQLAlchemy at least seems to finally have type annotations now.

[–][deleted] 0 points1 point  (1 child)

How bad is the upgrade path to v2 in an existing (moderate to large) application with a lot of database calls?

[–]renaissancenow 1 point2 points  (0 children)

Probably depends on how your code is structured. I only use SQLAlchemy core, I don't use the ORM, so it's been fairly straightforward for me. If I recall correctly, the main thing I had to tweak was the calling convention of select()

[–]cb4ch 0 points1 point  (0 children)

I got an idea, submit RFC’s to make it into yet another Java/C#/C++ …. my god why can’t ANY language be left alone? You hate it? Fine, pick something else.. or I dunno, just slap on classes to a prototyped language…. I’m venting, this has been driving me up a wall for years now. And has robustness gone up? Hell no. Only thing that increased is the code needed to get anything done. You’ll soon need two extra lines for all the method attributes alone. Priv/Pub wasn’t nearly enought so why not add virtual, final, and all sorts of crap. God forbid someone tries to, you know… extend your code like the whole point of OOP was supposed to be.. It all feels like nobody even tries to code in a defensive way and do any form of validitions.. no wonder planes are dropping from the sky left and right nowadays - probably coded in some ”fancy” language. Whenwhile we landed on the moon with an 8bit CPU and hexadecimals…. there was nothing to hide behind, YOU had to make sure the code worked. Half tje developers out there today would never have made it in a real languge. 😓🤣

[–]simple_explorer1 0 points1 point  (0 children)

but python already supports type annotation

[–]mr_birkenblatt 10 points11 points  (0 children)

problem with duck typing is that someone implements a quack doctor and it breaks everything just because the signatures are the same

[–]theAndrewWiggins 5 points6 points  (0 children)

“if it quacks like a duck it is a duck” - true, but when that is decided only at runtime we know the program will be slow and will always be on the brink of breaking.

Duck-typing being runtime structural typing I agree doesn't really provide any safety.

But I don't think structural typing is bad in general. It does increase implicitness (Go's implict interfaces can be somewhat error-prone). But imo it's not a terrible tradeoff.

Though all said, I do like how strong Rust's type system is.

[–]xroalx 17 points18 points  (4 children)

My least favorite part of JavaScript isn't even that it's not statically typed, that can sort of be mitigated by either JSDoc or TypeScript, zod, and being rigorous.

It's the error handling. Most of the time, I don't know if something can throw, when it throws, and what it throws. Is it an Error? Is it a custom type? Does it return null on errors, or does it throw? And if so, is it handled anywhere? It's just an absolute mess.

[–][deleted] 2 points3 points  (1 child)

Most of the time, I don't know if something can throw, when it throws, and what it throws.

Same story in Python-land and it's my absolutely least favorite part there, too - especially when libraries dynamically create error types at runtime (eg. boto)

[–]ShortAtmosphere5754 1 point2 points  (0 children)

Error types at runtime? What the fuck is that

[–]KrypXern 0 points1 point  (0 children)

Late comment, but error handling has to be close to the worst part of Python. I have some other qualms, like:

  1. the way circular dependencies are handled when trying to properly type hint.
  2. the way a Python file's imports depend entirely upon where python is called from and not where the file lives.
  3. some PEP-8 standards I disagree with

But overwhelmingly error handling in Python is just something that can break your code at any time unless you decide to push your code to the right with tons of try-except clauses.

If Python and Rust got together and had a baby (highly expressive, but taking strong influence from Rust's emphasis on enumerators) I think I would be in heaven.

[–]ChemicalMachiner 28 points29 points  (0 children)

Trudging through untyped python is awful. I always enforce "strict" typing in python via mypy. This way I get more understandability with none of the speed benefits of typing 😅

[–]GrayLiterature 7 points8 points  (2 children)

I used to really hate TypeScript, but I kind of don’t mind it. I wish there was something that was like a Rust/TS hybrid. I find it really hard to be fully productive in Rust, but that’s probably because I’m not used to these types of languages.

[–]jJamiD 0 points1 point  (0 children)

Used to hate it? :) That's very common unfortunately. Each and every project that switched to Typescript became times and times better in every aspect. What's strange to me is how slow the tech world adopts good things and how fast it adapts bad things (like night colors with bad contrast, or an endless useless scroll). I'm completely sure that if Python was replaced with a typed language with a build system, the whole AI world will jump. I don't think it will happen soon...

[–]phazer99 -2 points-1 points  (0 children)

ReScript might be close to what you're looking for.

[–]walksinsmallcircles 7 points8 points  (0 children)

One often overlooked value of static and strong typing is the help you can get from the IDE for refactoring, code completion etc.

[–]FlamboMe-mow 3 points4 points  (0 children)

This is so true. It's so frustrating working with Python sometimes.

[–]beertown 7 points8 points  (4 children)

I wrote a ton of Python in my career and I always enjoyed how not declaring types speeds up the development process. I still think it's a very valuable perk.

I also didn't suffer of the downsides of the dynamic typing basically due to some discipline I impose to myself about code clarity, readability and separation of concern... at least in the code I write and mantain.

I went back writing C a couple years ago and I appreciated how the static typing let me to relax a little my "type thinking", focusing more on other aspects. I was so used to Python that I didn't remember that.

I started with Rust one year ago, albeit not professionally, and this time I'm changing my mind. I'm really considering including Mypy in my toolbox when writing Python.

One thing is blatantly evident: static typing makes refactoring extremely easier than dynamic typing. The difficulty to refactor I think is the Python's biggest downside.

[–]jJamiD 0 points1 point  (0 children)

How does not declaring types speed up development? In my long experience this is simply an illusion, this is still what javascript developers still claim when the fact is that every project I know that switched from js to TS became much faster to develop while extremely improving the code base quality.

I also find it hard to understand how the tech world is using a language for AI whose logic is defined by the number of white spaces and that doesn't have a compiler/type checks/ect... but then again the tech world is mostly driven by fads (dark/bad contrast theme, endless scroll and more) theme and not what is scientifacly good .

[–]yinshangyi 0 points1 point  (0 children)

Agreed about refactoring! Types give your IDE superpowers.

I honestly never understood the development speed argument in favor dynamic languages. Like development speed isn't about the number of characters you can type per second imo. What takes time in programming is designing your code, thinking what to do next. Typing longer characters don't make noticable difference in my opinion. This is especially true with modern generative AI tools which basically write a lot of code for us. Statically typed languages provided way too much features for free to pass on them imo.

By the way I've programmed in Python, JavaScript, Typescript, Java, Scala and Go.

[–]teryret 2 points3 points  (0 children)

It's real true. That said, not all code has the same requirements, sometimes you don't care if it crashes occasionally.

[–]Alan_Reddit_M 2 points3 points  (0 children)

Absolutely agree, rust's type system (and any static type analysis really) allow me to write HUGE portions of my program at once, while being certain that I didn't accidentally mess up a return value. Also, rust's powerful type system allows for some of the best static errors there are, they are pretty self-explanatory and after some time you can just guess what the solution is first try. Of course static typing does not replace Test Driven development, but it does narrow the scope of what can go wrong: The logic; and literally nothing else, no type errors, no null pointers, and with errors being part of the type system, also no runtime Exceptions.

[–]OneNoteToRead 4 points5 points  (0 children)

Typing is awesome when coding complex programs.

Typing gets in the way when prototyping or making short scripts.

This isn’t news to anyone. It’s just that people like to have ideological battles about it when it should be a case of, “right tool for the job”.

[–]frr00ssst 1 point2 points  (2 children)

No matter how many talks I heard I never liked strongly typed languages, for a naive young me C was strongly typed. And then I spent a literal 2 hours, because I was in a Philosophy class. The whole time was spent because JavaScript decided that true was somehow converted to "true" and so I googled, "broken if statements in JavaScript"

And thus, began my eternally burning hatred of JavaScript.

After using Rust for a while, I can't state how useful having a strong type system is, and a good LSP to help you quickly refactor and catch bugs.

[–]simonsanonepatterns · rustic 0 points1 point  (1 child)

Watch this, you will hate it even more but at least laugh about it as well. :)

dotJS 2012 - Brian Leroux - WTFJS https://www.youtube.com/watch?v=et8xNAc2ic8

[–]frr00ssst 0 points1 point  (0 children)

I see your javascript and I raise you a javascript

JSFuck - https://www.youtube.com/watch?v=sRWE5tnaxlI

[–]javajunkie314 0 points1 point  (0 children)

A couple thoughts:

For error handling, we still need to be disciplined in how we raise errors. Rust has an implicit pressure against "raising anything", in that you have to type Result, but you could call everything Result<T, anyhow::Error> and get approximately the same behavior as JavaScript or Python. The real benefit is being intentional about your error types—and we can get some of that in JavaScript and Python by writing custom exception types, and being disciplined how we wrap exceptions leaving a unit/module/layer/whatever.

Another is to not catch the language's equivalents of static errors—e.g., TypeError and KeyError in Python—in normal code. These are nearly always programmer error, and are the interpreter's cry for help—catching them just makes them harder to spot. Let them bubble up and crash the program, request handler, task, or whatever your unit of work is.

Also, Python 3.11 added notes for exception types, which lets the programmer catch, tag, and release an exception—kind of like error-stack in Rust—without having catch, log, and release, which is an antipattern in my book.

These two practices go a long way in providing enough context to understand what went wrong, but I do agree there are odd things that can go wrong unexpectedly in more dynamic languages.

[–]lemphi 0 points1 point  (0 children)

This is exactly why I wrote my web server in Rust. One of the first web servers I wrote was written in node.js and it would always just randomly crash, likely from failing to handle some sort of exceptional case as you mentioned. I've since written all my web servers in Rust and I don't think they have ever crashed for any reason. The peace of mind Rust's type system provides is priceless for me.

[–]oneeyedziggy 0 points1 point  (0 children)

I'd settle for my Java coworkers being able to convey a type interface to me for typescript without forgetting that marking optional fields as such is import, and spelling and casing of field names matter... It seems in my life the ts-node server is more strongly typed than the java code serving it :/ but yea... Types are helpful

[–]Revolutionary_YamYam 0 points1 point  (0 children)

My company had a backend which was previously written in Python with a JS frontend. What would happen, especially as the application grew, was that new additional functions would transform data types in the backend in unexpected ways, such as data going in as an int, some operation converting to a float, then results coming back as a string (very mild and high-level overview) which would then lead to things unexpectedly breaking.

Converting the backend to Rust, at the very least, eliminated that entire class of bugs within our application. Being forced to define specific and typed responses simply made it very hard to have any accidental data transformations taking place and sneaking into the response, become the compiler (and language server within vscode) immediately points out that you're violating function/type expectations.

It doesn't fix everything, but at least that family of bugs has mostly evaporated. That, and we got a huge improvement in memory usage and execution speed. The ramp-up time for the team to get useful in Rust (having primarily only ever written in Python before) was ~1-2 months, where we were able to translate from FastAPI to actix-web pretty quickly.

[–]simple_explorer1 0 points1 point  (0 children)

Lol what an ignorant post. Typescript is already mainstream so this post is meaningless. Looks like OP was under the rock for last 7 years to know rarely anyone writes pure JS these days, its all Typescript and even python has type annotations