Why make it complicated?
-
Map (Int, Int) Int
. Kind of a bad example because tuples have special-case infix syntax, the general case would beMap Int (Either Int Bool)
. Follows the same exact syntax as function application just that types (by enforced convention) start upper case. Modulo technical wibbles to ensure that type inference is possible you can consider type constructors to be functions from types to types....function application syntax is a story in itself in Haskell because
foo a b c
gets desugared to(((foo a) b) c)
: There's only one-argument functions. If you want to have more arguments, accept an argument and return a function that accepts yet another argument. Then hide all that under syntactic sugar so that it looks innocent. And, of course, optimise it away when compiling. Thus you can write stuff likemap (+5) xs
in Haskell while other languages need the equivalent ofmap (\x -> x + 5) xs
(imagine the\
is a lambda symbol).wrote on last edited by [email protected]Interesting. Thanks!
-
any new keyword could break backwards compatibility
Wouldn't that happen anyway with variable and function names? Any type other than primitive/built in ones are usually camel case so lower case keywords are more likely to clash with single word variable and function names, unless you restrict the cases of those too or allow keyword overriding or something.
wrote on last edited by [email protected]Yeah, it's in my edit I realized the same thing. I'm thinking it doesn't actually really make sense and the real reason is more "the specific way C does it causes a lot of problems so we're not poking syntax like that with a 10 foot pole" + "it makes writing the parser easier" + maybe a bit of "it makes grepping easier"
-
Rust is verbose, but C++ might still take the cake with its standard library templates. Especially when using fully-qualified type names...
auto a = ::std::make_shared<::std::basic_string<char, ::std::char_traits<char>, MyAllocator<char>>>();
A reference-counted shared pointer to a string of unspecified character encoding and using a non-default memory allocator.
wrote on last edited by [email protected]Yeah, I mean Rust is only verbose if you want it to be.
let foo = "bar";
is valid rust too, no need to declare the type and definitely no need to declare the lifetime.For that matter, if you ever declare something as explicitly
'static
in code that isn't embedded or super optimized, you're probably doing it wrong. -
I would because I know TypeScript and I don't know Rust.
ok but then you can't do Rust, so this does not apply.
but if you did.. !
-
ok but then you can't do Rust, so this does not apply.
but if you did.. !
Probably would still use TypeScript, because I use that for work.
β
οΈ Rust just seems like... a lot. Regarding Rust, I've seen a lot of praises and a not so insignificant amount of complaints that make me very hesitant to take the plunge. Can't remember off the top of my head what it was, specifically, but it was enough for me to write it off, that much I remember.
-
Made with KolourPaint and screenshots from Kate (with the GitHub theme).
STRING A WHAT, MOTHERFUCKER
-
If there's only two options you only need one keyword
Ah, but this is JS, so there are three options! And they all function entirely differently. And your assumptions don't apply, either.
-
Probably would still use TypeScript, because I use that for work.
β
οΈ Rust just seems like... a lot. Regarding Rust, I've seen a lot of praises and a not so insignificant amount of complaints that make me very hesitant to take the plunge. Can't remember off the top of my head what it was, specifically, but it was enough for me to write it off, that much I remember.
People really overstate it, it's not that hard. It has a reputation of being difficult because people use it for difficult, low-level tasks, OS stuff, parsers, cryptography, highly optimised serialisation, but those things would be hard in any language. For a newcomer it's, IMO, way easier than say C++, because it doesn't have a mindbogglingly huge std lib with decades of changing best practices to try to figure out. To do simpler things in it is really pretty straightforward, especially if you're already comfortable with a robust type system.
-
Dude, even just a "FY,I, you sure about this?" would be nice. I gladly embrace python's by-all-means-shotgun-your-leg-off philosophy, but the noobs could use the help.
the problem is that the language doesn't and can't support one single way to use type annotations without changing fundamental functionality. you can absolutely hook up mypy to your editor for newbies, but once you get on the intermediate level, fighting with mypy takes more code than actually solving the problem.
also there was that proposed update to mypy that was put on held when it turned out that the maintainers didn't know how annotations are used in the wild.
-
the problem is that the language doesn't and can't support one single way to use type annotations without changing fundamental functionality. you can absolutely hook up mypy to your editor for newbies, but once you get on the intermediate level, fighting with mypy takes more code than actually solving the problem.
also there was that proposed update to mypy that was put on held when it turned out that the maintainers didn't know how annotations are used in the wild.
Oh I'm well aware. Took me a solid year to appreciate type annotations for what they are and yeah I'm happy using what we have in stdlib now and not messing with mypy tyvm. The problem is that history is lost to newcomers who have very different expectations. Modern IDE's mostly solve it though, so for all my Java peeps dipping their toes into the snake waters, listen to your ide
-
Oh I'm well aware. Took me a solid year to appreciate type annotations for what they are and yeah I'm happy using what we have in stdlib now and not messing with mypy tyvm. The problem is that history is lost to newcomers who have very different expectations. Modern IDE's mostly solve it though, so for all my Java peeps dipping their toes into the snake waters, listen to your ide
i mean, i'm all for rejiggering the internals. i've personally written at least two libraries that uses type annotations in reverse to force arguments into the correct type, and i feel like that should probably be a separate mechanism to "just call the annotation"
-
People really overstate it, it's not that hard. It has a reputation of being difficult because people use it for difficult, low-level tasks, OS stuff, parsers, cryptography, highly optimised serialisation, but those things would be hard in any language. For a newcomer it's, IMO, way easier than say C++, because it doesn't have a mindbogglingly huge std lib with decades of changing best practices to try to figure out. To do simpler things in it is really pretty straightforward, especially if you're already comfortable with a robust type system.
wrote on last edited by [email protected]This contradicts what I've heard others say about it. I have a feeling it is quite subjective, and this might just be an anecdotal recommendation because you have an easy time with it. Maybe I will too! But maybe I won't.
Either way, one part of me really wants to try it, but one part has very little time in life. π₯²
Also comparing it to C++ might not be the flex we think it is.
-
This contradicts what I've heard others say about it. I have a feeling it is quite subjective, and this might just be an anecdotal recommendation because you have an easy time with it. Maybe I will too! But maybe I won't.
Either way, one part of me really wants to try it, but one part has very little time in life. π₯²
Also comparing it to C++ might not be the flex we think it is.
Well sure, I guess you're right, it's definitely a bit subjective and some people have an easier time with some languages and ways of thinking than others for sure. And I didn't really mean to say that it was totally super easy, but... no kind of programming is really super easy. It is quite different and that in itself has a learning curve.
My recommendation is for sure anecdotal, but I think the point about it seeming more difficult than it really is because people often use it for difficult stuff is actually true.
-
i mean, i'm all for rejiggering the internals. i've personally written at least two libraries that uses type annotations in reverse to force arguments into the correct type, and i feel like that should probably be a separate mechanism to "just call the annotation"
dataclasses do this for you at the class level. They enforce type annotations at instantiation.
-
Yeah, it's in my edit I realized the same thing. I'm thinking it doesn't actually really make sense and the real reason is more "the specific way C does it causes a lot of problems so we're not poking syntax like that with a 10 foot pole" + "it makes writing the parser easier" + maybe a bit of "it makes grepping easier"
wrote on last edited by [email protected]One thing that annoyed me about C# as a Java guy is that it really wants you to use camel case for function and property names, even private ones. I don't like it specifically because it's hard to differentiate between a function/property and a type.
But C# has quite a few keywords and seem to like adding them more than Java.
Maybe that's their way of ensuring keywords don't clash with stuff?
-
Well sure, I guess you're right, it's definitely a bit subjective and some people have an easier time with some languages and ways of thinking than others for sure. And I didn't really mean to say that it was totally super easy, but... no kind of programming is really super easy. It is quite different and that in itself has a learning curve.
My recommendation is for sure anecdotal, but I think the point about it seeming more difficult than it really is because people often use it for difficult stuff is actually true.
Take my up vote. I agree with everything in that comment.
-
dataclasses do this for you at the class level. They enforce type annotations at instantiation.
wrote on last edited by [email protected]i think we're talking about different things. you use enforce to mean "validate", i used it to mean "coerce". one of the cases was a command line argument parser that consisted of a single decorator, so you could write
@command def foo(bar: int, baz: float): print(baz * 2 + bar * 3)
and call it with
$ myfile.py foo --bar 3 --baz 2.2
and it would print 13.4another was about creating working protocol buffers from an excel sheet, nested types and enums and oneofs and everything. we used it to parameterize tests of our bluetooth protocol.
-
You're encoding more information in the typescript one. You're saying it's a string that will get updated.
Meanwhile if it's rust it's the opposite. (Variables that can change must specify that they are mutable)
-
That's just a comment
Looks like a snippet of C with two labels that will be referenced by a goto instruction. Very bad code tbh.
-
And bow to the compilerβs whims? I think not!
This shouldnβt compile, because .into needs the type from the left side and let needs the type from the right side.
If type constraints later in the function let the compiler infer the type, this syntax totally works.