Code and Words
interesting concepts, programmer’s life and a software engineer at work
Follow
Following
Latest
Patterns in Scala: 101
There are lots of patterns which developers use extensively in Scala world. Some of the famous ones are stackable traits pattern, cake…
pattern and magnet pattern. They are very common to be found in any good Scala projects, you might not understand them in one read, it takes some good amount of time and patience to understand the beauty of each one of them. Today we will check out traits in scala and what is so cool about stackable traits pattern.
¶
Traits are exactly what it means in natural language. Let’s begin with an example.
Saheb Motiani
Feb 13
Lessons Learned @ Job: 2015
Last year went by pretty quick. I like to remember it as the year when my life’s party phase ended and work phase started. Mainly because I…
started working to solve actual problems, responsibility started coming on my shoulders, I got a feel of monotonous life and I kept waiting for the weekends.
¶
I enjoy programming and am fortunately working with a great team at Morgan Stanley. My team and especially my manager are pretty cool and I don’t have anything to complain from my side. My project is called WING. Wealth Management Information Notification Gateway, which delivers notifications to the clients of the firm.
Saheb Motiani
Dec 30, 2015
Tail Recursion: 102
Having explained the basics of Tail Recursion in my previous post, I would be doing something different in this post.
I would be showing you some code, you need to figure out what is going wrong and resulting in a Stack Overflow error.
¶
Context before looking at the code: These snippets are part of a solution to a chess positioning problem, which is nothing but a generalization of N-queens problem.
¶
tokens: tokens to be placed e.g. Q,Q,Q or K,R,K i.e. (King, Rook, King)
¶
tokenLoc: map to store location of placed tokens on the board.
Saheb Motiani
Dec 10, 2015
Tail Recursion: 101
Factorial is 1 2 6 24 120……
…
¶
Mathematical recursive function for the above is fact(n) = n * fact(n-1)
¶
Doing this manually for large numbers will take a lot of time. So let’s write a computer program to make a computer do the manual work.
¶
This works and here is how stack frame is going to look for fact(6)
¶
While filling the stack
¶
fact(1)*2 fact(2)*3 fact(3)*4 fact(4)*5 fact(5)*6 fact(6)
¶
While clearing stack
¶
1*2 //This frame is cleared once it returns 1*2 down.
Saheb Motiani
Nov 26, 2015
More stories →
About Code and Words