Quicker to read because less type clutter to distract and stretch one's view [easier to understand and reason about the code]
That's like saying normal text is easier to understand without punktuation. Types provide concise additional information that make it easier to understand what the code does. var s; requires you to look at the rest of the function to figure out what that variable does, var s : set; immediately tells you that it is a set, making it quicker to understand.
And if you are really not interested in the types, they are usually different enough syntactically that you can ignore them at a glance. What are type signatures and what not isn't something you think about after getting used to the language a bit.
That's one of the dumbest analogies I've ever seen on this subreddit, lolwtflol?
First of all nobody would call the variable "s" they could have used a more descriptive name.
Mathematics have been around for 1000+ years and they generally don't "type" all variables in all proof expressions to gain anything in clarity.
Secondly the problem is when you have to use stuff like Func<ISequence<T>, IComparator<T,T>> f all the time, or in writing complex generic methods, it can get so bloated and cumbersome, and involving overspecification of the trivial, that languages that use type inference advertise it as a major selling point.
Finally it is extremeley rare that understanding what the code does depends on the type of the arguments or variables it uses.
They change the font to mark the type š¤ or s are sets, sā is a vector, s a scalar, S a map, Ļ the standard deviation, ...
Problems are also typically stated using types (called domains in maths): "let A be a complex square matrix and x be a vector of non-negative real numbers..."
First of all nobody would call the variable "s" they could have used a more descriptive name.
That doesn't matter, unless the descriptive name has a type in it (Hungarian notation), which is awful for other reasons.
Even if the variable was:
var users;
it would still be much easier to understand at a glance if it was:
var users: set<string>;
Yeah, you could probably name the variable userNameSet or something but it's still somewhat ambiguous and now you need to type the whole thing out every time you use it, rather than just once at its declaration.
Edit:
Finally it is extremeley rare that understanding what the code does depends on the type of the arguments or variables it uses.
wat. Knowing the types of what you are working with is critical to understanding what the code is actually doing.
Are you fucking nuts? Why would you use a name like "userNameSet"? It's downright stupid. The majority of data arguments you are using will be a dictionary or list/seq, and it's not that hard to disambiguate that from a comment or even just by the first god damn line it's used. You might only need to use a name like that if the data structure is really weird. Man I can't believe these comments...
You are also talking about some completely trivial example, where that shit isn't needed, and by your reasoning type inference mechanisms are useless and reduce clarity since you make it necessary for clarity reasons to specify the Func<Seq<T>,Action<IEnumerable,T,long>> stuff all the time.
wat. Knowing the types of what you are working with is critical to understanding what the code is actually doing.
No wtf ? it's not critical, most complex code (that isn't written in some kind of 1995 style huge object graph with "nominative" typing OO method) will just take a few data arguments that are simple data structure interfaces on data records, and a few functions to use. All the actual complexity will not be on the specific data types, but what the code actually does with the data. Sometimes it shouldn't depend on the data types too much, since you may want to generalize the operation.
Have you ever used linq in C sharp? Sometimes you are basically defining 20 implicit anonoymous types within some method, doing the equivalent thing your way would make the code 5 times as large and about 2 times less clear to the reader. How can the data types be so crucial if when they are defined implicitly the code actually gets more clear?
le reddit comment edit: I honestly can't believe the people downvoting, and the moronic replies, this thread has gone got full retard, lolwtf?
In case you missed the point of my previous post, I never said that you should name something "userNameSet" - just that you'd have to if you wanted to communicate that it was a set of user names, whereas with declared types, it would be much clearer (if it was a "set<string>").
The majority of data arguments you are using will be a dictionary or list/seq, and it's not that hard to disambiguate that from a comment or even just by the first god damn line it's used.
Well, I can think of a couple collections - like "list" and "set" - that would look very, very similar in their use, but have different semantics. Not to mention that even when you can deduce that a given argument is a list, you still don't know what it's a list of. Is that users argument a list of user names (strings), a list of user IDs (ints), or maybe a list of some kind of User domain object, with other data about it?
and by your reasoning type inference mechanisms are useless and reduce clarity since you make it necessary for clarity reasons to specify the Func<Seq<T>,Action<IEnumerable,T,long>> stuff all the time.
... where did I say that? I think type inference is great. I also think it should not be used to infer the types of function arguments or function return values. It's nice to have for local variables because you can make the decision whether or not you want to specify the exact type on a case-by-case basis.
Have you ever used linq in C sharp? Sometimes you are basically defining 20 implicit anonoymous types within some method, doing the equivalent thing your way would make the code 5 times as large and about 2 times less clear to the reader.
Oh boy, let's talk about this - because I do use LINQ with C#. First off, the vast majority of the times I use LINQ, I don't use anonymous classes - because the "result" ends up being something like a list of strings or some already-defined domain object.
But if it's useful, you can define anonymous types in C#. You bind variables to them using the var keyword for the type. It's a great example of how useful static typing is - any access to those anonymously-typed objects is checked by the compiler.
Now you could argue that in a dynamic language, you don't need to even write those domain types - they're mostly simple objects with getters and setters (well, properties in C#). But then you want to add an extra field. In C#, this is easy - you add the field to the object and constructor, then go to each place the constructor is called to figure out how you want to pass in the new field. (Or maybe you keep the old constructor and use a default value, if you'd like.)
In dynamic typing land, it's much more difficult. You're ad-hoc creating these objects, so you'd have to track down every place you create one (a very difficult task where the type system cannot help you) and make sure you either add a default value or pass in some specific value for the new field.
Yeah, you don't need to write another getter/setter, but my IDE basically does that for me (in C# it's even easier with auto-properties) - and it's way easier than dealing with the subtle bugs you'd get at runtime with a dynamic language.
Well, I can think of a couple collections - like "list" and "set" - that would look very, very similar in their use, but have different semantics.
Yeah the point is you don't really need this? It's hardly the point of the code where you are gonna get stuck trying to understand what it's doing, you can just add some comment to it if it doesn't do the obvious.
And that the real issue isn't in variables like that, but when you are forced to type stuff like what I wrote
where did I say that? I think type inference is great. I also think it should not be used to infer the types of function arguments or function return values. It's nice to have for local variables because you can make the decision whether or not you want to specify the exact type on a case-by-case basis.
If you are suggesting that a "users" name is unclear over whether it is a set or a list and you should absolutely go and add a type definition to it => all variables that you get when writing complex generic code and end up being typed with something way more convoluted should also be unclear if their type isn't provided => type inference makes things unclear. Which means that if you are also saying that type inference is great you are contradicting yourself. Type inference implies that you don't (as someone reading the code) particularly care about and won't have to state the type, and your initial comment is about how not stating the type is problematic.
Oh boy, let's talk about this - because I do use LINQ with C#. First off, the vast majority of the times I use LINQ, I don't use anonymous classes - because the "result" ends up being something like a list of strings or some already-defined domain object.
Then you are just not doing the kind of thing they are supposed to be useful for. In linq queries I am often forced to use "let" or select anonymous types to connect loosely associated entities or do intermediate ad hoc transformations that will go and get grouped , I do use non anonymous classes every now and then, but for the large variety of "connections" between tansformed entities that might arise you are left with 4 options 1) use local anonymous types 2) make a large amount of result/view classes 3) make a few result classes with many members 4) make all entity associations be part of the entity's class. IMO (2) adds too much stuff and it can be dificult for someone else too discover those classes (he might have 20 classes with similar names and be unsure what to choose), (3) I am not completely ruling it out, but it can sometimes make the code less clear when you are using structures where 80% of what they provide is unused (some other programmer will assume that something is missing and get confused) (4) is basically similar to (3) but even worse.
"Uhh" yeah it is static typing, and what? Lol wtf is wrong with y'all niggaz are you smoking weed?
iiirc the initial argument in this part of the thread was some blatantly wrong analogy that was supposed to be a counter argument to how dynamic languages make the code more clear.
I tried to show how it completeley missed the point (the code gets more clear when the types are complex, hence the type inference)
Then despite me bringing up the fact that type inference came to make static languages read like dynamic languages, precisely beacause dynamic languages are easier to read, you came and gave some logically incoherent and pointless stuff that as arguments they contradict themselves. And I pointed out how it's basically a contradiction, and all you have to say is that linq is indeed static typing and I am supposed to not have noticed?
I am trying to explain why dynamic typing can be more clear to read, by giving an example of static typing emulating dynamic typing for clarity reasons, and you are like saying the exampe doesn't count because it comes from static typing! It makes no sense! Unless you are smoking the ganja!
9
u/tejp Jun 12 '16
That's like saying normal text is easier to understand without punktuation. Types provide concise additional information that make it easier to understand what the code does.
var s;requires you to look at the rest of the function to figure out what that variable does,var s : set;immediately tells you that it is a set, making it quicker to understand.And if you are really not interested in the types, they are usually different enough syntactically that you can ignore them at a glance. What are type signatures and what not isn't something you think about after getting used to the language a bit.