Hello everyone! Welcome to another one of my blogposts! I heard AI is popular in the world right now, but why would this blog cover anything thats actually useful and up to date from the past 20years. No, we are going back to atleast the 90's with every single one of these. Every single piece of code that was writen on this blog can still natively run on a 32bit intel cpu from before 2010. Good old pentium 4. Anyways, lets cover why do dynamically typed languages exist. And to be honest, I have no idea. Imagine someone showed you this code: ``` void* Width = 640; void* Height = 480; void* main() { void* a = SDL_Init((void*)SDL_INIT_EVERYTHING); void* win = SDL_CreateWindow("", 0, 0, Width, Height, (void*)SDL_WINDOWPOS_CENTERED); SDL_ShowWindow((void*)win); if(a < 0) error((void*)1, (void*)0, (void*)"Window failed"); if(!win) error((void*)1, (void*)0, (void*)"Window failed"); while(1) { std::cout << "Not really a frame delivered\n"; void* event; while(SDL_PollEvent((void*)&event)) {} } } ``` "Everything is a void pointer, I can't follow this code at all", you might say. And you would be correct. Imagine trying to debug this issue without a proper debugger. Absolutely impossible. If the code is code is not complete garbage, you might be able to guess, that most likely due to accessing memory of a different type incorrectly, but yet, its memory safe. So what could a segfault mean? It could mean absolutely anything. Now whats the advantage of this dynamically typed code? Apparently, the fact that its more readable if you remove the void* to have no explicit types whatsoever, so lets remove them! ``` Width = 640; Height = 480; main() { a = SDL_Init(SDL_INIT_EVERYTHING); win = SDL_CreateWindow("", 0, 0, Width, Height, SDL_WINDOWPOS_CENTERED); SDL_ShowWindow(win); if(a < 0) error(1, 0, "Window failed"); if(!win) error(1, 0, "Window failed"); while(1) { std::cout << "Not really a frame delivered\n"; event; while(SDL_PollEvent(event)) {} } } ``` And now, we have apparently reached the heaven of dynamic typing. The code is 100% unreadable without using the documentation for sdl library, or atleast a 20GB IDE to store all the documentation for you. What a piece of piece of glorified garbage this truly is. This comes from back when we only had numbers to store, but those were indeed still had their types aligned propertly, = based on where were they stored. rax = 64bit (nobody knows what the r stands for) eax = 32bit (extended a register extended) ax = 16bit (a register extended) al/a = 08bit (a register) b/c/d also works ofc Now however, as we have more and more types, dynamic typing makes less and less sence. Imagine you would have to debug this code if it broke down on a moderate intel celeron machine? Impossible to say the least. The worst thing is there is nothing such as an invalid type, therefore its not be handled by the compiler(propertly), but everything has to handle it by the developer, which often means its not propertly handled. Or, it is built upon hundreds of dependencies in a chain, which is even worse. There should only be 3 types that can be directly used inside a function directly, which is a number(e. g. 1), a string(e. g. "Hello, world"), and a pointer, instantiated from a variable(e. g. &something) or directly from a memory address, however in that case it should be casted propertly(e. g. (uint8_t*)0xA0000), if its not one of these types, it should be clearly defined in the same file or casted(such as: (Color3){200, 255, 128}) Every struct or class's type should be defined atleast once in the code for a specific variable. Why? Debugging an invalid class input error is impossible, if you dont know which one. One variant people also choose for their code is to append the type to the variable name like so: Movie_List(List inside), but whats the point of defining it inside the name, when you can just define its type. Now, I am not telling anyone to use an intel celeron, but imagine your IDE is just not setup propertly yet? Wouldnt it be a nightmare to debug anything like it? Anyways, that will be all for today, see you next time.