Posts

  "Do What You Love" "The only way to do great work is to love what you do. If you haven’t found it yet, keep looking. Don’t settle." ― Steve Jobs As kids, we are taught to keep work time and play time separate. My mom used to say, "If you work for two hours, you can play for an hour". Your parent(s) probably said something similar to you too. If not, you're weird. Jk. :) We are made to believe that work and play are opposites. We were trained to not have fun while we work, because there is a separate time for that and you have to earn the right to have fun. As we grow older, you are told that if you do what you like, you tend to do it well. In other words, you do well what you like. Or at least pretend to like. Because if you do your work well (by liking it), you get to go home early and have fun. Why do what you love? There are thousands of students in your school or hundreds i
Pure Functions A function is called pure function if it always returns the same result for same argument values and it has no side effects like modifying an argument (or global variable) or outputting something. The only result of calling a pure function is the return value. Examples of pure functions are strlen(), pow(), sqrt() etc. Examples of impure functions are printf(), rand(), time(), etc. If a function is known as pure to compiler then Loop optimization and subexpression elimination can be applied to it. In GCC, we can mark functions as pure using the “pure” attribute. __attribute__ ((pure)) return-type fun-name(arguments1, …) { /* function body */ }   Following is an example pure function that returns square of a passed integer. __attribute__ _((pure)) int my_square( int val) {      return val*val; } Consider the below example for (len = 0; len < strlen (str); ++len)      printf ( "%c" , toupper (str[l
How does the linker or interpreter recognize the indentation in python? The lexical analyzer (tokenizer) uses a stack to store indentation levels. At the beginning, the stack contains just the value 0, which is the leftmost position. Whenever a nested block begins, the new indentation level is pushed on the stack, and an “INDENT” token is inserted into the token stream which is passed to the parser. There can never be more than one “INDENT” token in a row. When a line is encountered with a smaller indentation level, values are popped from the stack until a value is on top which is equal to the new indentation level (if none is found, a syntax error occurs). For each value popped, a “DEDENT” token is generated. Obviously, there can be multiple “DEDENT” tokens in a row. At the end of the source code, “DEDENT” tokens are generated for each indentation level left on the stack, until just the 0 is left. The parser then simply handles the “INDENT” and “DEDENT” tokens as block deli