Cs Biggest Mistake | Prime Reacts

  Рет қаралды 69,664

ThePrimeTime

ThePrimeTime

Күн бұрын

Recorded live on twitch, GET IN
/ theprimeagen
Article: digitalmars.co...
Author: Walter Bright
MY MAIN YT CHANNEL: Has well edited engineering videos
/ theprimeagen
Discord
/ discord
Have something for me to read or react to?: / theprimeagenreact

Пікірлер: 395
@disgruntledtoons
@disgruntledtoons 10 ай бұрын
C was created by engineers who just wanted to get stuff done. After creating it, they used it to get stuff done.
@chuckcrizer
@chuckcrizer Жыл бұрын
Walter Bright is a freaking LEGEND. He wrote the Zortech C/C++ compiler. The first such compiler for PCs in the 80s. He's the real deal.
@DJCloudPirate
@DJCloudPirate Жыл бұрын
Zortech was my first compiler. It came free with a C book my parents bought me in middle school. I hadn't even thought about that compiler in decades. Thanks for the shot of nostalgia!
@chuckcrizer
@chuckcrizer Жыл бұрын
@@DJCloudPirate I like to say that Walter Bright taught me C. I read every line of source code that came with that compiler and database supliment. I even printed out all the source files. It was just over a case of wide fanfold paper.
@slawtul
@slawtul Жыл бұрын
D lang also.
@k0rnburn
@k0rnburn Жыл бұрын
Also Empire game creator
@LeviShawando
@LeviShawando Жыл бұрын
Arguably this isn't C's "mistake", the issue is that C needed to be backwards compatible with B at the time, B didn't have arrays, it had "vectors" where it was just a pointer that pointed to a memory block. For B, arrays and pointers were the exact same. This is also why you can't just directly assign arrays in order to copy them. You _can_ however get both behaviors by wrapping arrays in a struct. Structs let you directly assign each other to copy and struct sizes are known at compile time. Moral of the Story: Backwards compatibility can hurt you badly.
@dickheadrecs
@dickheadrecs Жыл бұрын
moral of the story is structs are the dongles of C
@ErazerPT
@ErazerPT Жыл бұрын
True words. One could even argue that the root of all evil (in programming) is (bad) legacy. Be that Be that BadThingsTM that you propagated into the future or GoodThingsTM that were left out of the future because of legacy. One could also argue that the whole x86 both hw and sw is a clusterfsck of bad legacy, and the only good thing to do looking forward would be to design a new (proper) architecture and run legacy emulated/virtualized. Pains me deeply having to admit that, for all it's faults, Apple was the only (major) player to consistently tell the eco to "put up or shut up". And lo and behold, they put up and moved onward/forward.
@LeviShawando
@LeviShawando Жыл бұрын
@@ErazerPT Objective-C could've been done much better. They royally messed it up.
@amateurprogrammer25
@amateurprogrammer25 Жыл бұрын
computer scientists, putting the backward in backwards compatibility since the late 1960s
@dickheadrecs
@dickheadrecs Жыл бұрын
@@LeviShawando Obj-C is a language for NScrazy people
@m4rt_
@m4rt_ Жыл бұрын
I think a language being successful is when there is a lot of people who still use it 50+ years later.
@realdragon
@realdragon 8 ай бұрын
It is fast, when I'm simulating orbits for a 100 years I don't want to wait 100 years for simulation to finish
@tempname8263
@tempname8263 8 ай бұрын
@@realdragon And when I don't want to write code for 100 years, I use something else. Beeflang for example.
@realdragon
@realdragon 8 ай бұрын
@@tempname8263 Sure, go use the thing you want or is the best for the job
@jimhrelb2135
@jimhrelb2135 Жыл бұрын
I love this style of reading RFC-like articles. Such a fresh air from the common JS dev blogpost reactions.
@Charlyzard_ssb
@Charlyzard_ssb Жыл бұрын
As a game developer, this is the first Primeagen video I understand fully from start to finish
@jerichaux9219
@jerichaux9219 Жыл бұрын
As a web developer, I hate web development.
@MrDgf97
@MrDgf97 Жыл бұрын
As a neurological nanotechnologist, I shid and cummed 💀
@GuyFromJupiter
@GuyFromJupiter Жыл бұрын
As an electrical engineer, same (mostly)
@alvarohigino
@alvarohigino 9 ай бұрын
lol
@ccgarciab
@ccgarciab Жыл бұрын
I only have limited C experience but I dealt with this problem by assuming arrays just don't exist, which isn't strictly true, but is enough to eliminate confusion. From then on, if I wanted a proper array I would define my own struct. I couldn't do much about null except programming very defensively, so that felt like a much more significant problem.
@xBiggs
@xBiggs Жыл бұрын
I mainly use C for work. The number one thing I hate is that enums decay to the underlying type.
@BboyKeny
@BboyKeny Жыл бұрын
Is "enum class" different in this regard?
@brianb2308
@brianb2308 Жыл бұрын
@@BboyKeny enum class is c++, but yeah enum class is generally typesafe in that you can't just treat it as the underlying type without a cast.
@SVVV97
@SVVV97 Жыл бұрын
And yet we can't specify the underlying type (pre C23) - it's so insanely annoying
@brianb2308
@brianb2308 Жыл бұрын
@@SVVV97 true. C++ fixes this by allowing for syntax like enum MyEnum : char {A, B, C}; But it is kind of dumb that C does get updates here and there and yet it took so long to get custom sized enums.
@svaira
@svaira Жыл бұрын
@@SVVV97 yes, and the biggest issue is in fact that the underlying type could be int16_t, i.e. only values up to 2^15-1 are safe
@pepn
@pepn Жыл бұрын
Thanks for putting the article in the description !
@svaira
@svaira Жыл бұрын
Odin has effectively this exact feature, and even uses it with the old array syntax (T[], but you have to pass the array as f(x[:]) to give the length too, see "slice")
@InfiniteQuest86
@InfiniteQuest86 Жыл бұрын
Yeah I use Odin for personal stuff now, but definitely cannot for work.
@autistadolinux5336
@autistadolinux5336 Жыл бұрын
3:30 you can use a pointer to an array and its expressed as int (*foo)[N]. In fact, you can use the VLA syntax to do this: void add(size_t size, int (*foo)[size]);
@nothke
@nothke Жыл бұрын
To me the biggest issue with C is the compilation process, the way the headers combine (and need to be manually created and maintained) and have name and macro collisions, additionally complicated thanks to lack of namespaces. Then everything else like: - switch requiring break (inherited by many other languages unfortunately) - null terminated strings - no array length.. - Edit: variables uninitialized by default - implicit casts, not just pointers and arrays - lack of bools for conditions like if (int) being legal - shadowing (very easy to have nested for loops with same "i") ..etc..
@JuusoAlasuutari
@JuusoAlasuutari Жыл бұрын
#define when break; case You're welcome. Yes, this works. It's legal to put a break statement between the switch and the first case label.
@Sealedaway
@Sealedaway Жыл бұрын
Honestly yes, keeping headers up to date is an annoying extra step that is easy to forget. I've run into some pretty cryptic bugs when changing the type of an argument from int to size_t or something because I forgot to update the function prototype in the header. The lack of namespaces is also very annoying and practically discourages you from relying on libraries lest they clash with each other. Maybe that's why C kinda has the reputation of "you need to build all your tools from scratch". I like C for doing fast physics calculations but it sucks having to reinvent the wheel all the time.
@vncstudio
@vncstudio 3 ай бұрын
@@Sealedaway You can get away with using one external library at a time after somehow forcing your editor to find it. LOL.
@EsronDtamar
@EsronDtamar Жыл бұрын
Haskell is so good that it is even a brand for hair products.
@ThePrimeTimeagen
@ThePrimeTimeagen Жыл бұрын
delete this
@airbus5717
@airbus5717 Жыл бұрын
Lol
@MrTact67
@MrTact67 Жыл бұрын
You should really have pointed out who Walter Bright is here -- he's the guy who created the Zortech C++ compiler. I also want to say. he wrote Turbo Linker.
@user-py9cy1sy9u
@user-py9cy1sy9u Жыл бұрын
The creator of D programming language
@homelessrobot
@homelessrobot Жыл бұрын
and the zortech c++ compiler was/is the first commercial c++ compiler for Windows, and maybe the first c++ compiler ever if you don't think transpilation to c counts.
@francescobrizi4940
@francescobrizi4940 Жыл бұрын
It's time to create the C** programming language, with array contents that start at A[1] and A[0] that contain the array dimention, to give new programmer more ways to fuck their code and segfault because of an unintentional change in A[0]. To make things more complicated, if A[0] does not contain enough space to store the entire lenght of the array, the compiler can randomly choose between transforming A[0] to a pointer to a bigger container or expand A[0] with A[1] without noticing, and it should be inpossible to know which of the 2 happened until a segfault happens
@dickheadrecs
@dickheadrecs Жыл бұрын
final boss: void** programming language where type annotations don’t exist at all, but if you get them wrong you brick your cpu
@isodoubIet
@isodoubIet Жыл бұрын
Somebody call the cops on this man
@LambdaJack
@LambdaJack Жыл бұрын
UNIX lredy hs tht covered.
@pokefreak2112
@pokefreak2112 Жыл бұрын
I always define my own "fat pointers" when I program in C. It's not just great for reducing bugs, you also get to create views/slices of larger arrays so you rarely need to allocate anything. Super nice pattern.
@darthvader4899
@darthvader4899 Жыл бұрын
can you please continue to cook?
@DFPercush
@DFPercush Жыл бұрын
I've been dealing with the Wasmer C api recently. The way they pass arrays is with a struct whatever_vec_t { size_t size; whatever* data; } It's not a bad idea, and intrinsic language support would be awesome. However, if you can use a C++ compiler to compile your mostly C-like code, you can use some small footprint templates to help with that. To get the size of a static array, template void foo( const MyType (&array)[N]) { c_function( FatPointer{array, N}); } I agree that being able to make sub-strings and slices without any memory allocation is great. std::string_view and std::span are staples in my code. I basically use span as the fat pointer type, as I'm sure it was intended.
@Sealedaway
@Sealedaway Жыл бұрын
I found that to be a fantastic feature in a physics simulation I've been working on. Minimizing the need for reallocations, instead keeping track of where the "meaningful data" is currently stored in a large buffer, does wonders for the performance. In a lot of situations it's easiest to have arrays keep track of their own size, but the fact that C doesn't do that encourages you to rethink how you handle your data and sometimes it gives you some chances to optimize for speed. As a physics major, I really appreciate C for that.
@Gahlfe123
@Gahlfe123 Жыл бұрын
i agree with this video, null is annoying but i feel like its mangeable as long as you understand why it exists
@yaksher
@yaksher Жыл бұрын
I think null is a bigger problem when you venture outside of C; in C, yeah, it causes some bugs, but it's a fundamental part of how things work. In Java, for example, a fallible function is not just unidentifiable from its type signature, but also failure can be either by raising an exception or returning NULL or whatever, and since objects are implicitly references, there's less clarity about which things can even potentially be NULL vs which things are safe, etc. In C, errors are done through error code returns and writing output to an argument pointer or specific value returns, and you can tell which it could potentially be from the declaration, so you have to deal with much less.
@laughingvampire7555
@laughingvampire7555 Жыл бұрын
I agree, if you know about null you can totally control it, but requires to build good habits, and people have zero idea about how habits are made or destroyed.
@PoorlyMadeSweater
@PoorlyMadeSweater Жыл бұрын
@@laughingvampire7555 Its the age old "This language is great because you have to learn to be disciplined to use it" vs "If a language requires you to be disciplined to use it, it isn't great".
@fr0zi
@fr0zi Жыл бұрын
@@PoorlyMadeSweater every professionalist has to have some sort of discipline. Would you like to have undisciplined construction workers building your house? IOr undisciplined car engineer designing you car? I wouldn't. In many professions you have to be disciplined otherwise you are risking your or somebody else's life. Only in computer programming people think that language and compiler has to save them from every mistake.
@PoorlyMadeSweater
@PoorlyMadeSweater Жыл бұрын
​@@fr0zi Yeap, thats one side of the argument. The other is the human brain isn't as capable as people like to think. Trying to entertain every possible mistake you could be making while maintaining a mental image of the entire system is impossible. Every mistake the compiler cant prevent is a land mine every pro is just one hour of missed sleep away from making. To use your metaphor, a *safe* language would require a buzz saw to contain a SawStop, a device that stops the blade when flesh is detected. A disciplined wood worker wouldn't argue against such a device simply because you *should* be good enough to not need one.
@alexanderlea2293
@alexanderlea2293 Жыл бұрын
As someone who has worked primarily in C/C++ and assembly, I actually really enjoy C strings. It's the most natural from the perspective of the computer and while (*s) is effective enough for most string parsing. I'm not saying they're perfect, and there are times where I just want the string split methods that python has, but I personally would not want to see any changes. As for the array size, just pass it as another argument. Maybe I haven't worked on large enough projects to be affected by that sort of thing though.
@alexanderlea2293
@alexanderlea2293 Жыл бұрын
And I'll take 1 C String over the 6 "Rust" Strings any day of the week.
@infastin3795
@infastin3795 Жыл бұрын
​@@alexanderlea2293same
@SimonBuchanNz
@SimonBuchanNz Жыл бұрын
​@@alexanderlea2293there's str, which is a slice of UTF-8 in memory somewhere and String, which is the mutable, resizable string. Pretty uncontroversial if you're ok with memory slices and Vec both existing. Are you counting all the pointer types like Box, Rc etc you can wrap str in? Or are you talking about OsStr, Path, CStr and all the other weird interop types? They're occasionally useful, but not a huge deal. Compare with the million custom string types people create for "performance" in C++...
@KayOScode
@KayOScode Жыл бұрын
I have worked in a very large c++ project, and it was awful. The project started in the 80s though, so it definitely used some old patterns
@alexanderlea2293
@alexanderlea2293 Жыл бұрын
@@SimonBuchanNz I was talking about the catering and osstr equivalents. It's a bit crazy to have a language which requires more than one type of string to use fundamental programming tools.
@martygusto3056
@martygusto3056 Жыл бұрын
walter bright sounds like a genuinely smart computer engineer. I hope he does not get along with his ex student jesse fuschiaman to create a cybercrime empire specializing in blue screens of death.
@20dareason09
@20dareason09 Жыл бұрын
If you love C, you will love Odin. Odin has that idea proposed in this article, in fact it offers a bit more than that in an elegant way. Odin also has map type and a string type, and more (types). Odin keeps the simplicity of C but fastforwards to the context of modern day computer architecture. When I write C code I always feel like I'm in danger. When I switch to odin I feel free, and I don't have to jam all types of abstractions into my head (*ahem* C++, rust).
@gnagyusa
@gnagyusa 9 ай бұрын
Yeah, I ended up implementing smart arrays in my C codebase. It was not a big deal, though. The only thing I'm missing from C is smarter function macros. I'm tired of the "\" line termination and the difficulty debugging them.
@HuxleysShaggyDog
@HuxleysShaggyDog Жыл бұрын
Null termination is a pain yes. So make a struct with a pointer and a length? 🎉
@sparky173j
@sparky173j Жыл бұрын
I'd pick switch-case requiring break. So many bugs have been caused by forgetting break. Add an explicit fall-through keyword instead.
@JuusoAlasuutari
@JuusoAlasuutari Жыл бұрын
#define when break; case
@sparky173j
@sparky173j Жыл бұрын
@@JuusoAlasuutari that's quite clever! In a "disgusting hack that's required to work around a poor design decision" kind of way.
@JuusoAlasuutari
@JuusoAlasuutari Жыл бұрын
@@sparky173j as is tradition in C ;)
@oleksandrnahnybida3167
@oleksandrnahnybida3167 Жыл бұрын
there are already -Wimplicit-fallthrough and attribute__((fallthrough))
@phitc4242
@phitc4242 Жыл бұрын
you code in C, I code in C, I'm just built different, so are you
@SvetlinTotev
@SvetlinTotev Жыл бұрын
In my experience with C++ 90% of the time the array size is known at compile time so I just use references to C-style arrays (typedef'd to avoid the ugly syntax). And when the size is dynamic, most of the time I need to allocate it on the heap anyways so I might as well use std::vector or std::string. All that's left are the relatively rare cases that Rust slices solve.
@IantoCannon
@IantoCannon Жыл бұрын
I like the simplicity where an array with five elements is exactly five times the size of each element. Use c++ if you want a custom array type
@IantoCannon
@IantoCannon Жыл бұрын
Another solution is to use bounds checking in the compiler options. The code runs more slowly but it is good for testing
@KayOScode
@KayOScode Жыл бұрын
C is the best language in terms of its power and speed. If you look from a customers perspective, c is always the best language for any job. The problem is the limited system library and general unsafe pitfalls developers who don’t know better (and developers who do) fall into.
@isodoubIet
@isodoubIet Жыл бұрын
@@KayOScode " If you look from a customers perspective, c is always the best language for any job. " ??? C is the wrong choice for just about any job. The number of footguns is unparalleled outside of the esolang space.
@isodoubIet
@isodoubIet Жыл бұрын
"I like the simplicity where an array with five elements is exactly five times the size of each element." std::array
@abhinavk0929
@abhinavk0929 Жыл бұрын
​@@isodoubIet never thought id dislike someone's comment and then like the next one lmao
@basione
@basione Жыл бұрын
Shoutout to Mr. Bartosz Milewski! A great academic/programmer renowned for teaching category theory to programmers. Definitely check him out if you're interested :)
@SimGunther
@SimGunther Жыл бұрын
As someone writing a simpler implementation of Monkeyscript in D, I completely stand by this article.
@DJCloudPirate
@DJCloudPirate Жыл бұрын
Why not implement the fat pointer in overloaded malloc and free functions dedicated to arrays? In theory, the new malloc implementation could always allocate a block of memory the size required for the array but include a size_t worth of bytes before the first element in the array. It would then just return the pointer to the first array element. These pointers would be fully backward compatible with all C code since the beginning of time, but if you index from the pointer in the negative direction you will be able to access the size_t that contains the size in bytes. Since C isn't object oriented the syntax for accessing this new size information would always have been done through a new library function anyway... something like size_t length = myarr.getSize(); doesn't fit in the design of C.
@TheMachina42
@TheMachina42 Жыл бұрын
The simplest way I think, is to use a composite type, with typedef, you create a struct, that contains a void* data, a size_t size, and an enum for the type, that is declared with the type width, I use this a lot you just typedef it into a nice array_t, or t_array and boom you have a simple and easy to use array. you can even go a step further, and use generic functions that are only facade to fonctions pointers switch statements to redirect your array to the correct type specific functions, based on the value of your enum. ( and in some cases if the compiler is able to see that your functions are only there to redirect your array to another functions, the compiler might replace your switch statement by a look up table reducing a bit the overhead).
@DJCloudPirate
@DJCloudPirate Жыл бұрын
@@TheMachina42 Yes, I think I see what you mean, and that is very much like what I proposed. This is due to the way C plays fast and loose with memory. Types in C are really just a means for calculating address offsets. Under the hood the languge doesn't really treat structs any differently than arrays... both end up doing just raw pointer math to get to what (you hope) is the desired data. The problem I see with the approach you propose is that having the void* first in your struct means that the size is dangling out at the end of the struct. In that case you actually have to do two pointer indirections to access your real data, first you have to dereference the struct to get to the void* that holds your data, then you have to compute the offset from that array head to get to the element you want. In my case there's only ever one pointer involved, the pointer to the first element in your array just like all C arrays. But in my case I leverage the fact that 99.9% of developers only ever do positive pointer offsets to sneak the extra size data in at a known offset from the pointer. That offset just happens to be negative.
@TheMachina42
@TheMachina42 Жыл бұрын
​@@DJCloudPirate I understand your approach, and yes, my method is clearly a very simple one. I believe many people have used this approach at some point. However, my main point is not about the implementation details, but rather about the fact that the language already provides a way (though not optimal) to handle bounded arrays. I don't think adding more to the language would be very useful in practice. It's one of those situations where people are accustomed to the way it's done in C and may not necessarily benefit from that feature even if it were implemented. Nevertheless, I find it interesting as it reminds me of how the system keeps the heap from becoming too fragmented by adding some embedded data at each allocation.
@donkeyy8331
@donkeyy8331 Жыл бұрын
I dunno, is it really that bad? maybe it's because I'm used to it, so everytime I use arrays in C I tend to make then dynamic, so I always have a variable with it's capacity along side it or if I only need one array at a specific place I will make it one index longer and put a "terminator" so I generally don't trip myself up.
@m4rt_
@m4rt_ Жыл бұрын
technically char a[] isn't exactly equivalent to char *a since if the length of the array is known at compile time, and not through malloc at run time, you can get the correct length with sizeof() ... but yeah, they are really similar.
@godofcows4649
@godofcows4649 Жыл бұрын
They are the same, though you can't change the address of a[0]. But just talking about treating them like arrays, they are the same. You're just allocating the block of bytes before run time not during; you must still keep track of the size. sizeof gets the amount of bytes during compiling because different compilers have different widths of bytes for the c's data types: unsigned char *a; a = (unsigned char*) malloc ( ARRAY_SIZE * sizeof(unsigned char) ); going with what you said, I think structs make more sense in that context: typedef struct { unsigned int data1; unsigned int data2; unsigned long data3; } myCustomDataType; myCustomDataType twoIntsAndALong = (myCustomDataType*) malloc( sizeof(myCustomDataType) ); if I explisedly said I wanted 8 bytes to be allocated, then it makes the code way less portable if a int or long for another compiler is not the same amount of width of bytes. Makes it more tedious too.
@xybersurfer
@xybersurfer Жыл бұрын
C offers structs to pair arrays with their length. it takes minimal effort, so i don't consider it a mistake. it being a systems programming language, it would be worse if you were forced to always have the length stored
@coolworx
@coolworx 10 ай бұрын
Except for the occasional screeching, I'm really enjoying this channel on my headphones.
@dziuaftermidnight
@dziuaftermidnight 3 ай бұрын
still not sure if enough people talk about the absolute beauty of a feature that C allows, that is an array pointer. if you really want to pass an array of the fixed length in the most proper way (which is, without losing it's size upon conversion to pointer), you can just pass the array pointer to the function. then, for the sake of normal syntax, you can extract the actual pointer and size of the array into different variables inside the function. only real problem with this is that you cannot pass an array of variable size, meaning you can only use it to pass arrays of certain size N across the entire program (and the size is embedded inside the array pointer).
@jakejakeboom
@jakejakeboom Жыл бұрын
If you use all the static analysis and instrumentation your compiler provides, then C is a much safer and more usable language. Without doing that, pretty much any C program over 10k lines will have some nasty undefined behaviour lurking somewhere.
@stefanalecu9532
@stefanalecu9532 Жыл бұрын
But it won't save you from logic bugs which is even worse
@warasilawombat
@warasilawombat Жыл бұрын
I’m really used to the void *buf, size_t size calling convention used to work around this problem, but as soon as this article pointed out this was a problem I was on board. This may not be the source of most bugs for us but it is such a huge tedious time sink to constantly need to pass the size of an array or create verbose sizeof() constructions just to deal with the problem that the size of the array is not part of the type. This is such a precise identification of a failure of C and its refreshing amongst all the bitching about modern language features.
@KadenCartwright
@KadenCartwright Жыл бұрын
The array as a backing data structure of a string is incidental, not core to the identity of a string. Technically it could be implemented under the hood with a linked list or a tree or other more exotic things (I know this would suck in 99.9% of cases, just pointing out that strings with another backing data structure are still strings)
@AK-vx4dy
@AK-vx4dy Жыл бұрын
It was maybe an error but this concept is not far from Rust &str or span, readliy adopted to other langugages for speed and less allocation. Surely in safer ways but cocnept is the same. Even in C++ they added it again in safer form
@CallousCoder
@CallousCoder Жыл бұрын
Assembly is code and it is data! It’s called self modifying code. I love that trick. And literally yesterday a kid asked me why to learn C. And literally my words were: “you really know how arrays works because they are not trivial to pass around.”
@stefanalecu9532
@stefanalecu9532 Жыл бұрын
So low-level Lisp/Forth?
@CallousCoder
@CallousCoder Жыл бұрын
@@stefanalecu9532 assembly language but in forth you could do the same thing since it’s a command interpreted language in which you define words. So you can generate those words based on situations and also do self modifying code. Although I hardly coded in forth. But in assembly 6502, 68000 and x86 I used it a lot.
@MaxHaydenChiz
@MaxHaydenChiz Жыл бұрын
Re: arrays and pointers, I am pretty sure this was changed somewhat in the years since this was actually written. You can specify that a pointer argument can only have length 1 (not an array), must be not-null, that the array arg must also have an arg that specifies the length, and a few other issues. Compiler support for checking this statically, is hit or miss still. But it's increasingly decent. The string thing is horrible though. I think the way that Plan 9 handled UTF was better than any other C-library I've seen. But they aren't in widespread use and probably haven't been updated to the latest unicode standards.
@AhmetTemizTR
@AhmetTemizTR Жыл бұрын
We need C-- lang. a[-1] = size and a[0] = first element 😂
@Chris-mm
@Chris-mm Жыл бұрын
Learned haskell just so I could put the sticker on my laptop and work at a coffee shop (in Python)
@Hector-bj3ls
@Hector-bj3ls Жыл бұрын
I'm consistent with how I say these things. Char is char with an H. Mut is like the dog. Say it how it's spelled.
@oualidel-feraoui1318
@oualidel-feraoui1318 Жыл бұрын
someone in the chat said "you don't talk about java. You ashamed writing it."
@sasukesarutobi3862
@sasukesarutobi3862 Жыл бұрын
You probably pronounce it like that because "char" is already a word (to burn something so that it chars), but "mut" isn't.
@johanngambolputty5351
@johanngambolputty5351 Жыл бұрын
I mean, even though you can have something like c++ with cuda or rocm, writing basically c99 for the GPU with opencl feels kinda nice.
@sepphuber7434
@sepphuber7434 7 ай бұрын
The only way to fix C is being serious about static analysis. Then it's not too bad anymore.
@OrtiOr-in1rd
@OrtiOr-in1rd Жыл бұрын
this from richard mann is a concept of a helmet hacker this worst vice that the thieves have is a much worse vice than the drugs themselves and in addition to the money it is cursed to be remotely attacking other users with those intentions that this was done predators concept
@somenameidk5278
@somenameidk5278 Жыл бұрын
holy shit someone finally said it, god i hate this. i'm too scared to use ever use raw arrays in c++ because it is so easy to shoot yourself in the foot with them
@krisdabrowski5420
@krisdabrowski5420 Жыл бұрын
I think it's fine to pronounce char as burnt because a u8 char has almost nothing to do with an actual language characters. Coincidentally it has the latin alphabet plus some other random symbols because ASCII standard, but so much of the ASCII standard isn't language characters but things like tabs, spaces, newlines, return carriage, etc. Those aren't characters! They're dark and hidden in the ASCII standard... dark as burnt charcoal.
@isodoubIet
@isodoubIet Жыл бұрын
The whole "functions and arrays decay to pointers at the slightest provocation" deal is also one of the most annoying features C++ inherited from C and a big reason why std::array exists. Stuff like this is why I struggle to take opinions like "Oh C is so simple you should use C" seriously.
@PoorlyMadeSweater
@PoorlyMadeSweater Жыл бұрын
C is like the nunchuks of programming. Its so simple, just two sticks and a piece of string, what could go wrong?
@isodoubIet
@isodoubIet Жыл бұрын
@@PoorlyMadeSweater I used to practice with those and, ironically, they're a lot safer than C.
@wdavid3116
@wdavid3116 Жыл бұрын
It took me a while but I really warmed up to python3's treatment of strings. Strings really aren't arrays they are the idea of textual data. That textual data can be encoded in different ways and when you encode a string it becomes an array. Of course the string has to be stored in memory and just like everything else it is a block of memory, but it conceptually is not an array.
@homelessrobot
@homelessrobot Жыл бұрын
but what does this get you? its conceptually appealing, but i don't know that i could actually generate a description of that conception other than the ole mathematicians fallacy of platonic beauty.
@wdavid3116
@wdavid3116 Жыл бұрын
@@homelessrobot It is similar to any other guard rail. It forces you to think about encoding and explicitly convert between the idea of text and a buffer of memory filled with encoded values. It prevents you from accidentally mixing the manipulation of text and the manipulation of an array in a way that could mess things up. It also holds your hand and makes unicode work.
@nangld
@nangld Жыл бұрын
Walter Bright is that prominent person, think volumetric Terry Davis.
@deniyii
@deniyii Жыл бұрын
Isn’t the array decay problem fixed by passing an array pointer to a function instead of passing the array directly?
@DigitalOsmosis
@DigitalOsmosis Жыл бұрын
Alternatively you can just typedef a simple struct to achieve the same improvement without needing to change the language. typedef struct my_array_t { size_t dim; char * data; } my_array_t; void foo(my_array_t a);
@MaxHaydenChiz
@MaxHaydenChiz Жыл бұрын
Haskell isn't the top of the type complexity hill. There are Idris, Agda, Coq, and other systems that have features the Haskell people wish they had.
@mishaerementchouk
@mishaerementchouk Жыл бұрын
Suffices to say C does not have a built-in type "array". All it has is quite convenient syntactic sugar for operating with contiguously allocated data and the respective conceptual wrapper. That's it. If one, indeed, needs an "array", say as in linear algebra, in C, it must be properly implemented. In contrast, Fortran and Pascal (to name close languages that are still in use) had the array type before C, which makes all references to weak contemporary hardware irrelevant. So, decaying arrays to a pointer was a conscious decision. The fact that so much can be done with so little is almost a miracle and reflects how deep was that decision.
@MH_VOID
@MH_VOID Жыл бұрын
Seeing `#include void main() { int arr[] = {0, 42, 69}; printf("%d", 2[arr]);}` (newlines stripped) print 69 really showcases this shit to me.
@Sealedaway
@Sealedaway Жыл бұрын
@@MH_VOID The fact that array indexing is commutative will never cease to amuse me.
@GiovanniCKC
@GiovanniCKC Жыл бұрын
C23-- the most recent version like just came out very recently lol, it is in fact very slow.
@JuusoAlasuutari
@JuusoAlasuutari Жыл бұрын
This makes no sense in so many different ways it's like a hypercube with all dimensions having a negative size
@GiovanniCKC
@GiovanniCKC Жыл бұрын
@@JuusoAlasuutari I'm talking about the update cycle my guy lol. Why would I be talking about literally anything else?
@JuusoAlasuutari
@JuusoAlasuutari Жыл бұрын
@@GiovanniCKC it was a little ambiguously worded
@MrAbrazildo
@MrAbrazildo Жыл бұрын
7:14, the only "unsafe design" about those is that, when the vector changes its size, it's not granted to stay at the same location in memory, so the iterators keep pointing to old address. 1 just needs to "refresh" them. But this need exists only 1 time per allocation (size changing). This is not made automatically due to possible performance. It's like web pages that are always refreshing themselves vs those waiting for the user to do it: the 1st is more comfortable, but wastes performance/resources from the machine. The operator [] hasn't this issue, because it comes all the way from the beginning. But has a performance penalty. I personally use iterators intensively. I only had this issue once. 8:55, agree. This is awkward because, for every 1 of the millions of f()s, the code will has this amount of lines. The way I use to do this is to write a macro only 1 time, calling it everywhere: #if NEWC #define arrpass(type, name, dim) type name[..] #elif C99 #define arrpass(type, name, dim) type name[dim] #else #define arrpass(type, name, dim) type *name #endif Then f()s will be written like (doesn't matter the standard): extern void foo (const size_t dim, arrpass (char, a, dim));
@quelchx
@quelchx Жыл бұрын
Rust developers are starting to sound like Python developers.
@vncstudio
@vncstudio 3 ай бұрын
lol
@Bp1033
@Bp1033 Жыл бұрын
the only reason I learned C# was because of the game Space Engineers and the desire to have automatic solar arrays and mining drones.
@DFPercush
@DFPercush Жыл бұрын
This video is talking about C. C# is a very different animal. That's cool though, I've written a few Space Engineers scripts myself. Good motivation to learn how to code, kudos for the effort. ;)
@Bp1033
@Bp1033 Жыл бұрын
@@DFPercush oh, I just saw 'Cs' and was like "*.cs", I do like C. It's my home programming language.
@DeathSugar
@DeathSugar Жыл бұрын
char stands for charcoal which is left of you stool when you've done with c's segfaults
@sergrojGrayFace
@sergrojGrayFace Жыл бұрын
C's biggest mistake is relying on preprocessor. I actually love having a powerful preprocessor, but it should be a complimentary tool. In C it's used instead of proper modules and proper constants.
@DrewryPope
@DrewryPope Жыл бұрын
this is how you should be lit in every video. 10/10 no notes.
@DrewryPope
@DrewryPope Жыл бұрын
if you aren't a specter of light reading code to me from the ethereal realm, then i don't want to hear it.
@stoneHeHenge
@stoneHeHenge Жыл бұрын
So, basically Zig addresses all Cs biggest mistakes?
@vaisakh_km
@vaisakh_km Жыл бұрын
that's why zig born
@notuxnobux
@notuxnobux Жыл бұрын
Yeah, and at the same time it produces binaries that are smaller than C binaries (using musl). Hello world in zig is just 2kb. It's a sharable static binary (no runtime dependencies) on linux.
@krux02
@krux02 Жыл бұрын
It's not just `Zig` that have solutions for this problem. It's basically all programming languages fixed this problem. Except maybe some older ones. All fix it differently and they also added a big pile of features you never asked for.
@jakejakeboom
@jakejakeboom Жыл бұрын
@@krux02irrelevant when only a few languages can be a drop-in replacement for C to do systems and embedded programming.
@diadetediotedio6918
@diadetediotedio6918 Жыл бұрын
@@jakejakeboom Nah, there are a big bunch of pile of languages that can do systems and embedded programming.
@replikvltyoutube3727
@replikvltyoutube3727 Жыл бұрын
Primagen say about Haskell programmers looking down on other ppl, but has he seen APL programmers
@mage3690
@mage3690 Жыл бұрын
The D lang is great, BTW. I've never touched it, but just reading the docs gives me the warm fuzzies. It's like someone read the Arch wiki and said "we need that, but for a programming language."
@NikolaNevenov86
@NikolaNevenov86 Жыл бұрын
Honestly...playing with C for the past two years, as a hobbyist....I think the thing does what it supposed to do. It's low level. An array is not converted to a pointer, it always is a pointer. The ability to do array[i] , to my knowledge, is just compiler syntax sugar to make code more readable. In the end an array appears to know only it's size in bytes and it's starting memory position. Thus this is basically the cheapest(in terms of memory) way to describe an array. What the guy is asking back in 2009 could be easily achieved with a struct. He could store the type, size in bytes, and length and a void pointer to the start of the memory address. To me the article sounds like a non C programmer complaining about C. And as someone who came to C from python I still have my annoyance with the language.
@NikolaNevenov86
@NikolaNevenov86 Жыл бұрын
@@pineberryfox well to me it feels arr is just an object that along with it's pointer it holds the size of the data block in memory. And the size of the stride(type) it should read. While the pointer just holds the memory address. So an array to me is just a pointer with extra info about the size and stride of the memory address.
@jerrygao1495
@jerrygao1495 Жыл бұрын
i use c and nim,they feels like js and react,perfect
@AJMansfield1
@AJMansfield1 Жыл бұрын
4:04 "char" is pronounced the way it is specifically so it rhymes with "star" when pronouncing that oldest most fundamental type, char*.
@AK-vx4dy
@AK-vx4dy Жыл бұрын
I was top one thing i envied C programmers - this mistake - in 1990 era Pascal... when i was young, brave and stupid ... now i'm only experienced stupid ;)
@tokiomutex4148
@tokiomutex4148 Жыл бұрын
C's biggest mistake: it's not Rust
@ThePrimeTimeagen
@ThePrimeTimeagen Жыл бұрын
gotem
@mattias3668
@mattias3668 Жыл бұрын
This would require that &array[index] returns an array rather than a pointer, and pointers and arrays would no longer be compatible - big fat No thank you. Also strings don't just need NUL termination because the array size is unknown, it needs it because the array may be larger than the string.
@jarvenpaajani8105
@jarvenpaajani8105 Жыл бұрын
It's weird i also many times feel like writing C, but then end up feeling like shit 😂 I think its cause every time i think how something is in memory i think it as a c struct, so i unintentionally think in C
@jarvenpaajani8105
@jarvenpaajani8105 Жыл бұрын
I think
@ThePrimeTimeagen
@ThePrimeTimeagen Жыл бұрын
i think the same things when i thought about thinking
@jasondoe2596
@jasondoe2596 Жыл бұрын
_Cogito, ergo sum_ This poster *definitely* exists.
@Sayan_Shankhari
@Sayan_Shankhari Жыл бұрын
lack of fancy libraries and bad habbits of using them in other languages
@harleyspeedthrust4013
@harleyspeedthrust4013 Жыл бұрын
lmao I wouldn't call "hasklul" the pinnacle of programming languages. idris for example is more powerful than haskell and more high level. APL is another one that's difficult but extremely powerful in a different way. i have no experience with lisp but apparently you can do crazy meta stuff with it. i do agree that rust is a step below haskell though. note: i'm using the blub scale here (blub programmer scale)
@davidfrischknecht8261
@davidfrischknecht8261 11 ай бұрын
I would say the most successful programming language is the one used in the most projects.
@coder_foo
@coder_foo 7 ай бұрын
It's weird that C functions are aware of the size of lower dimensions of multi-dimensional arrays, but not the first dimension. Pass a 1D array to a function. The function knows the size of the objects, but the array "decays" to a pointer. Like having a string of beads, but it doesn't know how long the string is. Pass a 2D array. The array decays to a pointer to the first sub-array. It knows the size of that array. Like a spreadsheet, where the function knows the size of each row and cell entry, but has no idea how many rows there are. Pass a 3D array. Now it's a pointer to a 2D array of defined size. Like a multi-layer cake - the function knows the sizes of each layer, but no idea how many layers there are. Why is the first dimension the exception?
@deado7282
@deado7282 Жыл бұрын
C is the only S-tier language
@dovh49
@dovh49 Жыл бұрын
I really like V Lang. It is largely based off of Go but has built-in monads.
@nighteule
@nighteule Жыл бұрын
The V stands for Vaporware 😎
@dovh49
@dovh49 Жыл бұрын
@@nighteule I've been using it with much success! There's some features that would be nice to have. But for a newer project it works quite well.
@zytr0x108
@zytr0x108 Жыл бұрын
Can’t you just make a struct with a pointer and a size component?
@pillmuncher67
@pillmuncher67 Жыл бұрын
Fun Fact: Bartosz Milewski is from Poland, so his name is pronounced more like Bartosh Milleffski.
@notuxnobux
@notuxnobux Жыл бұрын
My main issue with C is error handling. To properly handle error cases in C you pretty much have to use goto and initialization checks. This is fixed by defer/errdefer in some languages. Then the second big issue is null terminated strings. Unfortunately operating system api also rely on null terminated strings (for filepaths).
@Jmcgee1125
@Jmcgee1125 Жыл бұрын
The advantage of C error handling is that you don't have weirdly jumpy logic. You see the error handler right there where it would actually run, and if you want a parent to handle it then set errno and return -1. I suppose I'm just a fan of that sort of design. Python's not as bad since you can wrap only the errorable call within the try block since it's scoped inline with the function. Then it works similarly to C's `if ((rc = badfunc())) { /* error */ }`
@oleksandrnahnybida3167
@oleksandrnahnybida3167 Жыл бұрын
@@Jmcgee1125agree,tried Zig with defer/errdefer/try and it was kinda hard to follow error handling path for me after C
@notuxnobux
@notuxnobux Жыл бұрын
@@Jmcgee1125 By error handling I dont just mean the check of the error, but also cleanup of resources. You have to jump around a lot in C if you want to do that properly, unless you want to do free(aaa); free(bbb); free(ccc); in every single if statement. You cant let the parent handle fully since you would have to also pass the resources to the parent to free. It's this connection between resource management and error handling that is the pain.
@Jmcgee1125
@Jmcgee1125 Жыл бұрын
@@notuxnobux That's more an issue of not having a garbage collector or automatic destructor than an issue of error handling. You'd still have to do that in another language if allocations weren't automatically cleared.
@AvalancheGameArt
@AvalancheGameArt 10 ай бұрын
You are supposed to know how much data is in something you have declared. Pcs be like beep boop, they don't know what you want or how to do it. you tell them how to do it with what they can do.
@victorarnault
@victorarnault Жыл бұрын
Go lang was created in 2008.
@FireDragon91245
@FireDragon91245 Жыл бұрын
what is it with the sagfaults when i first startet c it took 2 weeks of writing programms to get my 1. sagfault (a +-1 bug)
@notuxnobux
@notuxnobux Жыл бұрын
Walter Bright created the D programming language
@k98killer
@k98killer Жыл бұрын
Pernacious? Wasn't he a church father from Exaldrandia?
@adama7752
@adama7752 Жыл бұрын
No, a foo(char a[..]) hides the dim parameter. In C, making things explicit is the goal.
@InfiniteQuest86
@InfiniteQuest86 Жыл бұрын
Yeah I truly cannot understand what the complaint here is. It makes no sense. If you want a length, pass that in with the other argument. Wtf??
@itellyouforfree7238
@itellyouforfree7238 Жыл бұрын
I think the point is that if you require programmers to pass a length and a pointer as two separate arguments then they can get out of sync by accident (programmer's mistake), whereas here the suggestion is to have an array type that inherently knows its own length, which gets communicated automatically when passed as an argument. This is basically what a slice (`&[T]`) does in Rust.
@InfiniteQuest86
@InfiniteQuest86 Жыл бұрын
@@itellyouforfree7238 That seems like it has equally as many dangers. How can this be done accurately? Maybe you can track a max length...maybe. But then you still would have to pass in how much of the array you have filled in, so you don't actually get a win. In fact, by saying it tracks the length and using that field, you will introduce way more bugs when programmers rely on the length that is wrong since is not actually how much of it is used. By having to explicitly pass the length, you are telling the programmer, hey you better keep track of this and tell me the right value which avoids a ton of bugs, not introduces them.
@isodoubIet
@isodoubIet Жыл бұрын
@@InfiniteQuest86 You're conflating length and capacity.
@itellyouforfree7238
@itellyouforfree7238 Жыл бұрын
@@InfiniteQuest86 Think of it this way: "smart arrays" that own their buffer ought to have both a capacity and a length (how much is actually initialized and valid); "slices" that do not own their buffer may only have a length, since they are merely a view inside a buffer owned by someone else. At least, this is how `Vec` and `&[T]` work in Rust.
@PlanetComputer
@PlanetComputer Жыл бұрын
thanks prime
@br3nto
@br3nto Жыл бұрын
4:09 nooo! It’s gif as in gill… and mut as in nut and char as in charcoal… everyone one knows that… any other pronunciation is just people taking the piss
@michawhite7613
@michawhite7613 Жыл бұрын
I just pronounce "char" as "character"
@FusionHyperion
@FusionHyperion Жыл бұрын
technically you can do OOP in C and it's a nightmare
@JuusoAlasuutari
@JuusoAlasuutari Жыл бұрын
Technically you can have a rocket-powered bicycle. C being the rocket.
@bzboii
@bzboii Жыл бұрын
holy shit its bartosz milewsky rearing his head bc you mentioned haskell and cpp in a video
@NickPaul41
@NickPaul41 Жыл бұрын
As a youtube only watcher. How do you dig up the old articles?
@ThePrimeTimeagen
@ThePrimeTimeagen Жыл бұрын
reddit.com/r/theprimeagenreact
@airbus5717
@airbus5717 Жыл бұрын
D is really good
@sprytnychomik
@sprytnychomik Жыл бұрын
If gif is jif then git is jit and gift is jift?
@ThePrimeTimeagen
@ThePrimeTimeagen Жыл бұрын
big if true giant will be jiant... my life is completely in shambles
@davawen9938
@davawen9938 Жыл бұрын
null terminated strings are the single biggest mistake for me. so inefficient. so annoying to work with. so error prone. all of that just to save one (16 bit), three (32 bit) or seven (64 bit) bytes of memory. it makes me so sad.
@Tabu11211
@Tabu11211 Жыл бұрын
you're right
@Tabu11211
@Tabu11211 Жыл бұрын
bar gif
@Ryan-in3ot
@Ryan-in3ot Жыл бұрын
cant you just typedef a struct with a pointer and a size_t? Or... pass in the length of the array as the second argument? I dont understand how this is "the fundamental mistake" of C.
@user-py9cy1sy9u
@user-py9cy1sy9u Жыл бұрын
Technically you can but the endless list of buffer overflows means people dont do that.
@isodoubIet
@isodoubIet Жыл бұрын
Ok now make the standard library take that instead of arrays. You can only go so far without environment support.
@Ryan-in3ot
@Ryan-in3ot Жыл бұрын
@@isodoubIet what functions in the c standard library even take in arrays?
@oleksandrnahnybida3167
@oleksandrnahnybida3167 Жыл бұрын
@@isodoubIet if it is not string i don’t see where is issue wifh this approach
@isodoubIet
@isodoubIet Жыл бұрын
@@Ryan-in3ot None, because you can't pass arrays with C. Functions that taken pointers meant to represent arrays though? Lots of them. scanf, strlen, strcpy, qsort, bsearch...
Code That MURDERED 6 People | Prime Reacts
17:57
ThePrimeTime
Рет қаралды 254 М.
Haskell Is Faster Than C | Prime Reacts
31:46
ThePrimeTime
Рет қаралды 141 М.
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН
Java 21 Is Good?! | Prime Reacts
27:08
ThePrimeTime
Рет қаралды 257 М.
Zed Editor Overview | Linux Quick Start
10:34
Brian Cooper
Рет қаралды 63 М.
32-bit Computer Inside Terraria? | Prime Reacts
29:04
ThePrimeTime
Рет қаралды 415 М.
how NASA writes space-proof code
6:03
Low Level
Рет қаралды 2,4 МЛН
Forest City: China's $100BN Mega Ghost City
15:05
MegaBuilds
Рет қаралды 4,2 М.
Jblow Talks About Rust, Jai, And More | Prime Reacts
22:50
ThePrimeTime
Рет қаралды 136 М.
miss the good old days...
1:49:52
Ambient Crafts
Рет қаралды 2,7 МЛН
Stop Being A JR Software Engineer | Prime Reacts
22:04
ThePrimeTime
Рет қаралды 374 М.