Google Interview Round 2 Question

February 9, 2018 at 4:11 pm | Posted in C++, Hacking, Programming | 1 Comment

I was just searching for C and C++ related topics and came across Google interview question.:

/**
*
* Google OnSite Round 2
*
* Input is an integer array A
* Return an array B such that B[i] = product of all elements of A except A[i]
*
*/

Original Question was on CareerCup. I wrote an algorithm on paper in 7 min and took me another 10 min to type it in computer. Do it without using division.

Continue Reading Google Interview Round 2 Question…

Literate Programming

January 10, 2018 at 10:43 am | Posted in Hacking, Programming | Leave a comment
Tags: , , , , ,

I was reading Knuth’s The Art of Computer Programming, the seminal in algorithms. I was unable to understand some parts of section 1.2.10 (analysis of an algorithm), so I asked on IRC channels (like ##programming, ##c, #haskell etc.) and I came across More Shell, Less Egg. Go read that article and come back here.

I hope you have finished reading that article. A few years back I came to know about Literate Programming. I was curious about it, I read some articles on it and really loved the concept. Fast forward to 2018, I am a full-time computer programmer with several years of experience now and my thinking has changed. So how does literate programming look now ?

I read full article and was quite impressed by the cleverness and experience of both Mcllroy and Knuth. Now Mcllroy is a UNIX guy (he wrote UNIX pipes). UNIX gurus are very practical and wise when it comes to solving problems. But I found myself little bit wrong in comparing a shell script with a full fledged programming language available on a variety of systems. Then I came across this comment by Charles Wolfe:

most comments tend to become useless rather rapidly and having the documents wholly separated from the code make the cross referencing or consultation of docs to understand code difficult most of the time.

I have to agree with that as per my own experience (it may not be valid all the time and this is how most of the industrial code is written). We combine that with another very practical blog post by Franklin Chen. He used 2 pieces of codes to prove his point, first one, normal Haskell code and 2nd, Haskell code written with documentation (something like Haskell’s own WEB system). If you look carefully you can see that one with documentation is not much readable (at least I felt horrible when I tried to read it).

So, What Do I think now in 2018 after working in software industry ?

Let me make it very clear that Knuth is a brilliant guy, I respect him a lot. I even someday want to learn from him by sitting next to him teaching me 🙂 . We are talking here about Software Industry, the commercial interests. I think Literate Programming will not spread into the software industry. First of all, industrial software developers (at least here in India) do not care much about comments. I do write hell lot of comments but that is because I learned my skills on USENET whereas most industrial programmers in India learned from usual engineering colleges where commenting your code well, is not part of the picture. There is no paradigm of “you will write it once and it will be read 10000 times, so help your fellow programmers by telling them what are you doing” (I just industrialized the quote from Knuth: “Programs are meant to be read by humans and only incidentally for computers to execute.”).  2nd, there is lot of job-shifting happens in industry. By the time  a project comes to its completion, there is a possibility that  1000 different people have worked  on it who never communicated with each other, hence,  lot of code changes and many times, comments, sooner or later, become irrelevant. Some comments stay same, many don’t. 3rd, managers in industry want solutions fast and even though, most of the time, such attitude hurts the software and hence the company in long term but then I do not think it is their fault because they have pressure on them to deliver. So, if a project takes a month to design, code and test and deliver then you have to get it done by next week. In such cases, all things not related to “fast delivery” are generally ruled out. If it is not a whole project and there is problem you have to solve then  because of “fast delivery” requirements, UNIX tools win. I have experienced both. You can’t beat UNIX tools there with a general purpose language.  So, I think Literate Programming  will never catch up in industry.

Copyright © 2017 Arnuld Uttre, Hyderabd, Telangana – 500017 (INDIA)
Licensed Under Attribution-NoDerivs 3.0 United States (CC BY-ND 3.0 US)

How much math you need for programming

December 5, 2014 at 10:47 am | Posted in art, Hacking, Patterns, Programming | Leave a comment
Tags: , , , , , , , , ,

Whenever I wanted to learn Algorithms, Mathematics used there somehow seemed to be an obstacle. I admit my Math is not that good but it ain’t that bad either but this “ain’t bad” level of knowledge was not enough to compete in interviews with the Big Four when it comes to their level of Algorithms and the time and space complexities involved and comparisons of sorting and searching techniques. I needed to learn all these and in that search I came across several articles written on Mathematics required for programming. When it comes to programming, most loudly known math-proponent is Steve Yegge. Here is what I have found on Math required for programming:

  1. Steve Summit notes on Math (author of brilliantly written C-FAQs)
  2. Steve Yegge who has written two articles Math Everyday and Math for Programmers
  3. Eric S. Raymond talks about how much math you need to become a Hacker
  4. Paul Graham on Math
  5. Evan Miller’s article as reply to 3 authors above
  6. Steven Noble wrote an article as reply to Evan Miller’s example of calculating fibonacci numbers

If you do not read all of those above then you might miss the intent of my blog post. As per Steve Summit, Eric Raymond and Paul Graham, you do not need to focus much on Math to become a brilliant programmer, a hacker (Wikipedia definition and Eric Raymond’s article on definition of a hacker). Steven Noble says you should learn a little bit of Math and Evan Miller somehow seems to agree with all of them with a bit of twist. I myself started programming just for the love of it.

Since 2009, I am programming professionally mostly in C, sometimes in C++ and almost always on Linux and sometimes on UNIX. My passion for programming has made me read and write code in many different languages where I had to learn different ways of thinking. Writing code is easy, thinking along the lines of the paradigm on the top of which a particular language was modeled is a tough, daunting and very time consuming task. What I have experienced is: Computer Programming is not Math. Let me say it again, computer programming is not Math and will never be. You want to learn computer programming, then learn computer programming. Do not flip through Math books, read whatever is written on a particular newsgroup (comp.lang.c, comp.lang.lisp for example). Use a news reader like Pan:

http://pan.rebelbase.com/

Read about all the software that came from GNU and use Linux distro exclusively for everyday tasks (I prefer a distro with least amount of binary blob). If you are learning lot of Math because you want to learn computer programming then you are confused and headed in the wrong direction and you will not learn much of programming.

As computer programmers, we write programs, but why? We write programs to solve problems of this world. That is what computer programmers do, they solve problems.

Now what does does a mathematician do? He tries to understand nature and uses mathematics as a language to do that. Mathematics has helped solved many problems of this world. Look at what Quantum Physics, a branch of physics that has literally changed our millennia old assumptions about atoms, is heavily dependent on Math. Math is everywhere, from chemical industry to societal problems we use Statistics. Take any part of your daily life and you will see how deeply it is influenced my Math. Math has been used as the most prominent vehicle not only to understand nature but also to solve problems of this world. There is a reason for this, all these properties are just inherent in Math.

I was not good at Math, so I was trying to solve the problems I was facing everyday as a programmer using my intuition, common-sense, flow-charts and more other kinds of diagrams. This went on for few years and I came up with some rules and ideas on which I was building a model to solve problems. Building up this model had one aim: to be extremely clear and very brief on what the problem is and same for solution. I was creating a model, to which you will feed a problem as input and it will produce a solution as output using English language, flow charts and lot of other kinds of diagrams I created. This model had certain assumptions, rules and conditions, which again were very clear. Clarity and simplicity were high on agenda. It was a kind of a general, abstract mechanism to be applied to problems to get solutions. Now a few months back, after I read all these Math articles I came across one more article from Evan Miller titled Don’t Kill Math which was actually written in response to Kill Math by Bret Victor.

These two article hit me very hard. First, Bret was trying to do the same thing I was trying from few years, though he was more successful than me in producing something. I could never come up with some solid model which could have been used by everyone and here is Bret who has already done that. Was I happy, yes, because I found what I was looking for and I was ready to follow Bret’s footsteps but I never did. Why?

There was a reason I could never come up up with a solid model. I always thought it lacked something. No matter what I did and how much I worked on it, I always felt that something very fundamental and basic is lacking. Whenever I studied Schrodinger equation, Maxwell’s equation, Newton’s laws, Kepler’s laws, The Uncertainty Principle or Shulba-Sutras, I always felt that all those equations are complete but my model does not. Both of these articles Kill Math and Dont’ Kill Math made me realize what is that completeness. It is the properties of Mathematics mentioned in Don’t Kill Math. The questions Evan asked in this article and the way he has explained in very simple and basic details, concluded my search for a model. Math is a terse, succinct and concise method to solve problems and understand a phenomenon. These brutal characteristics are inherent to Math, just like soul is inherent to every being. With Math you can solve problems in a much shorter and better way than not using it.

This brings me to a very basic question: Why did I hate math? It was the way math was taught to me in school and college. I was taught rote-math, not real math. It is the fault of school, fault of our education system, not of the student. Coming back to the primary question of whether we need Math for becoming a great programmer, this is how tho world solved its problems in beginning:

math-1

Then came Math and this is what most mathematicians did:

math-2

And this what almost all computer-programmers/software-engineers/developers do:

math-3

Evan Miller says you can become first rate hacker without using a lot of Math and I think he is right and that is in agreement with all other authors. The point he stressed was role of Math in solving problems of this world, that Math is brutally efficient in solving real world problems. As programmers, we solve problems, but if we solve problems using Math and then apply programming solutions to the mathematical model of the solution, then we can have some amazing ways of providing better solutions that will make our lives easier as a programmer (kind of side-effect):

math-4

I conclude this blog-post with:

  • You do not need math to become a first-rate programmer because we do not use much of Math directly. If you want to become programmer then learn programming. Computer programming is very different from mathematics, and as a computer programmer you have to focus more on how to write better programs, how to think in a particular paradigm (e.g functional, OO, Generic, Procedural, logical, declarative etc), find better ways to create software, you need to understand design-patterns, not to mention learning and using C for few years will add new dimension to your thinking. All these are not related to math in anyway. You need to learn these first and it will take you few years before you get a grip at them and then you can learn Math if you want. Read Introduction to Progrmming using Emacs Lisp by Roberrt J. Chassell to know how the problem of creating a customizable, self-documenting, ever-extensible real-time display text-editor was solved. Read GNU Make Manual and find out why does it need M4 and Autoconf.
  • Math is the most widely used vehicle to understand the nature and solve problems of this world. We can learn more ways of solving problems by learning mathematical methods. I myself have started studying probability because like Steve Yegge said, once you understand Math then you can look at the problem and see whether it a probability problem, calculus problem or statistical problem etc. Math is related to the nature of the problem, not nature of software, software has its own methods and tools of solving problems, keep that in mind.

Copyright © 2014 Arnuld Uttre, Hyderabad, Telangana – 500017 (INDIA)
Licensed Under Creative Commons Attribution-NoDerivs 3.0 license (a.k.a. CC BY-ND)

The DVORAK Experience

October 26, 2014 at 2:53 pm | Posted in Hacking | Leave a comment
Tags: , , , , , , , ,

A few months back I wrote about how I switched to DVORAK from QWERTY. Last week my logitech keyboard died and I searched for DVORAK keyboards and could not find anyone selling that online in INDIA. I guess INDIA is QWERTY, therefore I got myself a new DELL KB212-B wired USB2.0 keyboard. As per hardware quality, I will say for 440/- rupees it is damn good. DELL did a great job on manufacturing. I started typing on it and guess what, after using DVORAK for few months QWERTY arrangement felt so idiotic and dumb, not to mention painful, as if QWERTY was designed specially not for typing English words.  I was accidentally hitting DVORAK arrangement on QWERTY keyboard.  I have used QWERTY since the day I touched computer first time (10 years I guess) but subconsciously my hands/fingers were never able to memorize more than half dozen key-positions but few months usage of DVORAK and now I can write 20 or more key-positions of DVORAK arrangement. Heck, I can draw full fledged DVORAK arrangement on paper just from my memory. With practice you can easily memorize any random key arrangement but mind you, I did not practice memorizing DVORAK. What I wean is: DVORAK matches human thought better than QWERTY.

I  did lot of search on QWERTY vs DVORAK vs XXXXXX and 99% of comparisons were based primarily relative to speed. Let me tell you again, speed, speed, speed, speed, speed, speed, speed, speed, speed, speed, speed and all comparisons were based on one criteria of speed. Everyone (especially the ones who are biased) have ignored the most basic requirement when it comes to typing: “comfort and ease of typing”.  I type almost whole day, I do programming and I write this blog and reply to my emails etc.  That is me. What about professional clerks and authors and fiction/non-fiction writers who have to type much-much longer hours.  Will you sacrifice your body (RSI and CTS) for just a keyboard habit?  QWERTY does not give you more speed than DVORAK, it is the practice which does. All you have to do is change your habit to use DVORAK. Habit before Health?

Well, I needed to change the key arrangement. I noticed that keys were fixed, hence I could not change their places. Therefore, I decided to stick some handmade letters onto the keys and this is how keyboard looks like now. Trust me, I have not regretted a bit that my brand new keyboard looks like a children’s toy now. It is immense pleasure typing on DVORAK

Jpeg


Copyright © 2014 Arnuld Uttre, Village – Patti, P.O – Manakpur, Tehsil – Nangal, Distt. – Ropar, Punjab (INDIA)

Verbatim copying and distribution of this entire article are permitted worldwide, without royalty, in any medium, provided this notice, and the copyright notice, are preserved.

Must Reads – 1

March 23, 2012 at 4:59 pm | Posted in Hacking, Programming | Leave a comment

I started learning programming in year 2005. After I quit my sales job in February of 2005, I purchased Red Hat Linux Bible in end of April same year. It has been 5 years since then, I learned a lot about computers and it became my passion since then, all possible because of GNU, different Newsgroups, mailing lists, forums and all the helpful people. I have read many articles and books and essays and history of UNIX, Linux, GNU, BSD, Debian, and many other organizations and groups. Based on my experience I am providing here a list of articles that every computer science student, every programmer must read.

Ideal process would be to just read these links and google for extra information:

I guess in 1996 I tried to learn English from a book which you can find on every corner of India and it boasts to teach you English in 30 days. I tried and failed several times. Then 7 years later, during my graduation I tried to learn programming from a 30 days book and I failed again.

The problem was that these 30 days, 30 weeks, 10 days, 21 days books never teach fundamentals. Most of them have many unreasonable assumptions. By reading these you can only have superficial knowledge about these subjects and almost no knowledge of basics. This is so strange but I myself wanted to write an article like Teach Yourself “Martial-Arts/Car-Repair/Large-Scale-Electric-Systems/Nuclear-Physics/Fine-Arts/something-here/fill-your-favorite-words-here” in 10 Years.. At that time I never came across anything like blog, in 1996 there was no internet at my place, therefore I never wrote the article. Later I went into different kinds of jobs and forgotten about it. When I started learning programming and started my blog I wanted to write one but then suddenly one day I came across Peter Norvig’s Teach Yourself Programming in 10 Years and I was surprised. I concluded I will not write any blog post about my experience because people will think I am copying Peter Norving, trying to imitate him. So I dropped the idea but in the meantime before internet came I shared my experience of 30 days books with my friends.

The list of books and articles above is exactly opposite of those 30 days books. Enjoy 🙂

Copyright © 2010 Arnuld Uttre, #331/type-2/sector-1, Naya Nangal, Distt. – Ropar, Punjab (INDIA) – 140126

Verbatim copying and distribution of this entire article are permitted worldwide, without royalty, in any medium, provided this notice, and the copyright notice, are preserved.

Next Page »

Create a free website or blog at WordPress.com.
Entries and comments feeds.

Design a site like this with WordPress.com
Get started