My Blog about tech, Web & Mobile development. IoT etc.

Named arguments vs Indexed

There is two ways of using arguments both has pros and cons, I want to emphasize that there is no “silver bluet” and you don’t have to choose one or another. You have to know both and use both whenever it appropriate.

Indexed arguments

Some application, languages, and even syntax contractions force you to use index version of arguments, they all well known and don’t worth to mention, but what is really interesting that some times we can use it in unexpected places.

in Postgres

Each of the arguments you specify in a select has a 1-based index and you can use these indexes in the order by as well as group by statements.

Instead of writing

select id, updated_at from posts order by updated_at;

you can write

select id, updated_at from posts order by 2;

If you want to group by a table’s type and then order by the counts from highest to lowest, you can do the following

select type, count(*) from transaction group by 1 order by 2 desc;

in Swift

Closure automatically provides shorthand argument names to inline closures, which can be used to refer to the values of the arguments by the names $0, $1, $2, and so on.

Instead of writing

reversed = names.sort({
    (s1: String, s2: String) -> Bool in
    return s1 > s2

you can write

reversed = names.sort( { $0 > $1 } )

$ git stash // for daily usage.

One of the most awesome features in git is underestimated. git stash is awesome and you will see why.

Imagine you average day, tons of task, issues, and concerns. You have to switch on and off all the time during the day. It’s a bit annoying isn’t it ?

You spend some time to figure out what’s going on on a project, add some log statements, and binding.pry. Your console.log is logging pretty much all information what you need, but manager want’s you to take a look on a urgent hotfix.

$ git stash

Is going to help you, it works fine, but there is even more useful options. Use -u if you want to stash unstated files too.

$ git stash -u

This command is going to clean you project tree to original state and keep all changes as well as new files in safe place. Of course you can restor it any time by hitting git stash apply, but if know for sure it was an experiment or just one time job, it’s better to use git stash pop, pop work as expected and no more work for clean up you stashes required.

Last but not least things to know, you can use an awesome flag -p with stashes as you do with git commit. It works the same, you gonna be asked about any change in the same way.

$ git stash -p