Hacker News new | past | comments | ask | show | jobs | submit login

IMO this is no small part of why C still has its reputation for speed. Think how you'd write this in C. Maybe

  /*
    Recursively removes doublets from input. A doublet is a pair of adjacent chars,
    identical or differing only in capitalization (eg. "aa" or "aA"). The result is
    written to output, which must be at least input_length bytes long.
    Returns the number of bytes in the result.
  */
  size_t remove_doublets(char * output, const char * input, size_t input_length);
and the body is a dozen lines of pointer pushing and tolower. Do you faff around with malloc? unicode case conversions? hashmaps??? Of course not, that would be too hard, so you just write the stupid C code. For all its faults, the C idiom really does push you towards the simple, stupid answer to code like this.



That's also a problem with C though. Because the complex answer is such a pain to write, people go for the simple answer that doesn't handle all the cases that it actually should. Like ignoring Unicode case conversions means that it will only work as expected on English input.

Really, no matter what the language is, people need to actually put some thought into what they're doing.


Both good points. C gives you rope to hang yourself with when it comes to correctness; Rust gives you rope to hang yourself with when it comes to performance. Personally I prefer the latter, but awareness and understanding of what's really going on is important no matter what language you're using.


The other thing is say algorithm selection. Some data structures may be more performant for the job at hand, but do you really want to package or build them yourself? A lot of the time the answer is no.


Among new languages, zig aims to make all allocations obvious.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: