Burak Dede's Blog

Catching Up with Android Development

March 21, 2017

It has been a long time since I develop anything for mobile screens. My native mobile development story started around 2009 with Android 1.5 and since then I move onto different platforms including iOS to Blackberry (yes blackberry). I stop developing for mobile phones around when Android 4.x came out. I had my personal reasons to not continue developing but some of the high-level ones are

  • inconsistencies around device types and APIs
  • backward compatibility mess
  • lack of stable development tools

I stopped actively developing anything but still followed most of the news and changes. Since I have time lately I decide to give it a shot to see if anything above changed or at least is it still fun to do mobile development like when I started. This is post is all about catching up on the Android side.

IDE, SDK, Emulator, Phone

These four prerequisites are still required in order to start developing but it is much more fluid right now. Android Studio come prepackaged with Android SDK (I think it is the latest one) and you don’t have to deal with setting up SDK or connecting it with IDE, adding plugin etc.

Apply Changes

I must say emulator is much faster and usable and with the new Apply Changes option change-test cycle is really easy.

Since there is not much defacto book on Android and it is really hard to keep content of the book updated with ever changing Android SDK best way to consult is Android developer page (https://developer.android.com/training/index.html)

[Update] I read Big Nerd Ranch book Android Programming before and from release date it looks like it is up to date with latest Android version so if you are interested in books you can check that one.

I have minor issiues with phone and Android Studio bridge but fixed it with downloading driver from manufacturer site, still much better than editing files with manufacturer codes.

ViewGroup, View, XML

As you may expect Android development still going around xml viewgroups/views and java code but I must say Android Studio is making this so much easier. We still have ViewGroups (layouts) and Views (widgets) and XML for designing UIs. ConstraintLayout is new for me but it looks like RelativeLayout but much more powerful and have lots of option to place your views according to parent or sibling views.

ConstraintLayout is new ViewGroup and designed for adaptive UIs and tries to make ViewGroup tree more flat so that rendering will be quick. It looks a lot like RelativeLayout but much more adaptive one depending on the constraints and other elements.

Rendering times for the changes on design view is much faster even though multiple changes takes places still you can see the results in a fairly efficient way. Project structure starts to get messy when you app reach to significant size but new project structure makes it really easy to navigate with IntelliJ great search shortcuts.

new project structure

And finally when you add new Activity class it will be added to AndroidManifest automatically. This probably will save hundred or thousands because of why is this chrashing and then you realize you forgot to add new activity to manifest bugs are now gone.

Around 2010-2011 there are good books about Android but as we reach to 2014 most of them become outdated. Even though there are not good quality books out there I must say Android docs doing a really great job.

Where Is My Classes and Classpath?

March 15, 2017

What is the deal with classpath?

Ok I admit, I did not understand what is the use case for classpath when I started programming java or other JVM languages. But believe me, it is important. IDE and programming environments just shadow this knowledge with their fancy interfaces but you hit the wall hard when things get messy on production or whatever the environment you are running your application different from your fancy IDE.

Basically classpath is where java compiler (javac) and virtual machine (java) looks for your class files when they are referenced.

That is it, it seems trivial at first but searching mechanism is a bit more elaborate. By the way, I will show this case with java compiler javac but searching mechanism is not much different in virtual machine case. I will try to focus on search case not the verbosity of the java language, so I will try to use minimum classes.

The Classpath Case

Here are the two simple classes for our case.

package com.mycompany;
public class DBConnection {
    public static void main(String[] args) {
        System.out.println("This is the main method of DBConnection class\n");
    }
}
package com.mycompany;
public class User {
    public static void main(String[] args) {
        System.out.println("This is main method of User class\n");
        DBConnection db = new DBConnection();
    }
}

So two really fundamental classes, one is just for printing simple stuff, other both printing and only referencing it. No IDE help here so you have to create a simple structure manually for this project.

mkdir testj
cd testj
mkdir -p com/mycompany/
cp User.java DBConnection.java com/mycompany/

Above commands would make a simple structure for our test case.

You can name your root level folder whatever is suitable for your case. In my case, it is testj but tree structure must match com/mycompany/

Test Ride Classpath

Let’s first override the classpath and make compiler look nowhere for class search.

cd com/mycompany/
javac -classpath "" DBConnection.java

Above command will tell java compiler to look nowhere (in that case “”) for class files and try to compile **DBConnection” class. And it will success while doing that. It will not fail because compiler easily found the DBConnection file and it does not reference any other class.

cd com/mycompany/
javac -classpath "" User.java

Above command will fail and gives the following compile error.

User.java:5: error: cannot find symbol
        DBConnection db = new DBConnection();
        ^
  symbol:   class DBConnection
  location: class User

Why is that? All files needed to compile just there? Ok, compiler will try to find User class and had no problem doing that and after that it will see that there is DBConnection reference and try to find it in the same com/mycompany/DBConnection. Guess what? the compiler does not know where to look because we told it to look nowhere. Let’s change that to look for the current folder which is logical to do.

cd com/mycompany/
javac -classpath "." User.java

Still no luck, what is going on? Ok, we may be messed with compiler search thing when we gave it ”.” (current folder) path. Here is what compiler do in this case it will search again for DBConnection in com/mycompany but in this case, we gave it a current folder compiler will try to locate DBConnection in com/mycompany/com/mycompany which does not exist.

”..” is an upper directory in Unix case.

Let’s fix this mess and give it relative two level upper directories so that compiler can aim right folder for compilation.

javac -classpath "../../" User.java

That command will successfully compile both files and ready to run by the virtual machine. But it is kind of ugly because we are dealing with relative paths. Let’s change starting point to the root folder and give relative path from there.

cd ../../
javac -classpath "." com/mycompany/User.java

This will also compile and much better looking than the first successful one.

”.” does not mean look for the current folder for search but start from the current folder, it can go deeper if it wants.

We can also compile these two classes with single wildcard and not mess up with classpath much.

cd testj/com/mycompany
javac -classpath "." *.java

This will extend wildcard to match all the java files in that directory because compiler now has all reference in its hand compilation will be successfull.

Class Files and Java Files Hell

After compilation will place the .class files along with .java files so it not much a problem when you are working with two files but will be a mess for larger projects.

Class folder to the rescue!!!

cd testj
javac -d classes -classpath "." com/mycompany/*.java

This will compile all the files inside the com/company and place their output inside classes folder with related folder structure. When I mean related folder structure when you compile “com/mycompany/User.java” the output will be “com/mycompany/User.class” and will be in folder classes

That is all great we can compile and product output in whatever folder we want but this is kind of messy and can lead to errors.

Jar to the rescue!!!

I did not say Jar file because Jar is actually folder

jar cvf mylib.jar com/mycompany/*.class

When you use jar utility to package your java class files, you can give jar to classpath so that compiler peeks inside your jar file.

javac -classpath /myclasses/mylib.jar ...

There is also system CLASSPATH case even though it solves most of the problems by setting CLASSPATH environment variable and even better by adding it to your .bashrc it is easy to forget you have setted that and suprise yourself by compiler errors.

My Jekyll Blog Setup

March 8, 2017

It has been a long time since I set down and write a blog post about something. For the last 10 year, I constantly changed the platform for my blog from WordPress to Posterous(defunkt) to Jekyll to Medium and Ghost. The thing I wish I had done differently is backing things up properly when I change platform and give more care to my content. Anyway, I am back with Jekyll and I am considering staying a long time with it. I am already a paying customer for GitHub and I wanted to own my content so Jekyll seems like a good way to back things up and own your content.

Finding Theme

Default theme comes with Jekyll is not that good for my own taste and I wanted to find something minimal and nice on the eyes. While surfing some GitHub Jekyll repositories I came across this repo. I like wider layouts so I tweaked Sass a little and change a couple of things related to layout and it looks good enough for me right now.

Jekyll

I have used Jekyll in the past but without knowing some syntax and details of it. I think it is one of the reasons why people abandon some tech or tool, not knowing details and philosophy behind it. I sat down an afternoon and read official documentation of the Jekyll and created a couple of templates, played with the liquid template engine. I still have missing parts but I think I can easily say that now I know what I am doing with it.

Seo

This is something I usually give zero care but it is important if you don’t have an audience or reach like Medium or other hosted platforms. People usually reach your site trough social media links, newsletters or search engines. For this, I used Jekyll SEO plugin which is really easy to setup just add jekyll-seo-tag to your _config.yaml and you are good to go. Add related content to your YAML front matter and it will automatically create meta tags for you. Of course, every page to take SEO tags change your default template in _layout folder and add seo tag before the head tag.

For more information check offical doc from GitHub.

Sitemap

This is related to seo and it is important. I have used Jekyll Sitemap plugin without much customization. Add it to your _config.yaml and your _site folder will include sitemap.xml for the next build of your page.

For more information check offical doc from github.

[UPDATE] I came across Google Search Console tool which helps you track any kind of event whether it is sitemap, robots.txt or any crawled content. It looks like it sends reports related to current status of the page weekly/monthly. But beware it take a little while to get data on search console. You can check google help page for more information.


<html lang="en">
{% include head.html %}
{% seo %}
<body>

Newsletter

Even though most people rely on social media for reaching an audience I found the newsletters still a thing so I searched for a free solution since it is a nice to have. I found TinyLetter which I think backed up my MailChimp and with free account allows your to have 5000 subscriber which is more than enough for me.


---
layout:none
---
<!-- newsletter layout -->
<h1>Latest Posts on {{site.name}}</h1>
<!-- add site logo here -->
{% for post in site.posts limit:6 %}
    <h2>{{post.title}}</h2>
    <p>{{post.summary}} <a href="{{post.bitlylink}}">Read more &raquo;</a></p>
{% endfor %}
<!-- add ads here?? -->

Created new layout for mail by taking last 6 posts with minimal makeup. Added summary of every page to YAML front matter and created bitly links which also added to YAML front matter to measure clicks and other stuff. Measure everything!!!

Still not that automated but will work on it. By the way, you can test it by reaching to the end of the page and subscribing with your mail.

Caching, SSL, CDN

I decide to use CloudFlare after checking site speed with Google SiteSpeed tool. I had red flags on caching (GitHub provide 10min cache) so using CDN seems logical. I set up CloudFlare account and updated my DNS with CloudFlare’s to redirect traffic to them. (it is in the pending phase right now) Plus they provide SSL, AMP and other extra stuff for your site with just a free account. This is still in progress and we will see how it goes. There is nice tutorial how to work CloudFlare with Github Pages.

Update my site currently works over SSL and force all the traffic through https so CloudFlare works like a charm.

For image and assets on my site, I am using ImageOptim app to compress and get every bit of optimization for the page. Every time I place new asset for the site it is optimized already.

Writing

I already know enough markdown to be dangerous so I am writing my posts with markdown. First, it starts with a draft on Grammarly to check every bit of grammar in real-time. It is an awesome extension and really easy to use and it is free with acceptable limitations.

After being done with the draft I update the post with markdown give links to their right places and build site locally jekyll serve to see if anything wrong with it. After everything went fine I push the new post to Github for production site to be built. Done!!!

Book - Zero to One - First Part

March 8, 2017

For the last 2 weeks, I have been reading on and off Peter Theil’s Zero to One book. I kind of liked the book and decide to take some notes on important parts.

Book have a clear writing style and really easy to read. I probably finished it in total 2 days of reading and it has total 14 chapters. The reason I finished it quickly compared to other books is that I like kind of books mashing up past experiences and historical data to give advice about technology/startups/businesses. Peter Theil exactly doing that in the book, taking all his past experiences and mashing it up with data related to startups and making claims on monopolies, culture, hiring, marketing and future technology.

What does zero to one means?

In his view, doing things that nobody has done before means going from zero to one, a technological breakthrough, like creating word processor from a typewriter. This is called vertical progress. While he claims that if you are taking something already working and copying it or changing little means going 1 to N so as horizontal progress. He also relate horizontal progress as globalization like Chinese copying some working products and making new markets for themselves.

Peter Theil Zero to One Graph

What really happened in dotcom crash?

It was an era that people created companies like crazy that provide no value so just to get a little piece of the whole cake. People started and run multiple internet companies from their living room and only become rich on the paper even though they have no actual money for living. Seems like using company share to pay big party bills was a regular move at that time. Of course, it ended not well for that people. Following lessons learned from that era

  • Make incremental advances or It is better to risk boldness than triviality
  • Stay lean and flexible or A bad plan is better than no plan
  • Improve on the competition or Competitive markets destroy profits
  • Focus on the product, not sales or Sales matter just as much as product

Monopoly or a perfect competition?

Your company can be in one of the two different markets either in a monopoly which you surpass all your competitors market share or you are in a perfect competition that getting even small market share is blood battle.

Monopolies generally do not sell themselves as monopolies because doing that put the target behind their back so auditions, lawsuits will be a big problem in the future. Google for example gets %95 percent of their profit from ads while putting themselves as a consumer tech company not advertisement monopoly. Monopoly companies can set their own prices because of their big market share. Author also believe that being monopoly is a good thing. Because your are monopoly and your proiority is not profit anymore you can put much more effort on vertical progress.

On the perfect competition side since no company has any market power no one is capable of changing prices. Contrary to that companies lower their prices in order to gain market share. This will also lower profits which make some of them go out of business in short time. Economy classes advertise perfect competition as preferred state but seems like it not working in real world mechanics.

Zero to one monpoly

Characteristics of Monopolies

Proprietary technology look at what Google did to other search engines with their search algorithm. You have to have at least 10x better technology in order to gain advantage in this side.

Network effect so that people have a hard time choosing other product while all your network is here. Facebook is the best example. You do not go to other networks while all your friends are here.

Economics of scale allows you to use fixed costs for a product while growth is not affected by later costs. Twitter is a good example, monopoly gets stronger as it gets bigger. Twitter cost are not skyrocketed when they reach their hyper growth phase and there is nothing stop them to get bigger and bigger.

Branding of course not without mentioning Apple look at Apple brand and others.

  • Start small If you think your market is big than it definitely is. Look for power users with a small market to dominate. It is easy to dominate a small market.
  • Scale up After dominating the small market look for similar user groups and markets. Amazon started with books and move onto other categories as he dominates. Paypal started with Ebay power users and move on from there.
  • Don’t Disrupt Do not start with disrupting, disrupting means trouble.

Be the first mover if you can continue your cash flow in the foreseeable future if not it is better to be the last mover.


powered by TinyLetter