RANDOM BITS

A random site by a random clueless human

Random bits of programming, math, and thoughts By a clueless human

2025 Blog Archive (2025)


A Look Into Virtual Table via Assembly

August 20, 2025

Polymorphism is an important feature of Object Oriented Programming whereby one can represent an object in different forms, hence the name. However, its implementation between Java and C++ which could bite you if you are not aware. This blog is going to explore the following topics: Static Dispatch The need for virtual functions Dynamic Dispatcher - Looking Into Assembly Virtual Pointers and Virtual Tables Static Dispatch Here’s a snippet of Java code that would behave differently in C++: class Shape { public void draw() { System.out.println("Shape"); } } class Triangle extends Shape { public void draw() { System.out.println("Triangle"); } }...

Read More...


The Issue With Default in Switch Statements with Enums

July 5, 2025

Reading the coding standards at a company I recently joined revealed to me the issue with default label within the switch statement and why it’s prohibitted when its being used to enumerate through an enum. default label is convenient to handle any edge cases and it’s often used to handle errors. However, when working with enums, it is often the case that the prpogrammer intends to handle all possible values in the enum. To catch this mishap, programmers would enable -Wswitch or -Werror=switch to their compiler. For instance, let’s suppose I have an enum named Suit to represent the different...

Read More...


this: the implicit parameter in OOP

February 11, 2025

I was recently reminded that the variable this is an implicit parameter passed to all methods in OOP such as C++. We can observe this by comparing a regular function vs a method belonging to some class: #include <iostream> void greet() { std::cout << "Hello World\n"; } class Human { public: void greet() { std::cout << "Hello World\n"; } }; int main() { greet(); Human human = Human(); human.greet(); } Output: $ g++ test.C $ ./a.out Hello World Hello World Furthermore, their resulting mangled names do not indicate that the function/method takes in any arguments: $ nm a.out | grep...

Read More...


view is just vim

January 24, 2025

I recently found out accidentally at work that vim and view were the same thing when I happened to be editing a file on view instead of my beloved vim editor. Note: This is a follow up post from my microblog For context, view is often used in lieu of vi when trying to open a file for read only while retaining the same shortcuts as vi. This is why it surprised me to see that I could modify a file when view was supposed to be read only. If we were to take a look at the documentation: $...

Read More...


The Sign of Char

January 20, 2025

Note: This is a follow up post from my microblog WARNING: I am no expert in Assembly. The last and only time I ever wrote assembly was computing the Fibbonacci Sequences 8 years ago for the MIPS architecture The following below has a value that is vague: char i = -1; The issue with the above line is that the value of i is not immediately obvious as compilers for different architectures could treat this as signed or unsigned. The signedness of a data type can be simply thought as whether or not there is a dedicated sign bit that...

Read More...