Wednesday, January 31, 2018

The Birth of Bitcoin Cash

Firstly, I would like to shed some light on the Blockchain technology. Blockchain is a transparent peer to peer network that allows us to transfer goods, funds and intellectual property fast and in secure way online. Before I go ahead further, it is important to understand the following general terms related to blockchain:
  • Transaction blocks – All the transactions are maintained in blocks. Like say 4/5 transactions per block. There is a limit on the size of block.
  • Distributed ledger – The entire public ledger is distributed across many systems. It is not maintained on a single server.
  •  Decentralized system – There is no central head responsible for the transactions. Group of people called ‘Miners’ add the transactions to a block and add the block to the ledger. No federal organization / a bank is involved for the verification.
  • Mining – The process of obtaining bitcoins
  • Consensus – Set of rules and proof of work for the transaction to be valid.

Now the famous ‘Alice - Bob’ example: Suppose Alice wants to send 10 bitcoins to Bob. She initiates the transaction. Every user gets a unique address linked to their account. To send / receive bitcoins, all you need is that address. Once Alice initiates the transaction to Bob, miners obtain the proof of work and add it to the transaction block. Once the transaction block reaches consensus, the transaction is added to the global ledger and Bob receives 10 bitcoins. Now in this case, miners who discover this block or who add it to the ledger receive certain number of bitcoins as a fee. If there is a deadlock and transaction is not being added to the ledger, then Alice can reinitiate the transaction with higher fees for the miners so that the transaction can speed up. Then, miners will void the previous transaction and add the new one to the ledger. For mining, miners use super GPUs to solve complex mathematical problems and to hash the transactions. This mining will earn them bitcoins.

As you can see, there is a limit on the size currently. That’s when forking comes into picture. Forking of the entire blockchain is done temporarily or permanently sometimes. Forking will assure the security of the application. The recent Bitcoin Cash was released after forking the original Bitcoin chain. As the number of transactions grew in bitcoin, it reached a point where adding new transactions was taking a lot more time than expected. The size limit on a block in Bitcoin is 1MB. So, the entire chain is forked and they increased the size of the block to 8MB. This is released as Bitcoin Cash with more features and updates than Bitcoin. BCH allows more transactions and less fees than bitcoin.
I will provide more technical details in my upcoming posts.


P.S: Once you initiate any cryptocurrency transaction, you can not get it back. So be careful with the transactions. 

Monday, January 29, 2018

Object-oriented programming or Functional Programming?

Recently, I have been introduced to Scala and that got me thinking about the difference between functional programming and object-oriented programming. After trying few programs in Scala as well as in Java and after reading many articles on this, I personally like functional programming now. For me, computer science and the programming world is like a mathematical world. It’s all Math! After all it’s basically all ones and zeroes! But it depends on what you try to achieve with the program too. If you know the problem statement and have a theoretical solution for it in terms of mathematical equations and stuff, along with the required data, then go for functional programming. Its direct implementation of math. Simple and short. But if you need the heuristics of a problem and need a user-friendly program without involving much complex functions and methods, go for OO. I kind of wonder why OO is still more popular than FP. OO is more user friendly, people understand objects easily compared to functions. 
The good news is that Scala is both OO and FP and that’s the strength of Scala, so it is easier to understand than the other hard-core FP languages like Lisp, Haskell, etc. Scala is inter-operable too  with Java (and of course inhabits the same JVM). On the other hand, Java8 has become more like functional programming language too. So the answer really depends on how you plan to approach your problem statement and what you are comfortable with the most. Anyways, I am enjoying both! Maybe in few years, it can be a different approach that would be more interesting to me. 

Tuesday, January 23, 2018

Scalar Query in SQL

Scalar Query is a query in SQL which returns exactly one column from a single row as a result in SQL.
Now, why do we need it? 

  • We usually need it to retrieve a scalar value from result set.
  • We can also use it in WHERE clause while checking certain conditions (true or false). This is termed as Scalar Subquery. 
Let's see few examples of Scalar Query and how well we can utilize it.
I have used SQL data set from w3schools.com for explanations.

Simple Scalar Queries :

SELECT CustomerID FROM Customers
WHERE Country='Germany'
LIMIT 1 OFFSET 3;
Output: 25

SELECT TOP 1 CustomerID FROM Customers
WHERE Country='Germany';
Output: 1

The way I used this query is as follows:

SELECT TOP 1 0 from Customers WHERE Country = 'London';
Output : 0 records.
Here, As there are no records with country = 'London', it won't have any result set.

SELECT TOP 1 0 from Customers WHERE Country = 'Germany';
Output: 0

SELECT TOP 1 1 from Customers WHERE Country = 'Germany';
Output: 1

SELECT TOP 1 or 0 will help to get a boolean value from query result.

Scalar Subquery example:
SELECT ct.CountryName,
              (SELECT COUNT(*) FROM Customers c where c.CountryID = ct.ID ) count
FROM Country ct


This helped me while writing lengthy queries with multiple joins and conditions. I hope you find it useful.


Thanks to you my team lead Hemant Ahire at Yardi for introducing me to this query.

The Birth of Bitcoin Cash

Firstly, I would like to shed some light on the Blockchain technology. Blockchain is a transparent peer to peer network that allows us to ...