it's just very dense and doesn't exactly communicate its intentions.
I agree... but comments are nice for this.
For example, there's already functions called islower() and isupper(). It's easy to write x >= 'A' && x <= 'Z' but at the same time isupper and islower exist for a reason.
That's true, but the reasons I avoided them were:
- they are library functions, so they may not be readily available, wasn't sure in that case
- it's locale dependant, if I'm not mistaken, which can cause really strange bugs if you're not cautious ('é' for example can return True for islower, and if it's the case, you'll get a segfault when fetching the char in the const char)
- it's slower, even more so if you test isalpha then islower/isupper, and if you work in plain C, I'd argue that you may care about speed
The 'b' - 'A' thing is also confusing. I mean again it's not rocket science but it does take some brain cycles to figure out what it's doing.
I guess it does, but I may have done too many low-level programming and assembly, it's easier to read for me than a bunch of tolower() and fetchs in const strings...
I may be the strange guy there, though.
At the end of the day, you'll read faster the kind of code you'll usually write, anyway.
When you're staring at code 10 hours a day and / or debugging a nasty problem, you want to spend as little time as possible thinking about what it does.
I know... I do less actual coding now than a couple years ago (although a LOT more CS teaching, and believe me, reading code from average students is miles harder than anything fancy from actual programmers ^_^ I have a bunch of students that fancy using, in Python 3k, x//=1. to get the integer part of x... talk about a strange idea)
don't get me wrong, just as a matter of preference I would go with something I can understand without spending any brain cycles on it.
Oh, I perfectly understand your concerns... I was truly curious about what was the hardest part exactly.
Again, since I'm teaching a lot currently (to beginners, but not C... Python and CaML), so I'm interested in anything that could be natural for me and hard to understand for others. Especially since I'll do strings soon (but in both Python and CaML, there's no implicit casts between chars and ints, so you can't do anything like this, anyway).