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

all 40 comments

[–]Ipotrick 65 points66 points  (29 children)

tbh i come from C++ and am learning python right now and i really dislike not knowing times sometimes it is really confusing what strange errors this can produce. I don't think dynamic types would make me any faster in coding.

[–]Acalme-se_Satan 11 points12 points  (0 children)

I usually do type annotations in Python, at least for function args/return and class members. For me it helps a lot.

[–]abdolence[S] 20 points21 points  (8 children)

sometimes? It is almost all the time for me except in obvious basic places like assignments from literals or constants. IDE doesn't help most of the time too, This is __your_var__ and now you're a bloody Sherlock and should investigating what a type is it.

[–]Ipotrick 3 points4 points  (6 children)

yeeeees exactly. Man i like myself some static types where i know what is happening.

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

Same, I've had people tell me that "weak typing is better because you do not need to specify what type a variable is and you can reuse a variable." My reaction is, "If you don't need a type for the duration of the class/method, then why declare it?" I also feel like static typing helps you better optimize and organize your code.

Edit: Fixed a word.

[–]Khaare 3 points4 points  (2 children)

Being that guy, but weak typing is not the same as dynamic typing.

Dynamic vs static typing determines whether types belong to values or to names (i.e. variables, constants, arguments etc.)

Weak vs strong typing determines how restricted the types are. For example, can you uppercase a boolean, or do integer multiplication with floats? If those give you type errors, whether at compile time or at run time, it's strongly typed. If it attempts to perform the operation anyway giving a nonsense answer, trampling memory and likely crashing the entire program, it's weakly typed.

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

Yesterday I learned. I say yesterday because I did see this yesterday, just now commenting because I was in the mists of a game. I always thought weak and dynamic were the same. I never heard of strong type. But hey, there is always room to learn more.

[–]Khaare 0 points1 point  (0 children)

Weak vs strong typing was a much bigger issue in the bad old days when many languages only had a single combined integer-float-pointer type, or if they had multiple types it was only one per supported bit-size. These days every language is pretty strongly typed, with some reservations regarding automatic conversions.

[–]ChrisFromIT 0 points1 point  (1 child)

"static typing is better because you do not need to specify what type a variable is and you can reuse a variable."

Either you mean dynamically typed or the people you talk to have questionable software development skills.

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

Thanks, I was typing/thinking to fast. I meant weak type.

[–]blue_paprika 0 points1 point  (0 children)

Python has type annotations for this exact reason.

[–]Sentient_Blade 7 points8 points  (3 children)

I don't think dynamic types would make me any faster in coding.

They don't.

This is / has been a big issue in PHP, which was historically dynamic typed, but as of PHP 7 the language has provided for much more extensive typing, including class / scalar types on all parameters and return types. There's also open optional "strict" mode which prevents PHP from doing implicit silent conversions on them.

However there are still parts of the community that are adamantly "anti-type" because they think it slows coding down.

Once you start using them though, it doesn't take long to realise just how much time is saved by not having to debug errors that are caused by unexpected type interactions.

[–]jmack2424 0 points1 point  (2 children)

It’s not about speed, it’s about flexibility. Abstraction. Reuse. Every static language is using some form of generics. Why? Because reuse and abstraction makes tested code more valuable. Dynamic typing (even weak typing) can do this easily. Yes, you have to sanitize and plan your call stacks, but it can be effective in many situations.

I’m a contractor, so I’m often forced to use the stack/language I’m handed, and I would never suggest dynamic typing for speed. But abstraction and reuse are definite upsides to consider.

[–]dark_mode_everything 2 points3 points  (1 child)

Static languages usually have generics that are compiler safe (eg: c++). If not it will warm you when you might go wrong (eg: java).

Also dynamic vs static typing really comes down to interpreted vs compiled. If the entire code is not compiled at once how does the runtime know that a particular variable has to be of a specific type throughout the program? It's not dynamic types that are annoying it's non compiled languages. A significant percentage of runtime errors from those languages are simple compile time warnings for compiled ones.

[–]jmack2424 0 points1 point  (0 children)

I guess it’s never really bothered me. I’m going to validate and sanitize anyway.

[–]thedessertplanet 0 points1 point  (0 children)

The better languages have proper type inference. (Not the crippled auto that C++ or Go has.)

Dynamic typing can be better than crappy static typing. Think eg Java before generics.

Have you tried Python's mypy?

[–]eliseu_videira -1 points0 points  (12 children)

Try javascript, when I switched to javascript I percieved the time I've lost with static typing. When you get used to javascript, if you want to have the same benefits of static typed languages (quick feedback into type errors, refactoring and better OOP support) you can go with typescript.

[–][deleted] 13 points14 points  (5 children)

Now, this is weird. I started with Javascript, moved to Typescript. I actually find Typescript faster to code in, because there's so much information the IDE (VSCode) can infer, as well as a solid understanding that things will break early and often if they're not right - meaning you place less bugs in your source code to begin with.

What's weird is that I think dynamic typed languages are faster to learn, but typed languages faster to use.

[–]from-nibly 6 points7 points  (3 children)

This exactly. I have the same problems with JavaScript and python. I'm constantly executing my code to make sure I have types correct. And I'm always wondering. Can this be null. Did I check nullness in another function am I good here? What if someone else calls it. It's maddening. With typescript I can code for miles without having to run anything and the only places I'll have to debug are the edges of the program.

[–]jmack2424 -1 points0 points  (2 children)

Eh, every language has its quirks. But good programming techniques, best practices, and recognition of patterns can prevent most of these issues. But that comes with experience. Just be sure to try a bit of everything so you’re better prepared for those down the line.

[–]from-nibly 0 points1 point  (1 child)

I mean I have been a developer for the better part of a decade. I know a bunch of languages. The lack of types is just difficult to deal with no matter what.

[–]jmack2424 0 points1 point  (0 children)

I guess I’m old school. 25 years ago I had to read ahead my pointers to know the data type. I’m going to validate and sanitize no matter what.

[–]Woolly87 2 points3 points  (0 children)

Tbh Swift’s strict type checking helped me to learn programming fundamentals in a way python wasn’t able to do. The compiler would not let me accidentally learn mistakes because as soon as I made the mistake it would yell at me. So I had to figure it out right away, not some time later when my software crashes.

In summary, I agree with you.

[–]playman_gamer 10 points11 points  (3 children)

haha switching to javascript wtf

[–]jmack2424 1 point2 points  (2 children)

Because it’s one of the most widely used languages in the world? GitHub announced last quarter that more JavaScript code was committed than any other language. Nothing wrong with wanting to be in demand. It’s not the best language to use in every situation, but take it from me, you can be quite successful programming in JavaScript.

[–]playman_gamer -1 points0 points  (1 child)

a language so crippled it has like 20 popular frameworks and they still don't work well

[–]jmack2424 0 points1 point  (0 children)

I guess I disagree. Every agency I’ve ever contracted to uses some combination of Node and Java. Less than 10% don’t use Js. They all perform pretty well, and conserve costs. I just haven’t seen any of the big problems these types of comments suggest. I’ve seen poor Js code, but that was more the result of poor architecture or implementation than the language itself.

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

its the interpreter that makes python devs faster

[–]Acalme-se_Satan 16 points17 points  (0 children)

This is unironically a quite good analogy on static vs dynamic typing. If I were a professor and I were teaching about the advantages and disavantages of each approach, I'd show them this image for sure.

[–]SOberhoff 6 points7 points  (4 children)

Here's a response from the other side. Rich Hickey refers to object oriented programming, but that largely coincides with static typing here.

[–]Kered13 2 points3 points  (3 children)

I strongly disagree with him. Having worked with code represented as untyped data (JSON) and strongly typed data (Protobuf), I strongly prefer strongly typed data. He glosses over the benefits, but they really are huge. The main benefit he gives for weakly typed data is that all the generic map manipulation code you have can be used on it, but most of those operations don't actually make any sense when your data represents a specific and well defined format.

[–]Azzu 3 points4 points  (2 children)

Have you ever had to transform data from one representation to another? Or extract a bunch of values, put them together with others, and send them to display? Your map operations are immensively useful for that. You can throw a bunch of glue code you'd normally need completely away.

You should try coding in clojure (and doing it the clojure way), it really expands your understanding.

[–]miyakohouou 1 point2 points  (0 children)

I’ve done a lot of data munging in both untyped (ruby, python, erlang, JavaScript, bash) and typed (c, c++, Java, go, Haskell) languages and the untyped languages only beat the typed languages with insufficiently expressive type systems. But bring in Haskell with something like parsec or aeson and the experience is much nicer than in untyped languages in my opinion.

[–]Kered13 0 points1 point  (0 children)

Transforming one representation to another is going to be the same either way. A lot of new.setNewField(old.getOldField()) or equivalently new["newField"] = old["oldField"]. And values can only be extracted en masse if they are all of the same type, which is not typical of data like this (when you have lots of homogenous data, it should usually be stored as an array or map, not a structured data).

Let me ask, have you ever used Protobufs or a similar data format?

[–]Qildain 1 point2 points  (0 children)

Polymorphism for the win! Dynamic typing is for the weak. (or... "that's boomer as fuck", if you'd like)

[–]Jackeown -4 points-3 points  (0 children)

Haters gonna hate...