| ▲ | hbrn 10 months ago |
| > Writing software without types lets you go at full speed. Full speed towards the cliff. Isn't it strange that back when Python (or Ruby) didn't even have type hints (not type checkers, type hints!), it would easily outperform pretty much every heavily typed language? Somehow when types weren't an option we weren't going towards the cliff, but now that they are, not using them means jumping off a cliff? Something doesn't add up. |
|
| ▲ | dinosaurdynasty 10 months ago | parent | next [-] |
| It's because the nature of typing has changed drastically over the last decade or so, in well known languages, going from C++/Java's `FancyObject *fancyObject = new FancyObject()` (which was definitely annoying to type, and was seen as a way to "tell the compiler how to arrange memory" as opposed to "how do we ensure constraints hold?") to modern TypeScript, where large well-typed programs can be written with barely a type annotation in sight. There's also a larger understanding that as programs get larger and larger, they get harder to maintain and more importantly refactor, and good types help with this much more than brittle unit tests do. (You can also eliminate a lot of busywork tests with types.) |
| |
| ▲ | hbrn 10 months ago | parent | next [-] | | Large programs are harder to maintain because people don't have the balls to break them into smaller ones with proper boundaries. They prefer incremental bandaids like type hints or unit tests that make it easier to deal with the big ball of mud, instead of not building the ball in the first place. | |
| ▲ | liontwist 10 months ago | parent | prev [-] | | No it hasn’t? C++ type system has hardly changed (until concepts) and is one of the most powerful available. A certain generation of devs thought types were academic nonsense and then relearned the existence of those features in other languages. Now they are zealots about using them. | | |
| ▲ | josephg 10 months ago | parent [-] | | I think the point is that in newer languages like typescript, the price paid for static typing is lower because type inference does so much of the leg work. You get all the benefits of static typing, and the cost is usually tiny - you just need to define your types (a valuable exercise regardless) and add them to function signatures. We’ve come a long way from the C++ or Java I wrote when I was young, where types were named and renamed constantly. As I understand it, even C++ has the auto keyword now. | | |
| ▲ | maleldil 10 months ago | parent [-] | | C++ has extensive type inference now (C++20): #include <string>
auto func(auto x, auto y) -> auto {
return x + y;
}
auto main() -> int {
auto i = func(1, 2);
auto s = func(std::string("a"), std::string("b"));
}
`int` is required as a return type from `main`, but everything else is inferred. This works because `func` becomes a template function where each parameter type is a separate template type, so you get compile-time duck typing. It also works with concepts (e.g. `std::integral auto x`).It's quite neat, but I don't think anyone actually writes code this way, except for lambdas. |
|
|
|
|
| ▲ | sethammons 10 months ago | parent | prev | next [-] |
| Every single typed system I have ever worked on, no matter how poorly designed, has been easier to alter than the vast majority of ruby, python, perl, php, and elixir that I've worked on |
| |
| ▲ | zmgsabst 10 months ago | parent [-] | | I have the opposite experience: Inserting a library that wraps an existing one to add new features has been a nightmare in every statically typed language I’ve used — including times it’s virtually impossible because you’d need the underlying library to understand the wrapper type in its methods. In Python (with duck typing), that’s a complete non-issue. | | |
| ▲ | josephg 10 months ago | parent | next [-] | | Can you give an example? I think part of the problem is that mixins and such are so hard to do in most statically typed languages that programmers just don’t code things that way. I see your point - I certainly find myself reaching for clever high level patterns less in typescript than I do in JavaScript because complex typing can get in the way. But also, programs that make heavy use of metaprogramming are often, also, harder to read and debug. There’s something very nice and straightforward about explicit, concrete types. | | |
| ▲ | pmontra 10 months ago | parent [-] | | I'm not the person you asked the question to but I had an unpleasant experience with Typescript recently. I used a HTTP requests library in a nuxtjs app (probably nuxt's native library) and I spent too much of my time conjuring the request and response types that would please the type checker. It was extremely frustrating because the code would work in Javascript but the compiler wouldn't accept it because of typing. I can't give you the details because I'm not at my computer now but the type was a mix of HTTP verbs and the structure of the JSON response. I gave up after a while and rewrote the code using fetch and no types. If they stand between me and the final result they can go down the drain. | | |
| ▲ | josephg 10 months ago | parent [-] | | Sounds like a bug in the type definitions. Thats an unfortunate consequence of typescript being glued to javascript: If you import a package that is authored in javascript, there's no guarantee that the type definitions are written correctly or kept up to date. Sometimes they don't exist at all. It doesn't happen too often, but its definitely annoying. In cases like this, the easiest way is to just add as any to your expression - which essentially turns off type checking for that expression. Maybe that's what you did? fetch('foo.json', {...} as any)
I don't think there's anything wrong with this. Using typescript types for only 95% of your code rather than 100% still provides a lot of value in my opinion.You can also ctrl+click on functions like this and read the actual types they're expecting. | | |
| ▲ | pmontra 10 months ago | parent [-] | | I did this: const response = await fetch(
url,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(reqData),
}
);
const resData: ApiResponse = await response.json();
then I parsed resData. The JSON in the response is still type checked but I don't have to fight anymore with the HTTP library. I can't remember what it was as it never made it into a commit. | | |
| ▲ | josephg 10 months ago | parent [-] | | Yeah makes sense. Now that fetch is standardized and built in to node, frankly I don't see any reason to ever pull in request. |
|
|
|
| |
| ▲ | plaguuuuuu 10 months ago | parent | prev [-] | | Worth mentioning that I've also have the opposite opposite experience. Wrapping/using a library in vanilla JS, the type signatures changing and breaking unexpectedly with an update and only finding out when parts of the app suddenly broke. It can be slightly laborious to manually wrap a bunch of operations so you can override something, but it's more of an annoyance/inefficiency than something that adds cognitive overhead. That said, many languages (eg structurally typed ones like TS) it should be a non-issue. |
|
|
|
| ▲ | lmm 10 months ago | parent | prev | next [-] |
| > back when Python (or Ruby) didn't even have type hints (not type checkers, type hints!), it would easily outperform pretty much every heavily typed language? No it didn't. It outperformed Java 1.2, and people thought that Java 1.2 was what a typed language looked like. Python always sucked compared to OCaml (yet alone OCaml with a decent IDE), but OCaml had a weird syntax and the documentation was in French, so no-one cared. Now that we finally have a copy of OCaml with curly braces and a critical mass of obnoxious fanboy hype, more people have noticed. |
|
| ▲ | IshKebab 10 months ago | parent | prev | next [-] |
| > when types weren't an option we weren't going towards the cliff Erm yes we were. Untyped Python wasn't magically tolerable just because type hints hadn't been implemented yet. |
| |
| ▲ | hbrn 10 months ago | parent [-] | | How come all those unicorns were built with intolerable Python/Ruby, not Java/C#/Go? https://charliereese.ca/y-combinator-top-50-software-startup... | | |
| ▲ | junyjujfjf 10 months ago | parent | next [-] | | They are likely leveraging Django/Rails which treads the beaten path for Startups. Startups are also more likely to do monoliths. For Enterprise & microservices, you will start to see more Java/Go/C#. | | |
| ▲ | hbrn 10 months ago | parent | next [-] | | I would expect dynamic type crowd to embrace microservices first, given how everybody says that dynamic codebases are a huge mess. Regardless, to me enterprise represents legacy, bureaucracy, incidental complexity, heavy typing, stagnation. I understand that some people would like to think that heavy type-reliance is a way for enterprise to address some of it's inherent problems. But I personally believe that it's just another symptom of enterprise mindset. Long-ass upfront design documents and "designing the layout of the program in types first" are clearly of the same nature. It's no surprise that Typescript was born at Microsoft. You want your company to stagnate sooner? Hyperfixate on types. Now your startup can feel the "joys" of enterprise even at the seed stage. | | |
| ▲ | josephg 10 months ago | parent [-] | | Eh. The amount of work it takes to specify your types in a typescript program is tiny. Type inference does almost all of the work. And the benefit of that work is largely felt in maintenance & onboarding, since the code is easier to read when you’re new and come back to later. Refactoring large JavaScript programs is a nightmare. The real enterprise death doesn’t come from types. It comes from tasteless over use of classes - especially once you have a complex web of long lived objects that and all reference each other. Significant portions of code in these codebases ends up dedicated to useless tasks like lifecycle management instead of the actual work of your application. It’s kind of the code version of corporate beaurocracy - classes everywhere devoted to doing BS jobs. It’s not complicated people. Just write the code that tells the computer what you want it to do. No more. Unnecessary encapsulation and premature abstraction will kill your velocity dead. |
| |
| ▲ | liontwist 10 months ago | parent | prev [-] | | This distinction makes no sense. Can you explain why types would be more relevant? | | |
| ▲ | junyjujfjf 10 months ago | parent [-] | | Actually I don't think types are relevant here. People are choosing based on other weighted factors like toolchain, ecosystem, products, and culture. | | |
|
| |
| ▲ | IshKebab 10 months ago | parent | prev | next [-] | | Proper engineering isn't that much of a concern when you have 0 customers, and by the time you have some it's too late to change. Besides nobody is claiming that it's impossible to build a successful products with dynamic typing. It's just not as good. You can build a successful product with zero comments in your codebase, doesn't mean it's a good idea. | | |
| ▲ | hbrn 10 months ago | parent [-] | | > It's just not as good Again, the evidence (as limited as it is) suggests otherwise. You are more likely to succeed if you're going with dynamic language and not doing "proper engineering". This has been widely accepted before type-checker era, and I see no reason why it would be different now. Utilize type checker when it's free, but don't waste time on type puzzles. "Proper engineering" doesn't get you to product-market fit faster. All it does is tickle your ego. |
| |
| ▲ | sethammons 10 months ago | parent | prev [-] | | My previous unicorn rose despite the initial tech, not because of it | | |
| ▲ | hbrn 10 months ago | parent [-] | | I gave you a selection of top 50 startups out of thousands funded by YC. You're giving me one anecdote. |
|
|
|
|
| ▲ | kstrauser 10 months ago | parent | prev [-] |
| A lot of the old robust code tended to have guard statements like “if not isinstance(…): raise ValueError”, which does a great job of surfacing mistakes before they can compound too much. We all wrote scads of production Python over the decades before typing caught on. I think it’s much easier to do a good job of it now. Having your IDE yell at you before you’ve even finished saving the file sure beats running it and hoping for the best. |