6 ms·
FYI: Ruby is strongly typed, not loosely. > 1 + "1" (irb):1:in 'Integer#+': String can't be coerced into Integer (TypeError) from (irb):1:in '<mai
by arrowsmith 1y ago
FYI: Ruby is strongly typed, not loosely.
> 1 + "1"
(irb):1:in 'Integer#+': String can't be coerced into Integer (TypeError)
from (irb):1:in '<main>'
from <internal:kernel>:168:in 'Kernel#loop'
from /Users/george/.rvm/rubies/ruby-3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.14.3/exe/irb:9:in '<top (required)>'
from /Users/george/.rvm/rubies/ruby-3.4.2/bin/irb:25:in 'Kernel#load'
from /Users/george/.rvm/rubies/ruby-3.4.2/bin/irb:25:in '<main>'
- kitten_mittens_ 1y agoThere seem to be two competing nomenclatures around strong/weak typing where people mean static/dynamic instead.
- jnpnj 1y agoyes, untyped names != untyped objects
- josephg 1y agoSome people mistakenly call dynamic typing "weak typing" because they don't know what those words mean. PSA: Static typing / dynamic typing refers to whether types are checked at compile time or runtime. "Static" = compile time (eg C, C++, Rust). "Dynamic" = runtime (eg Javascript, Ruby, Excel) Strong / weak typing refers to how "wibbly wobbly" the type system is. x86 assembly language is "weakly typed" because registers don't have types. You can do (more or less) any operation with the value in any register. Like, you can treat a register value as a float in one instruction and then as a pointer during the next instruction. Ruby is strongly typed because all values in the system have types. Types affects what you can do. If you treat a number like its an array in ruby, you get an error. (But the error happens at runtime because ruby is dynamically typed - thus typechecking only happens at runtime!).
- 0x457 1y agoIt's strongly typed, but it's also duck typed. Also, in ruby everything is an object, even the class itself, so type checking there is weird. Sure it stops you from running into "'1' + 2" issues, but won't stop you from yeeting VeryRawUnvalidatedResponseThatMightNotBeAuthorized to a function that takes TotalValidatedRequestCanUseDownstream. You won't even notice an issue until: - you manually validate - you call a method that is unavailable on the wrong object.
- arrowsmith 1y agoYou just described why I fell out of love with Ruby.
- 0x457 1y agoBecause you wanted to do 1 + '1'?
- deleted 1y ago[deleted]
- ameliaquining 1y agoI recall a type theorist once defined the terms as follows (can't find the source): "A strongly typed language is one whose type system the speaker likes. A weakly typed language is one whose type system the speaker dislikes." Related Stack Overflow post: https://stackoverflow.com/questions/2690544/what-is-the-difference-between-a-strongly-typed-language-and-a-statically-typed https://stackoverflow.com/questions/2690544/what-is-the-diff... So yeah I think we should just give up these terms as a bad job. If people mean "static" or "dynamic" then they can say that, those terms have basically agreed-upon meanings, and if they mean things like "the type system prohibits [specific runtime behavior]" or "the type system allows [specific kind of coercion]" then it's best to say those things explicitly with the details filled in.
- dpryden 1y agoI think you might be thinking of https://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/ https://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wr... It says: > I give the following general definitions for strong and weak typing, at least when used as absolutes: > Strong typing: A type system that I like and feel comfortable with > Weak typing: A type system that worries me, or makes me feel uncomfortable
- johnfn 1y agoirb(main):001:0> a = 1 => 1 irb(main):002:0> a = '1' => "1" It doesn't seem that strong to me.
- dgb23 1y agoIn the dynamic world being able to redefine variables is a feature not a bug (unfortunately JS has broken this), even if they are strongly typed. The point of strong typing is that the language doesn't do implicit conversions and other shenanigans.
- Spivak 1y agoWell yeah, because variables in what you consider to be a strongly typed language are allocating the storage for those variables. When you say int x you're asking the compiler to give you an int shaped box. When you say x = 1 in Ruby all you're doing is saying is that in this scope the name x now refers to the box holding a 1. You can't actually store a string in the int box, you can only say that from now on the name x refers to the string box.
- deleted 1y ago[deleted]
- 9rx 1y agoThe types are strong. The variables are weak.
- folkrav 1y agoIt would be weak if that was actually mutating the first “a”. That second declaration creates a new variable using the existing name “a”. Rust lets you do the same[1]. [1] https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#shadowing https://doc.rust-lang.org/book/ch03-01-variables-and-mutabil...
- johnfn 1y agoRust lets you do the same because the static typing keeps you safe. In Rust, treating the second 'a' like a number would be an error. In ruby, it would crash.
- pclowes 1y agoOops, I meant weakly typed as in JS or strongly typed as in Ruby. But decided to switch the Ruby example to Elixir and messed up the sentence
- js2 1y agoGood luck with this fight. I've had it on HN most recently 7 months ago, but about Python: https://news.ycombinator.com/item?id=42367644 https://news.ycombinator.com/item?id=42367644 A month before that: https://news.ycombinator.com/item?id=41630705 https://news.ycombinator.com/item?id=41630705 I've given up since then.
- arrowsmith 1y agoI already wrote about wrt Elixir: https://arrowsmithlabs.com/blog/elixir-is-dynamically-and-strongly-typed https://arrowsmithlabs.com/blog/elixir-is-dynamically-and-st...
- 9rx 1y agoWe've been reading comments like that since the internet was created (and no doubt in books before that). Why give up now?