[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
C is fucking retarded
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 29
Thread images: 2
File: assclowns.jpg (192 KB, 1216x816) Image search: [Google]
assclowns.jpg
192 KB, 1216x816
OK, /g/, I hope someone can give me some insights in this.

C is retarded.

No, I am not talking about that whole pointer thing. Variables storing the addresses of other variables is fucking ingenious.

I am also not talking about various overflow methods. If your code overflows your memory, it's your fault, and your fault alone for not making sure that you have enough memory reserved.

But there is one thing that effectively destroys C for me. It's something that is so elemental that, from what I can see, most people don't even think about this anymore.

It's the fucking null-termination of strings.

"Oh, you want to write a file with the name of what's stored at that address? No problem - BUT IT HAS TO BE NULL-TERMINATED!"
"You want to resolve the domain 4chan.org? Go ahead - BUT WHAT YOU GIVE ME MUST BE NULL-TERMINATED!"

In case you don't get what I mean exactly: the fact that most programmers use null-terminated strings in their APIs effectively kills my efforts to program zero-copy algorithms - which means that data is not copied even once. You have a file in which file paths are stored. But instead of the fucking null byte, at the end of each path is a line feed (\n). How do you pass the paths to an I/O function?

"But anon, just replace the line feed with a null byte, and you're good to go!" - and what if the file was mapped into memory read-only? Change the file mapping method, so that ugly copy-on-write is executed?

My question is on what drugs Dennis Ritchie must have been at the beginning of the 70s when he came up with that retarded concept of null-termination. It's retarded. R-E-T-A-R-D-E-D. And we are carrying this retardedness with us for 42 years now. What were they thinking?! What are we still thinking that we didn't get rid of this crap? Is backwards compatibility really that important for such an elemental - ELEMENTAL - component of our software infrastructure?
>>
>>52006118
You're dumb.
>>
>>52006144
And you are retarded as well, because if you had anything worthwhile to write, you would have done so already.
>>
>>52006144
This desu senpai
>>
>>52006196
literally git gud
>>
>>52006272
Alright, tell me how I should git gud and STILL utilize zero copy.

Protip: you can't.
And if you fail to realize that, then you are even more retarded then null-termination is.
>>
I am in agreement about strings in C being the absolute worst. The standard library and C++ only make things worse.

And it's far from a solved problem today:
https://sourceware.org/bugzilla/show_bug.cgi?id=19390
>>
Op this bothered me too, had to use assembly alongside the c program but that took far longer than i would have liked because I knew if I made a mistake I would have to debug and that's soul crushing.
>>
>>52006118
For me it's header files.

Especially when modules where available at this time.
>>
Is there a replacement to C? Like a complete replacement. Genuinely curious.
>>
>>52006118
Null termination in C was a concept developed via the general communication protocol used in that time. Communication protocols back then had one way traffic (because we can't into async), so a sender has to send all he has, and send a piece of data that marks the end of that communication transaction.

This null termination provides a sense of control over your data. It is a marker that holds no other significant purpose other than to tell the receiver that it has completed.

Appreciate old technology, and work around it. If you really detest it, find a way to change it's behaviour.
>>
>>52006417
Modules are available in C as well - they are the various ".c" files that get complied into object files.
Header files are cool, IMO. If I want to learn about an interface, I can just look into the header and learn how the API is exported.
The only problem here is that most projects are so badly written that it's a miracle they are still used - example? Take zlib for example and try to figure our how you can make it recognize gzip data instead of deflate data.

>>52006422
Some people say that C++ is a good replacement. I usually laugh at these people, because they don't know zero-copy either.
>>
Is D usefull at all, or is it just C/C++ loaded with even more bandaids and bullshit.
>>
>>52006431
I challenge that opinion - use a protocol that first takes a hex number indicating how much data is in the message at all, put a line feed after that, and then put your payload there.
If they only did that for HTTP ... and yeah, HTTP is retarded as well.
>>
Question: could be possible to implement a function of some sort that more or less says:

IF reading from file==TRUE
define \n=\0;
read file
>>
>C invented pointers
>Ritchie invented null termination
Seriously, f-a-m?
>>
Thank fuck I use Rust.
>>
>>52006701
Yeah, well, I like to free my object when I want it, and not when a function that uses it returns. And I'd have to add (slightly more, but still more) code to prevent that. Also unnecessaryly slow.

>>52006608
Cut the pseudo code and write what you want to know. What is n supposed to be? Do you want to implement a check if a file is readable before you write it?
And if that's the case - Yes, but there is the possibility of a race condition. You cannot read a file until the operating system told you you can do it, even if you checked before if the file is readable.

>>52006636
I never wrote "invented". I wrote "came up with that concept". It's ambiguous.
>>
>>52006388
>he doesn't know about NSString
>>
>>52006431
No it wasn't, NULL termination is because memory limitations at that time and memory access design.
Basically you have two options, either append a NULL or prepend length.
Ritchie went with NULL because 8/9bit count would limit the string length and maintaining it would be more complex.

In the end only real downside of NULL is that you can't use NULL.
>>
File: trueartisangsty_4507.jpg (40 KB, 350x228) Image search: [Google]
trueartisangsty_4507.jpg
40 KB, 350x228
>>52006118
php as seen by php devs
>>
>>52006118
C would be perfect if it used pascal strings or something, anything, else.
>>
>>52006856
>NSString
why does everything in objective C start with NS ?
>>
>>52006778
\n=linebreak
\0=null termination (for strings)

The idea was to tell the program "Ok bub, the OS just passed you this file m'kay? Now read what's written on it but remember that every linebreak is to be treated as a NULL. Everything clear? Good."
>>
>>52006778
>It's ambiguous.
It really isn't though, he chose to use those primitives in C.
It's like saying he came up with the concept of onions, when he created onion soup.
>>
>>52006309
>null-termination

You keep using that phrase. There is no such thing.

A one-L NUL, it ends a string,
A two-L NULL points to no thing
(But I will bet a golden bull
That there is no three-L NULLL.)

As for your "problem", the reason is quite simple, with NUL-terminated strings you don't need to predetermine the exact (only the maximum possible) length of a string when allocating memory for it, nor do you need to store (nor update if changed) the string's length at any time, you can always determine it on the fly (via strlen(), for example) if needed.
>>
>>52006422
Assembly
>>
>>52006504
>If I want to learn about an interface, I can just look into the header
Or you could look into your API browser or the documentation the way it is supposed to be.

Modules aren't c files, as they aren't included in each other in a symbolic, sane way.
>>
>>52006550
>use a protocol that first takes a hex number indicating how much data is in the message at all
Precisely this was to be avoided. By your logic, any string would need to be a struct holding an integer (denoting the length) and then an array of chars (holding the string itself). If you need it, implement and use such string handling yourself, but don't demand that all the rest who don't need it have to use it too.
Thread replies: 29
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.