This Week I Learned - 2016 Week 51

Last week post or the whole series.

Week 51 of 2016. The last second week of the year. Lots of time to reflect and ponder about my past and future. Here is an video of interviews with three centenarians (those who live past 100 years) on their secrets for living so long. There maybe many years to go with your life but never overlook the issue of mortality. Learn as much as you can, do things you enjoy, and spend your time with someone who both of you are mutually care about.



List of single-file C/C++ libraries. Someone really needs to compile a bigger list. There are a lot that needs to be picked up by me when come to C++, mostly are all the fundamental stuff. Good example is do you know there are different types of memory allocated (stack, heap, bss, data, and text) for a program? That's why good fundamental of computing hardware is crucial being a system developer. Background on how Operating System works or manage the memory is something i severely lacking. Which is why I'm still having a hard time understanding the whole C++ compilation process (another good introduction with plenty of diagrams).

While we're on C++, if you are creating a new project, this can be the folder structure of the project you can follow. Between a macro, a function, or a class, just stick to something simple, use macro for creating debugging details.

Another interesting item caught my attention, conversion of other data type to string in C++ is not as straightforward as I assumed it is. There are many approaches, such as the standard C++ or C++03 way (using stringstream), the C++11 way (using std::to_string), or the Boost way (using boost::lexical_cast). Unless you're stuck with legacy C++ compiler, use the C++11 method. While we're looking at string, C++ being a static typed language, string manipulation have to be expressed in an explicit manner. For example, to pad a string to a certain size and characters as shown below.
std::cout 
<< std::left << std::setw(10) << std::setfill('.')
<< foobar << ": " << 42 << '\n';

// output
foobar....:42

Need to implement your own logging function? This is the time where you need to use a C++ macro. Otherwise how can you use the preprocessor macro like `__FILE__` or `__LINE__`?

Function pointer in C/C++. Useful when you have an array of items that point to a corresponding functions.

It has been a while since I ever look into PHP. Found two interesting libraries, Httpful and Underscore.php. Both are either direct port of influenced by similar libraries in other programming language. Not really sure about the current state of PHP but I glad I ended up doing something else other than PHP. It's always nice to code in different kind of programming languages.

Hook system in Perl? This needs a third party CPAN module like Hook::LexWrap. Otherwise, it can be quite hackish.

No comments:

Post a Comment