Thursday, November 3, 2016

Writing a web app

Recently I have started writing a web app, which I was trying to build for a long time. This time I am much more closer to completion than ever before, and I feel I can easily complete it.
I want to think about why I couldn't do this for a long time, and why I have done a large part of it in a couple of weekends. Possible reasons coming to my mind are:

  • I was misguided by many blog posts
  • I made my first attempt using PHP, just because I knew the language
  • I was focusing on the wrong part of the app
  • My day job and my life in India was draining out all of my energy
  • I was trying to do too many things and not doing most of them
I'll know better when I actually get to launching the first version of the app. So far, here are my learnings:
  • Prefer podcasts over blog posts, if you have learn from the net
  • Put highest preference to books - buy them or loan them from a library - they are worth every penny
  • Start your prototype as a front-end app, using html and javascript. Use jquery extensively.
  • Use a Javascript array as your database, to begin with. It will be good enough for most prototypes.
  • If you are stuck, stop and read a book or discuss with someone
  • Don't start with any app framework - you don't know what you need.
I'll stop here and resume when I have made more progress

Saturday, October 29, 2016

My Javascript workflow

So I am trying out my hand in JavaScript, and want to talk about my workflows. I have two development setups - one on a cloud VM which is a DigitalOcean droplet, and the other is my laptop which happens to run Windows (since it is provided by my office).

On the cloud machine development is super easy. I connect to it using putty from Windows, and write my code using emacs, and run a python server (python -m SimpleHTTPServer) in another shell. I run both these shells inside a screen session which I keep alive, and detach when I logout. I can view pages served by the web server on my local machine's web browser by going to my VM's IP address and using the port 8000 which is what the python module uses by default.

On my Windows laptop it seems things are not that hard. I write my code using Notepad++ or Brackets, and run a node server (http-server.cmd) from the Windows PowerShell. I can view the web pages on my web browser by going to http://lopcalhost:8080 as 8080 is the port used by the node.js module. The Windows port of node.js looks pretty good, which means a lot of web development can be done on PCs now. How do I use git? Well github has a Windows desktop client which makes development in github repositories a breeze!

Wednesday, October 12, 2016

Poster inspired by podcast on abstractions

I am being mindblown by the world of podcasts, and programming podcasts in particular. Today I heard this episode of "this developer's life" where there was a nice quote at the end. I decided to make a poster out of it.

Thursday, September 22, 2016

Revisiting Javascript

Javascript was the first programming language I learnt, back in 2001, about to leave high school. In college I somehow 'learnt' that these were not real programming languages. The real languages were C, C++, Java and the like. I gradually drifted towards C++, and then worked in C and C++ for a decade in the industry.

Now I am stumbling upon one thing after the other about Javascript which makes me think - god why didn't any of the tutorials tell me all this back in 2001! Specially about the bits of functional programming possible in Javascript - and how you can quickly built complex programs with it.

I just want to list down the nice things I've encountered in the past few days:
1. A blog about how to write a programming language in Javascript
2. Marijn Haverbeke's book 'Eloquent Javascript'
3. A talk from EmpireJS on Knitting in Javascript
4. A 30-line implementation of a simple spreadsheet in Javascript
5. A blog post about variable scoping in Javascript

The language is confused and allows multiple paradigms - but so is C++. The best thing about Javascript is that it is much easier to use functional programming techniques in it. And the even better thing is that most devices/platforms seem to be supporting it. I am tending to believe that the bigger things of the future will be built upon powerful programming languages or systems. I am gradually moving away from the importance of building faster low-level programming systems.

Saturday, April 4, 2015

A command-line user's guide to building Android apps

I'd like to document my bare-bones Android app development work flow which is entirely command-line-based. The internet is full of app development guides using Eclipse or other IDE's, but resources for command-line users like myself are rare. I don't know why this is so, because the command-line is heavily used by programmers in most other domains I know.

Creating a new project

cd <android-sdk-dir>/tools
android create project --target <target-id> --name <name-of-project> \
--path <path-where-you-want-to-keep-your-project> \
--activity <first-activity-name> \
--package <app-package-name> 

For target-id do
android list targets
to see the available targets and select an id from them

Example:
android create project --target 1 --name MyFirstApp \
--path ~/Apps/MyFirstApp \
--activity MainActivity \
--package com.example.myfirstapp

Making changes

I use emacs to edit the java code generated, and the layout xml file main.xml. To test any non-Android-specific piece of functionality it is a good idea to try it out in a stand-alone .java file outside the project. I have done this for trying to do a http request and it has helped.

Building the app (debug version)

cd <your-project-directory>
PATH=<android-sdk-dir>tools:$PATH ant debug

Launching the app in your emulator or phone

Start up your emulator by opening the avd manager:
<android-sdk-dir>/tools/android avd

Otherwise, plug in your phone and turn on USB debugging.

In your project directory, do:
<android-sdk-dir>/platform-tools/adb install bin/<app-name>-debug.apk
<android-sdk-dir>/platform-tools/adb logcat

Your app is installed, run it and look at the logcat output running on your command-line to debug what went wrong. I am assuming you have put enough Log.d() messages in your app code.

After you're done, you can uninstall the app by doing
<android-sdk-dir>/platform-tools/adb uninstall <package-name>

where package name is that com.example.myfirstapp or something you gave while creating the project

Note: Google's documentation has all of this information - you just have to fish it out since their main focus seems to be Eclipse/Android Studio based development.

Wednesday, April 1, 2015

How to learn programming

There is a huge 'learn coding' wave nowadays. Coding is, as we know, common parlance for computer programming. Many people are prophesying that coding will soon be the new literacy. I don't totally agree with this with stand, but I do realize that programming a machine is a fundamentally new invention of mankind (like the invention of writing) which will lead us into different ways of thinking (like writing did).
What I don't really agree with is the numerous 'teach coding' programs around.

I'd like to give my views on programming and how to learn it, from my own experience of more than 10 years (college+industry). The first and most important thing to know is that programming cannot be taught. It can be learned, by doing it. Yes, you will get stuck every day while you are programming and then you will have to refer to some guides, or consult an expert, or listen to a class. But your guide or your teacher will only give you inspiration, direction, and clarity. And also what he/she thinks.
But programming is like human thought -- it is continuously evolving. When you are stuck at a problem, you might come up with a different way of programming which no one has done yet -- and this has been happening regularly for the last few decades.

As I see it, the way you advance in programming is:
1. get inspired and get some direction, by talking to someone, or listening to a good classroom lecture, or whatever works for you
2. get started and get stuck as soon as possible -- getting stuck is crucial to learning programming (it is crucial to any learning)
3. go back to the references, talks, scratch your head, and come back to step 2.
This is why I like programming so much -- it is such a very practical art which one cannot learn theoretically.

Thursday, March 12, 2015

Hurdles in android development

I have recently started trying to create an android app. Belonging to the command-line world of C/C++-gcc-make-linux this entire IDE-based development system is a big puzzle to me. I am not averse to IDE's. I wrote some of my first programs in Visual C++ 6 which was a terrific IDE. But somehow I could never get the hang of Eclipse, and could never appreciate why people used it when it took so much time to start up (VS was fast).
Coming back to android, I have succeeded in building a bare bones app from the command-line, and using Google Play services in it. The problem is that most guides on the internet (including Google's) lean heavily on the Eclipse or Android Studio paths. I couldn't find much guidance for the problems I have faced so far, and they have taken me a long time to figure out.
For example, when I tried to integrate Google Play services (for using GPS location data in my app) everyone told me about copying the google_play-services_lib folder to the libs directory of my project, and also updating the project.properties file of my project. But no one told me about putting a build.xml file into the google_play-services_lib folder. I learnt it the hard way.
The latest problem I was facing is that I couldn't install apps onto my phone because adb was complaining about my device being unauthorised. I did run my app on the emulator -- but that is a very slow way and practically useless for testing anything apart from the UI. Today, I finally found the answer to my problem in this stackoverflow post. And my app now installs merrily on my phone.
My next target is adding unit testing to the app's code, and also improving the location-finding capability. Let's see how I progress.