samedi 6 septembre 2014

paradigm shift

What is a paradigm shift?

Paradigm shift is something like a revolution. As Thomas Kuhn describes it in his book the Structure of Scientific revolutions, it's a change that has been driven by the emergence of an idea which challenges an existing orthodoxy. 
Initially, the two ideas compete while the old order maintains its dominance. Over time, the strength and popularity of the new idea grows, until it begins to displace the older order: This is what Thomas Kuhn calls a paradigm shift.

That's how all great ideas come into existence. It's not easy to think of something that can cause a revolution, something that can change history as well as existing patterns of thoughts. People are usually resistant to change, a new idea is not necessarily well accepted most of the time. Thus, when thinking of a new revolutionary idea, one must have enough resolve and keep on holding onto their own ideas. We have to think different, think outside the box, in order to be able to change the world. And as a programmer, it's not enough to have an idea, we must make the effort to implement this idea, turn it into something concrete.

How did fortran (and modern programming languages) come into existence

Excerpt from stanford C++ course (cs106b)

In the early days of computing, programs were written in machine language, which consists of the primitive instructions that can be executed directly by the machine. 
Machine-language programs are difficult to understand, mostly because the structure of machine language reflects the design of the hardware rather than the needs of programmers. In the mid-1950s, a group of programmers under the direction of John Backus at IBM had an idea that profoundly changed the nature of computing. Would it be possible, they wondered, to write programs that resembled the mathematical formulas they were trying to compute and have the computer itself translate those formulas into machine language? In 1955, this team produced the initial version of Fortran (whose name is an abbreviation of formula translation), which was the first example of a higher- level programming language. 

I guess that this bright idea was what brought the modern programming languages into existence. After all, it's possible to express any mathematical formula with an instruction or two in any programming language. Programming requires logical thinking, which is something mathematicians are good at. It might not be always the case, but I think a good mathematician can be a good programmer. However, a good programmer is not necessarily good in mathematics.

samedi 30 août 2014

Beware of command substitution in bash

It's dangerous to use a loop with ls results in your bash scripts:

for i in $(ls)

Unix/Linux allows for almost any character in file names, including new lines and spaces. Then, what happens when there's a file with a space in its name:

╭─mansuro@localhost  ~/workspace/new_dir 
╰─$ touch some\ file
╭─mansuro@localhost  ~/workspace/new_dir  
╰─$ ls
some file
╭─mansuro@localhost  ~/workspace/new_dir  
╰─$ (for i in $(ls); do echo $i; done)


 As you can see, the file was treated as two different arguments, and that would have undesirable effects in your bash scripts.
How can we fix this? We could change 

for i in $(ls)


for i in *

╭─mansuro@localhost  ~/workspace/learning/Terminal/new_dir  
╰─$ (for i in *; do echo $i; done) 

some file

And you're done, your bash script works the way you want it to.

vendredi 1 août 2014

Vim persistent undo

Starting from Vim 7.3, it's possible to keep your "undo history". Even after closing and reopening the file, you can still use u and ctrl+r in order to go back to changes you made before closing the file.
In order to enable this feature, all you need to do is to set the properties undofile and undodir in your .vimrc file
set undofile
set undodir=$HOME/.undodir

Don't forget to create the directory undodir, or else this won't work
You can find more information about this feature here: Vim documentation: undo

lundi 21 janvier 2013

The expr command

The expr command is used to evaluate an expression and output the corresponding value. It could be used for example to use the terminal as a calculator:

    $ expr 80 - 25
    $ expr 80 / 25
Note that there is a space between the different arguments, otherwise the expression might not be evaluated properly.
It can be used as well for string operations and boolean operations

    $ expr length "abc"
    $ expr 1 "&" 0

vendredi 18 janvier 2013

Working with multiple files in vim

There is a couple of useful commands that can be used to work with multiple files as tabs. I've mentioned them in a stackoverflow answer:

  • Open a file in another tab

    :tabe filepath
  • save the current session in order to be able to open the same set of files again

    :mksession session_name.vim
  •  navigate between different tabs

    gt: next tab
    gT: previous tab
  • close all tabs at once

  • open a saved session

    vim -S session_name.vim

mercredi 23 mai 2012

cryptic perl

"Perl is the only language that looks the same before and after RSA encryption."
Keith Bostic. Programmer, created Sleepycat, contributed to free BSD unices.