Finally I finished the 27th video on the famous Programming Paradigms course by Stanford. It’s excellent!
It basically covers:
C programming. Functional programming (using Scheme). Jerry is an excellent teacher! Thank you for putting up the material online. Highly recommended for anyone!
I have been watching the good old Stanford CS course Programming Paradigms. The first half of the course deals with C and serves as great material for learning C. Then the course introduced threads, and concurrent programming in C with some homebrew library. The most complicated example given is this program that simulated the icecream shop. Here are the description of the problem:
This program simulates the daily activity in an ice cream store.
I was shocked during this fantastic video by Kevlin Henney
not because all the programming history that he talked about, but by one simple example of if-else statement. Here is the leap year function he gave as an example in the talk:
def isLeapYear(year) { if (year % 400 == 0) return true if (year % 100 == 0) return false if (year % 4 == 0) return true return false } def isLeapYear(year) { if (year % 400 == 0) return true else if (year % 100 == 0) return false else if (year % 4 == 0) return true else return false } Which one do you think is better?
In HandMadeHero Day6, Casey showed a neat way to load a Windows function by yourself. The senario is as follows:
In order to get game pad input working, we need the function XInputGetState, but it is in different dll files on different Windows versions, if we link directly to Xinput.lib, then we have the risk of the program won’t start if somehow the dll is not found in the system. We don’t want that to happen considering that the user may not even use a game pad.
I started to follow Hand Made Hero again, here is the source code from Day 5. I also formatted it with clang.
win32_handmade.cpp
#include <stdint.h>#include <windows.h> #define internal static #define local_persist static #define global_variable static typedef int8_t int8; typedef int16_t int16; typedef int32_t int32; typedef int64_t int64; typedef uint8_t uint8; // 1 byte typedef uint16_t uint16; // 2 bytes typedef uint32_t uint32; // 3 bytes typedef uint64_t uint64; // 4 bytes struct win32_offscreen_buffer { // Pixels are alwasy 32-bits wide, Memory Order BB GG RR XX BITMAPINFO Info; void *Memory; int Width; int Height; int Pitch; }; struct win32_window_dimension { int Width; int Height; }; global_variable bool GlobalRunning; global_variable win32_offscreen_buffer GlobalBackbuffer; win32_window_dimension Win32GetWindowDimension(HWND Window) { win32_window_dimension Result; RECT ClientRect; GetClientRect(Window, &ClientRect); Result.