8 ms·
>The cost you pay for appeasing the type system is the cost you're not paying writing more tests around corner cases I have spent a lot of time in Rust getting
by whatshisface 6y ago
>The cost you pay for appeasing the type system is the cost you're not paying writing more tests around corner cases
I have spent a lot of time in Rust getting carried away with type system stuff that is not required for the actual program I am writing. I realize this when I go over it a second time and reduce line counts drastically by replacing my gee-whiz generics with primitive types. This is balanced out by an equal number of times where I've reduced line counts drastically by using the advanced type stuff to reduce the repetition that comes along with using primitives to represent a type that has way more structure than the primitive.
- hinkley 6y agoA year from now, isn't it the 'reduced line count' that will have value to you, rather than the churn?
- WJW 6y agoSometimes. Often the reduced line counts contain way more complexity per line and understanding it is just as hard. There's something to be said for code churn, as it keeps it fresh in the mind of whomever is on the team right now as opposed to "a guy that left eight years ago wrote this".
- hinkley 6y agoAs simple as possible, but no simpler. I sometimes use the analogy of haiku versus short story. You can pack a lot of meaning into a haiku, but few will be able to unpack it in the manner intended. A short story can get you to the point without filling a whole book to do so. And a lot more people can write a reasonable short story.
- pragmatic 6y agoExactly, the maintenance tax, you have to load the crazy type into your head and once you get to 2 or 3 layers of generics is just painful. C# and typescript both have this. The question is, what is beyond generics? We need a humane alternative that still provides the type safe guard rails.
- deleted 6y ago[deleted]
- chewbacha 6y ago> I realize this when I go over it a second time and reduce line counts drastically by replacing my gee-whiz generics with primitive types. I do this too, but I’ve also come to realize that fresh perspectives and newly learned patterns may be more of the reason than being a little over zealous. Edit: forgot to mention that this happens to me in most languages, not just rust.
- smichel17 6y agoI haven't used Rust before, but I can relate to the experience. In general I lean towards it not being a waste. That's not to say it's always useful for that project but it is usually useful as a learning exercise, that allows me to better identify similar patterns later (including whether generics are worth using compared to primitive types, in situations like that). For example, I spent a good year or two forcing all of my iteration into functional styles. Now I am much better at coding in that style... and at knowing when a for loop is the more appropriate tool.
- jiggawatts 6y agoOne of the most pleasant parts of programming in C# is that an 'int' is an 'int'. If some function takes an integer input, that's exactly what it takes. In C/C++, the base type system is so weak and squishy that everything redefines every type. You can no longer pass an 'int', but instead pass a "FOO_INT" or a "BARLONG" where FOO and BAR are trivial libraries that shouldn't need to redefine the concept of an integer. Like C#, Rust has well-defined basic types, which eliminates a crazy amount of boilerplate and redefining the basics.
- DaiPlusPlus 6y agoC++ itself has well-defined (if verbose-named) types (e.g. uint32_t ) the problem is as soon as you interface with any large library or platform API with a long history: Win32 and Qt comes to mind. It’s 2020 and Windows.h still has macros for 16-bit FAR pointers. I’m disappointed Microsoft hasn’t cleaned-up Win32 and removed all of the unnecessary macros (they can start with T()!) C# and Java might seem to have escaped that problem - but now it means that because `int` was defined back in 32-bit days programs can’t use `int` (System.Int32) when the intent is to use - what is presumably - “the best int-type for the platform” (I.e. C++’s fast-int types) - or the context (.NET’s arrays are indexed by Int32 instead of size_t, so you can’t have a Byte[] array larger than 2GB without some ugly hacks). (I know this is moot for function locals as those will be word-aligned and so should behave the same as a native/fast int, but this isn’t guaranteed, especially when performing operations on non-local ints, such as in object instance fields).
- throwaway8941 6y ago>I’m disappointed Microsoft hasn’t cleaned-up Win32 and removed all of the unnecessary macros Considering how seriously they take backward compatibility, the only way to do that would be to design a completely separate API, like they did with UWP. I'm 99.999% certain these macros are still being used somewhere out there. And who usually takes the blame when some badly written application stops working or compiling properly? Microsoft. (And I don't even like Microsoft.)
- 6y ago
- beefsack 6y agoI feel obsessing over types is often just a form of procrastination, as it feels more interesting than the real work that needs to be done. This seems to be a bigger issue in Rust because the type system is powerful. I write a lot of Rust nowadays, so I often need to keep myself in check and make sure I'm not getting sidetracked. When I'm writing internal code, the priority is to just get it done but still avoiding shortcuts. This is mainly avoiding .unwrap() / .clone() / taking care to handle Result correctly, as well as regularly running clippy to pick up the obviously silly stuff. I find the most painful part of this strategy is when you want to revisit completed code to reduce copying as that generally requires a lot of type changes. At least when you get to this point though and haven't taken shortcuts, you've got functioning software and it should be fairly fault tolerant.
- DaiPlusPlus 6y ago> I feel obsessing over types is often just a form of procrastination, as it feels more interesting than the real work that needs to be done. I spent 2 days implementing a (terrible) discriminated union struct type in C# (for types I don’t control, so I can’t just add an interface) rather than just return `Object` from a couple of methods. Type systems need to be more expressive if we’re going to be able to increase developer productivity without costing program safety.
- moreaccountspls 6y agoOr, you know, just return Object from a couple of methods. It's not the end of the world.
- rob74 6y ago...or interface{} in Go
- pwm 6y agoThere are expressive type systems around, it’s the industry at large that needs to use them more and educate future generations on why these are useful tools. I 100% agree that spending 2 days on that task is lunacy. But imagine if youcould do it instantly with 0 ceremony. At that point it would 100% worth your while.