Saturday, May 12, 2018

What is your favorite programming language or technology and why!?

In an interview I just attended, I was asked this interesting question. I felt that I had to tell them there are no favorites. Its pretty task specific. read more below >>>

What is your favorite programming language or technology and why!?
My Answer:


When it comes to programming, I have always been very versatile. I have worked with multiple languages and technologies, so I cannot really point my finger at any such favorite. I have loved working with visual languages. For example, HTML, CSS, JS, Jquery, (The web in general) are some languages that when I write code, I can view the results without needing to do more than a simple page refresh. This motivates me to develop code very rigorously and I iteratively make my webpage better and closer the specifications. Javascript has really blossomed into something beyond my imagination. From a simple client based scripting language, it has aggressively began competing with the latest and best out there. When I first started with Javascript in 9th grade, I had little idea about any of this. I wanted to build websites and looking at JS it seemed close to C language. It was simple and the interesting concept of the language was that it was un-typed. This meant I could worry less about pointers and types. Later, python also introduced similar concepts and I believe this is the reason these are widely used today. Though type-less variables makes the developer's life harder, its ultimately more fun and simpler to understand from the start.




Being well-versed in many programming languages, I don't have a single favorite language. I move from language to language as I change my clothes. I just pick up a new technology or language when I require it. When I started working with JAVA, I picked it up in just 3 days. I worked so much with SQL that I can write nested queries without even trying for a few minutes. I love challenging myself as well as keeping up with the new technologies. I feel that any language which helps me achieve one particular task is my favorite. For example, if the coding challenge's first question had an option for python, I would go with it. I only chose javascript to avoid pointers and after thinking about JS's built-in string and array functions/methods. 




The concept of Object-oriented approach was taught to me while I was learning C++. From then on, I learnt the same features specific to JAVA and then Javascript. Finally, I learnt the python features as well. Any language is good, as long as you have a strong sense of confidence and understanding of what exactly that language was built for. When the programmers wrote the language itself, what did they have in mind? Hence, we should choose a favorite specific to the task at hand. If I am working with lists, arrays and the likes, even data structures like linked lists and others, I would right away choose python. It makes it very simple. However, if I was building games, I would use C++ and OpenGL. Though, nowadays we have very high-quality libraries that enable me to design and develop them within your browser using javascript. I want to develop software without worrying the need to by-heart or mug-up the built-ins. I look up something and use snippets from anywhere as long as its legal to put together my program which produces the desired result.




One of my main challenges was when I was building a compiler for a certain Compiler Construction course in college. The question was similar, which language would you choose. I definitely pulled away from JAVA, and C++, owing to the inherent complexity. Next, I was deciding between python and javascript. My professor is a sticker to Racket, his own programming language, which he built along with his team. This language is also non-typed, though it has a really complex learning curve. However, it is good for matching and working with S-Expression, or even reg-expressions. It was a good language for building compilers, but I found it hard from day 1. I worked on it for a few months but gave up to work with python. I wrote a compiler for the language BrainF**k and it wasn't complete, though it was doing the basic bidding. I was inspired by the repl.it compiler is written in javascript for brainf**k. Now brainf**k is my favorite language. It has like 11 tokens and barely and complexity. But the most interesting part for me was the fact that a simple hello-world program was like over 40 lines of code. 


From this, I realized the more abstraction a language has, the fewer lines of code we need. Lesser the complexity of the language, higher the lines of code we need even for the most trivial of stuff. Hence, I like to conclude by saying that I love brainf**k as it thought me the required prerequisites in the programming paradigm and showed me how one can even make a simple language with little or no regard for its usefulness. 

Thursday, May 3, 2018

Check palindrome, simplest approach

Check palindrome:

The simplest approach to a quick, and efficient check palindrome program:

We don't need loops for everything!

The internal working is with a couple of if statements.


Always try to condense the program logic to skip loops if possible. There any many ways to implement simple tests which ensure the skipping of loops.


CODE(Javascript):


function checkPalindrome(inputString) {
    if(inputString.length == 1)
        return true;
    if(inputString.length % 2 == 0){
        if(inputString.slice(0, inputString.length / 2) == inputString.slice(inputString.length / 2, inputString.length).split("").reverse().join(""))
            return true;
    }
    else{
        if(inputString.slice(0, inputString.length / 2) == inputString.slice((inputString.length / 2) + 1, inputString.length).split("").reverse().join(""))
            return true;
    }
    
    
    return false;

}

Explanation:

  • String reverse in javascript 
    (ARRAY).split("").reverse().join("")
    

    This snippet can be used to reverse strings in javascript. The split("") splits the string into an array of characters. Next, the reverse() function reverses a JS Array. The join("") function joins them up again.
  • String slice is used to slice the string into smaller chunks. We slice at the center, if the string is of even length, if the string is of odd length, we slice around the center character.
  • If the string is of length 1, we know it’s a palindrome.
  • If the half of the string matches exactly with the other half, then we know it is a palindrome.



That is the logic behind this code! Isn't simple? Do try it out, I am sure it works for all test cases! Until next time!