11 ms·
I am student and I like C, I've tested Rust/Go, I like the feeling of C. Maybe that sentiment will change later, but for now, I like C. It's simple and sharp an
by erelde 10y ago
I am student and I like C, I've tested Rust/Go, I like the feeling of C. Maybe that sentiment will change later, but for now, I like C. It's simple and sharp and there's lots of doc/books.
- floatboth 10y agoHave you tried doing string manipulation in C? ;)
- boduh 10y ago+1
- erelde 10y agoYou can see two of my current school assignement on Github. I try to avoid manipulating strings as much as possible. ;)
- asveikau 10y agoNot OP, but I actually think string manipulation in C is really elegant. Many people who complain about it have too many allocations in their code and are trying to port the allocation-heavy non-C way of thinking to C. The C way I know focuses mainly on character at a time iteration with emphasis on not copying the source string. I'm reminded of a time a colleague needed something like string.split, and working in c++ he filled a std::vector<std::string> with the result. Using a more C way he'd really only have needed a couple of pointers on the stack.
- imron 10y ago> The C way I know focuses mainly on character at a time iteration Ah, yes, the good 'ole C way that only works reliably in English.
- dbaupp 10y agoIt's a little naïve to think it works on English without the coöperation of the users. (Also, less glibly, things like emoji seem to be becoming more and more popular.)
- imron 10y agoIndeed. In fact as we speak I am fixing a bug related to string handling with emojis.
- asveikau 10y agoFunny. You can parse utf-8 character at a time. Some characters advance the pointer by 4 at an iteration and some less.
- dbaupp 10y agoWhat do you mean by "character"? If you mean code point or "unicode scalar value", sure, but if you mean user-visible character (grapheme), it's much more complicated: even something "simple" like ö could be one or two code points.
- asveikau 10y agoI mean your iterator is char* and you advance it by adding. That's it. I do NOT mean that char itself corresponds to a glyph or codepoint, you are seriously preaching to the choir making that lecture to me.
- fauigerzigerk 10y ago>you advance it by adding And when do you stop? UTF-8 strings can have zero bytes in them so treating them as C strings is potentially error prone depending on the context.
- asveikau 10y ago
- Manishearth 10y agoFWIW in Rust you also tend to avoid allocations, since all string manipulation is done via slices -- safe (ptr, len) pairs. It's pretty neat. IIRC C++ is getting slices too, so it might be able to get better APIs around string manip. But I've seen decent string manip code that avoided allocations.
- burntsushi 10y ago> Using a more C way he'd really only have needed a couple of pointers on the stack. This is pretty much how it's done in Rust too via slices. For example, the standard way to split a string is to create an iterator and it won't do any allocations.
- IshKebab 10y agoC seems relatively simple, but it's also incredibly easy to do the wrong thing usually without realising it. That's the problem. I suggest you read up about 'undefined behaviour'.
- stevedonovan 10y ago'sharp' would be a good word ;) There's lots to like about it but writing good safe C is harder than it looks.