3 ms·
Speaking of learning many languages, something I noticed is that once you know 20+ languages, you can learn to recognise "accents" that programmers have, especi
by jiggawatts 5y ago
Speaking of learning many languages, something I noticed is that once you know 20+ languages, you can learn to recognise "accents" that programmers have, especially programmers that know only one or two and pick up one additional language.
There was one moment where I was standing across the room from a colleague, and just from the syntax highlighting colour scheme combined with the blockiness of the code I could tell they were writing PowerShell with a "VB script accent". Upon closer inspection the script totally looked like someone thinking through the problem "in VB" and then translating that statement by statement to PowerShell.
I've seen people try and shoehorn LISP into vanilla Java, which is just hilarious.
The most common example where it causes a real issue is people writing SQL with a "procedural style". This kills the database server and makes the DBA cry.
Another striking example is this example of JavaScript written with the accent of a mathematician: https://raw.githubusercontent.com/enkimute/ganja.js/627711f9a8a84d131083adc32883073b52c86445/ganja.js https://raw.githubusercontent.com/enkimute/ganja.js/627711f9...
- DonHopkins 5y agoClassic Java teaches you to stutter and repeat yourself again and again.
- jiggawatts 5y agoLots of languages have that problem. Both C++ and Rust makes you repeat the same identifier/literal over and over unnecessarily. The C++ language at least has an excuse: it was designed in an era where separate compilation was critical because of limited memory. Compilers were expected to work with just hundreds of kilobytes of RAM! But Rust has no such excuse, as it was designed in an era where 100% of its user were on 64-bit platforms.
- tialaramex 5y agoWhat examples are you thinking of where Rust makes you "repeat the same identifier/literal over and over unnecessarily" ?
- jiggawatts 5y agoA trivial example is simply a struct type and its "impl". You're already repeating yourself there, but if you want a more concrete example, have a look at what it takes to refactor even trivial pieces of code in Rust: https://tinyurl.com/56zny85x https://tinyurl.com/56zny85x
- tialaramex 5y ago> A trivial example is simply a struct type and its "impl" You're not obliged to implement a type straight after defining the type itself, so without repeating that identifier Rust has no way to be sure which type it is you want to implement. You particularly might want to define several types up front, and then write impl blocks for them later. > have a look at what it takes to refactor even trivial pieces of code in Rust For many similar refactoring jobs Default is adequate. Here Default's derive macro obviously won't guess that you think "blah!" ought to be the default string for some reason (or that miraculously a few lines later now "test" is the default). However it seems like the correct choice here is to implement Default for your new struct ? And you do eventually get to that. But on the way there you go off on a tangent to provide implementations for any arbitrary AsRef<str>, a feature the "equivalent" C# code didn't offer but which apparently was a compelling need for this "refactoring". The types change radically too. If you don't go off on that tangent, you can use Self as you expected, and your solution is much shorter and more robust but does the same thing as the C#. Or, you could modify the C# so that it is fully generic like your Rust solution, after all the Rust solution is able to take any string-like parameter type and the C# only works with the language's built in strings. While you're in there remember that C# "Strings" aren't like Rust's strings, they're just Vec<u16> in Rust terms. There's no promise that these are actually Unicode text. They probably are text but they're only promised to be some even number of bytes presented as ostensibly UTF-16 code units for your convenience.