Thursday, February 18, 2016

That application is wise which has less third-party dependencies or less dependencies whatsoever.

I heartily accept this credo "That application is wise which has less third-party dependencies or less dependencies whatsoever".

Most Ruby on Rails applications usually, and all Ruby on Rails applications sometimes, have plenty of gems. I believe that most of the gems can be easily eliminated and the application will still function as good as ever. In fact, it'll be faster, lighter and less likely to have bugs because gems are subject to have bugs.

I believe, that most of the functionality that gems provide, can be written by ourselves in a reasonable amount of time and without that much effort.

We don't need a third-party library which:
  • highlights a line in the terminal in the red colour and that's all it does.
  • allows us to write 2 lines of code to connect to gmail.com instead of 4 ones we write using the standard Ruby library.
  • allows us to write print_with_3_new_lines("Blabla") instead of print("Blabla\r\n\r\n\r\n")
  • takes us tremendous amount of time to learn its API.
  • is hardly used by anyone else.
  • makes us dependable on the author of the library and their mood of fixing the bugs or improving it.

Wednesday, February 10, 2016

2 different kinds of "list" in Python

When using pdb in python 3 you might encounter this odd error:

(Pdb) my_dict[some_key]
{'some_key': }

(Pdb) type(my_dict[some_key])


(Pdb) list(my_dict[some_key])
*** Error in argument: '(my_dict[some_key])'
How come? That's because "list" here is a method of "pdb" and not the the operator "list" of Python. To fix it, you can do this:

(Pdb) a1 = list(my_dict[some_key])
Now "a1" is, endeed, a list.

(Pdb) print(a1)
['a', 'cc', 'e', 'some_other_key']

Friday, February 5, 2016

Upgrading cabal of Haskell in Linux

When updating cabal, one might get this:

$ cabal update
$ cabal install cabal-install cabal
.......
Linking dist/build/cabal/cabal ...
Installing executable(s) in /home/alex/.cabal/bin
Installed cabal-install-1.22.8.0

$ cabal --version
cabal-install version 1.16.0.2
using version 1.16.0 of the Cabal library
Where is cabal we just installed gone? And the answer is that it's at /home/{your_user}/.cabal/bin And the old one is at /usr/bin/cabal How can we fix that? We should add the path to the newer version to PATH. As a rule, I do that via ~/.bashrc:

$ vim ~/.bashrc
And then

export PATH=/home/alex/.cabal/bin:$PATH
$ source ~/.bashrc
To ensure from now on the newer version of cabal will be used:

$ cabal --version
cabal-install version 1.22.8.0
using version 1.22.7.0 of the Cabal library 

Monday, February 1, 2016

Statics in Rust aren't that simple

1) Suppose we have this:

static MY_STATIC = 123;
fn main() {
  println!("MY_STATIC = {}", MY_STATIC);
}
That gives a compilation error: expected ':', found '=' The type of a static has to be defined, let's fix that:

static MY_STATIC: i32 = 123;
And it gives us:

// =>
MY_STATIC = 123
2) Let's create 2 static variables with the same name but in the different lexical scopes:

static MY_STATIC: i32 = 123;
fn main() {
  println!("MY_STATIC = {}", MY_STATIC);
  
  static MY_STATIC: i32 = 456;
  println!("MY_STATIC = {}", MY_STATIC);
}
And it compiles well and only a single warning implies that something is a little wrong:

warning: static item is never used: `MY_STATIC`, #[warn(dead_code)] on by default
static MY_STATIC: i32 = 123;

// =>
MY_STATIC = 456
MY_STATIC = 456
3) Let's add one more function and print the value of the global static variable in it:

static MY_STATIC: i32 = 123;
fn main() {
  println!("MY_STATIC = {}", MY_STATIC);
  
  static MY_STATIC: i32 = 456;
  println!("MY_STATIC = {}\n", MY_STATIC);
  func2();
}

fn func2() {
  println!("MY_STATIC = {}", MY_STATIC);
}

// =>
MY_STATIC = 456
MY_STATIC = 456
MY_STATIC = 123