Showing posts with label oo. Show all posts
Showing posts with label oo. Show all posts

This Week I Learned - 2017 Week 18

Last week post or you want to read through the whole series.

Since the prevalent of Internet these days, we're more connected that ever. And yet, we're even more isolated. More and more shopping malls and residential areas are being built especially around the transit stations. Basically all looks the same and people are discourage to travel to another town anymore because everything is available either online or at your nearest malls.

Sick. Down with fever. It has been a while since last time. No one but myself to blame. For people around my age, good rest and food is a way to healthy life. We're not seeking prolonged life but prolonged health.

#1 So, what's your Plan B? Good discussion from the comments. While there is some sort of discrimination against older programmers, but the reality is older programmers may just burn out or bore doing the same mind-numbling stuff over and over again. Yes, the same sh*t but different day. Not everyone have the opportunity to work meaningful projects (yes, subjective view), but most of us just work on some glorified spreadsheet or database skin. You see the same mistakes repeated over and over again from different systems and it's just pointless or bother to raise it up again.

#2 On becoming a low-level programmer. There is a curated list of information especially on the hardware part.. There is also another list of learning the fundamental of computer science. So many things to learn and explore and yet, so little time. Sometimes the reality of life commitments limit our choice on the thing we want to pursuit. I need to finish everything by July before I can start to clear the list from my bucket list. One step at a time. Follow the system.

#3 First, make it work, then make it right, and finally, make it fast. Get the thing to work first before you're thinking about making it right (giving the right name) and optimize it. Fulfill the requirements of the stakeholders first (prototyping) before you're looking into doing it right and fast. Something I need to remind myself constantly as we're often obsess with perfection. What's the point if your build it the right way and fast but does not meet the stakeholder needs?

#4 How to write a REST client in Perl. Most Perl modules have limited documentation, for example, little example on how to use the APIs. This is where PHP (it has been so long since I mentioned something about PHP) really shines. As the language is slowing dying, there are little or no good example on how to start something up fast.

Meanwhile, something rather interesting about Perl. I've seen quite a few Perl codes with subroutines that prepended with ampersand (&) operator. Basically, the ampersand is needed if you're calling a subroutine before its declaration. Off course, there are many other reasons and usages to use the ampersand, but commonly as reference to a subroutine.

sub hello {
    print "hello";

When using OO with Perl, you will need to instantiate the constructor or method invocation through the arrow (->) operator (a reference). Good examples given below.

Using the arrow notation or virtual method.
my $apple = Fruit->new("apple");

Using the double colons notation or static method.
my $apple = Fruit::new("apple");
Fruit::get_price($apple, "usd");

However, to invoke the method either statically or virtually, you'll need to write the constructor as follow.
sub new {
    my $self  = shift;
    my $class = ref($self) || $self;
    return bless {}, $class;

#5 "error: src refspec master does not match any." Silly me. You need to commit something locally before pushing to remote Git server.

#6 Tiny Python Notebook. Definitely not tiny but quite comprehensive guide to Python 3.6.

#7 How to unstage all staged files in Git? It's so easy that the best answer is not upvoted enough.
$ git reset

#8 Postgres Weekly. When come to FOSS database choices for web application for Intranet application, I'm strong opinion that PostgreSQL should be the default choice. Feature like Range Types and others solves quite a lot of issues and save lots of developer-hours. Yes, MySQL has its own usage, but for any business application which involves monetary and strong ACID compliance, it's not a right choice.

This Week I Learned - 2017 Week 12

Last week post or you can read the whole series.

9 hours of writing and only 3 pages done.

#1 The important of morning rituals in developing a system (install a habit) to achieve your life goals. Is good to be morning person as you can achieve quite a lot when your mind is fresh. There are these 7 morning rituals which I will slowly introduce to my daily life. These are:
  1. Plan a day before. I've been slowly adopting this habit by going through the list of items in my bag and write down what I need to do tomorrow. Not consistent though as for some day I failed to plan for anything.
  2. Wake up early. Either from 4:30 AM till 6:30 AM. This is doable provided that you sleep quite early on the previous day. According to this sleep calculator, these are the corresponding time you should sleep if you want to wake up at a particular hours.
    1. 04:30 AM - 7:30 PM or 9:00 PM or 10:30 PM or 12:00 AM
    2. 05:30 AM - 8:30 PM or 10:00 PM or 11:30 PM or 1:00 AM
    3. 06:30 AM - 9:30 PM or 11:00 PM or 12:30 AM or 2:00 AM
  3. Start the day with exercise.
  4. Do your highest priority projects. Study in the morning and reviewing again in the evening before bedtime. This is good for learning as you can recall and rethink what you've learned in the morning. Also? Before even you start your journey to work, you've already accomplished so much for the day.
  5. Work on your side projects. Definitely need to try this. Do not work on your side projects late at night. Do it in the morning.
  6. Have a uninterrupted conversation with your partner. Do we actually having any serious and uninterrupted conversation with our partner, even for just two minutes? Doubt so.
  7. Meditate. I've been doing this since the moment I woke up in the morning. Although for just a mere 10 seconds, slowly but surely I can really concentrate on it.
#2 Beautiful SICP. There is another Python version as well. The discussion is always revolves whether it's good or not. I haven't yet finish the damn book since I bought it 20 years ago. Is this year the year for me to finish it? Doubt so. Even though I placed the book next to my work place and look at it on daily basis. Also, SICP is also the recommended book (debatable) on the subject on programming in Teach Yourself CS. (via HN) While we on that, someone should start another list on Teach Yourself SE. My personal experiences is that Software Engineering knowledge far outweight the Computer Science knowledge.

Since we can all access good quality CS education through the Internet, does local CS degree still relevant today? Or does this means that universities or colleges have been rendered to just another platform for face-to-face socializing instead of gaining knowledge?

#3 Almost 15 years of Design by Contract. I can relate to the author experience and still is a firm believer of Design by Contract (DbC). Bertrand Meyer still have a huge influence on me. Like most things in life, moderation is the key. Use DbC only when necessary.

#4 Real-time LED strip visualization (see Gif animation below) using ESP8266 or Raspberry Pi. Not only the project was interesting, the detail documentation by the developer was impressive. Definitely one of the most solid Github project I've encountered.

#5 Alone in the Wilderness. (via Reddit) A documentary (search YouTube for the video) about Richard Proenneke, who upon his retirement at age of 51 years, build an ultimate man cave to live a life of solitude in Aslaka. Carpentry is such a underestimate skill a man could have.

#6 Interesting Git graph generated by Bit-Booster, the offline commit graph drawing tool from one of my personal Git repository. I'm not sure how to interpret the relationship of my commits, seems somehow broken?

This Week I Learned - 2017 Week 03

Last week post or the whole series.

#1 Having trouble finishing any personal side projects as a developer? Rethink the purpose on why you want to start a side projects? Don't be so hard on yourself, nobody is keeping scores and gives a crap. Do it because you want to learn, experiment, and have some fun along the way. However, keep the coding streak going. Don't overwhelmed yourself, it's not a full time job. Also, do not fall into the trap of researching more than doing ala analysis paralysis, a common behaviour when you're starting a new venture or hobbies and get overly excited.

#2 ShewhartJuran, and Deming. The giants of Total Quality Management (TQM) and theory. Humphrey applied these theories to software quality and thus, leads to the development of Software Engineering Institute (SEI), Capability Maturity Model (CMM), and Capability Maturity Model Integration (CMMI). Can quality theory used for manufacturing translates well to software development? Depends. Highly for embedded system development but doubt so for normal web development.

On a related note, can we apply these quality models and theories to our personal productivity and optimize our habits? If we consistently miss our commitments to our self, isn't that a symptoms of process failure? Hence, if we fix the process and thus fix our habits, can we increase the probability of the success of our commitments? Also can we apply CMMI's capability level to personal financial planning? That's food for thought. Again, this is a possible interesting idea, daily SCRUM family meeting. I've tried something similar with limited success. Feedback from SO is that it's too formal and too rigid.

#3 Keep up with fast changes of development field? Don't do front-end stuff. Don't follow the flash-in-the-pan (hot) technologies. Learn durable skills. Study and take online classes. Be a generalist? Don't think so. While we're still thinking on what hottest technologies or practices to use, ask yourself "when is practice X useful?" instead of "is practice X a good idea?" Good example is the numerous Agile practices, there are so many and not every one is applicable for your organization. One little gem I learned, Agile is used primary to solve communication or requirements issues. And also, another example of those practices is the use of monorepo, even through you're using a distributed version control system.

#4 T(Type) Driven Design over T(Test) Driven Design. Interesting indeed. Instead of embracing T(Test)DD, the problem can be partially solved by switching to a statically type programming languages. For example, switching from Python/Perl/PHP to Golang?

#5 While watching the short documentary series Mind Field on the subject on isolation, little I realized that boredom is the result of your brain lacking stimulation and worse, and epidemic psychological behaviour will little scientific studies.  Moreover, researches have identified that there are different types of boredom. Interestingly, Plutchik's wheel of emotions grouped the emotion of boredom with disgust and loathing. No wonder philosopher, Søren Kierkegaard said "boredom is the root of all evil" (or is it creativity?). How to prevent our self from succumb to boredom? Thinking about boredom itself, why something bores you. Or because we've become habituated? Maybe practice gratitude is an alternative way to resolve that?

#6 The Old School Object Oriented Perl (OSOOP). Yes, the bless-way. As I mentioned many times, specifically, Perl is a text processing programming language with multiple ways of doing things. Hence, OO supports is to the bare essentials, there is not syntactic sugar what so ever. If you're creating a CPAN module, best to use lightweight Moo package, which was designed for that purpose.

This Week I Learned - 2016 Week 26

Last week post or the whole series.

What the difference for the Git config option of 'push.default'? To prevent yourself from committing and overriding local branches to remote branches, stick with 'simple' way of 'git push'.

Why you need to support Perl's PSGI?

One of the dilemma faced by any programmer, what should I program? (via Slashdot) Someone if the forum joked that "I know how to post a comment, but I don't know what to say." Funny indeed but true as well. Yes, you can learn one programming language per year, but in the end, it will be quite a waste if nothing is created.

12 years of web programming (via Reddit). Sad but true. Layer of layer of layer of abstraction which in the end, just to produce HTML.

Another approach of subroutine parameters validation in Perl. This is from REST::Client. "Tim Toady" at work here using Carp module.
croak "REST::Client exception: First argument to request must be one of GET, PUT, POST, DELETE, OPTIONS, HEAD" unless $method =~ /^(get|put|post|delete|options|head)$/i;
croak "REST::Client exception: Must provide a url to $method" unless $url;
croak "REST::Client exception: headers must be presented as a hashref" if $headers && ref $headers ne 'HASH';

How to design a class?

"Start with the simplest thing that works. That thing will probably be just a function. Grow it from there. If it gets too big, split it. If you find that you pass the same 12 parameters to a bunch of functions - factor out a class. If you do the same thing in a bunch of classes - abstract it out. Keep it DRY. Keep it SOLID. Rinse and repeat. This way you end up with a useful class hierarchy - and OOP won't be awful."
-- azov, emphasis added
I like his approach, build working stuff incrementally, from procedural towards Object-Oriented (OO) design when needed compare to the more theoretical and classical way on how to design a class. Way more pragmatic for those coming from more procedural experiences. Based on my observation, some programmers still struggle on adapting an OO mindset. There is nothing wrong with procedural approach but if you're using a framework, at least try to understand and follow the underlying OO structure.

Variadic Function

Few years ago, I was introduced to this PHP function func_get_args() by my senior while reading his code (can't remember what or why he used it for). This function allows you to create a function that can take multiple arguments and no argument list declaration in your function signature. Code shown below is an example of a helper function to find the maximum value from a set of number.
function max() {
   $max = -PHP_INT_MAX;
   foreach(func_get_args() as $arg) {
      if ($arg > $max) {
          $max = $arg;
   return $max;

echo max(1,5,7,3);

Why I brought this up ? I didn't realize that the term "variadic function" is used to describe function that support multiple arguments until I read the Request For Comment (RFC) on the proposal of a new syntax for variadic function for PHP. Historically, variadic function is an old concept that long implemented in C programming language, especially for printf() and scanf() function. Not surprisingly, these two functions also existed in PHP , since it's a C-based programming language.

Back to the RPC. Reading through the discussion in Reddit and the RFC itself. I think is a good idea since we can now enforce type hints and enforcing consistency on interface. However, a feature that is nice to have but only useful for those framework or library writer and not mere library consumer like us.