Rant: I worry about devs learning from leetcode

238 points jkoudys

I'll start by saying I like the site. I think the puzzles are fun and they're neat little challenges to get you to stretch your brain and solve riddles. But leetcode is as close to building an actual project as solving crossword puzzles is to writing novels. I'm sure there's a lot of skills overlap but they're not the same thing at all.

My real issue with it is its multi-language nature gives Rust a big disadvantage. It's hundreds of thousands of devs all optimizing performance mostly for languages like Python where you've made some severe missteps if you're optimizing to that level in the first place. But Rust isn't getting to shine on any of its strengths because the mindset is to strip down everything to the minimum needed for just that puzzle.

Why is this so bad for Rust? Because these optimizations mostly get figured out by LLVM already, but a whole generation of devs is being trained make code that looks like it was written by the criminally insane. eg there was one yesterday that was essentially a string deserialization problem. Here's a string where it's some digits for a phone number, a letter for gender, two digits for an age (sorry, centenarians!), a couple more for seat #, etc. take a Vec of those codes and say how many are over 60 years old. The only lower-level optimization I can see that the compiler might miss is that you don't need to parse the age into a number to compare, you can check the string as bytes against b'6' and b'0'. Sure that's a fun little trick that could pay off to optimize a high-use codepath, though practically it's more likely to cause a bug a year later. But my real issue is the rusty approach works so well but gets ignored. Define a struct, phone # string, age usize, gender as its own enum, etc. Rust is perfect for writing readable code. But if my test binary is compiled to do nothing but check the age, a compiler is very good at going in and seeing that a field isn't read so don't bother getting it. I'm encouraged to write shittier code with no benefit because of the culture of some puzzle book website.

The things that I consider valuable skills in Rust don't get developed at all. I'm not writing reasonable error enums to describe my fail cases, just relying on a "constraints" section and panicking everywhere. I don't think about what good traits would look like, or finding existing ones to impl. I'll never write a macro, or even derive one onto a struct. I don't think about where I define Copy, Clone or Send.

But people are actually hiring based on this stuff and that's what's scary. Many are conceived of as exercises in writing as hideous a for loop in python as you can. And I don't think I'd read as many break and continues on labelled loops (bordering on goto abuse) in one afternoon of reading solutions than I had in 5 years of building real world solutions with Rust.