Android O

Android O is coming out in a few weeks, so I’ve decided to write about the upcoming changes in SafeDK’s blog (where I work), also I had the benefit of discussing these exciting news with our Android team lead – Ori, who helped to translate my wombelings in to a coherent piece.

So no further ado

Decisions and implementations – different mind states

If your current programming task is loose, without much specced details, you’re in trouble. You will be engaged in a constant ping pong and redoing/rethenking probably 80% of your work.
Worst than that, whenvever you have to make more than 3 decisions in a row, let’s take these 3 for example:

 

  1. Color of the title
  2. Text of the placeholder
  3. Refactoring legacy method, or leaving it be

 

The next decision you will make probably going to be shitty, unless you will empty your decision pool by doing the first thing that comes to your mind, just sticking something to it. That’s exactly what I’m doing now, a struggle between the flow of thought which feels natural, without much pondering, or the opposite, drilling down every specific detail. This two states of mind are opposites and we as professional programmers, and, well, people, should be aware of the implications of each state. There are times that we need the first and times when we need the second. You move from one state to another in cycles/iterations which reminds me of Agile or Scrum methodologies.

 

I prefer to call it cycles. First cycle is laying groundwork. You write down  whatever you are going to construct, without getting into detail. It’s essential that you won’t be tight about it or it will shoot you in the leg and bark the whole night at you and you won’t get to sleep and you’ll be tired the whole next day, because you were perfecting one measurable piece of stupid napkin paper.
Okay, cycles, first cycle: write something down. It should be a general plan, the outline of the algorithm, with as many specific details as you fancy as long as it won’t take too long.

 

Second cycle: start implementing that pickle. Now, you need to follow through your plan. Whenever you are stuck, trying to decide something, if you don’t come up with an answer straight up you should write down the question and follow through. My advice is to use  some note keeping software, this is the stuff of legends, Evernote specifically. Don’t have a note keeping software? Please do yourself a favor and download one. This is the most important thing, emptying your decision pool. This will later lead to better decisions because you won’t be not under stress to figure it out instantly in order to proceed implementing it. Sometimes stepping back gives you a better perspective later when you deal with the issue. Some examples:

 

  1. Not sure if singleton is the right way, ask Walt
  2. Duplicating that code because I want backward compatibily and afraid to screw up, ask Walt
  3. This graph looks shitty, ask Walt why are we plotting number of stars against day of the year

 

Third cycle: ASK THE QUESTIONS, WRITE DOWN THE ANSWERS
and we go back to cycle 1.

 

That’s it, pretty simple aye?

 

In my opinion, it’s the best analytical process for every task there is. It’s the key to your success, life fulfillment, and Arduino side projects. Don’t be torn by details you don’t know. You shouldn’t decide and implement at the same time, it’s counter productive. Lay some groundwork, do some lifting and iterate your whole life, separating decisions from the flow of your actual doingness ( .  Read about decision fatigue: https://en.wikipedia.org/wiki/Decision_fatigue

 

From the wiki article: There is a paradox in that “people who lack choices seem to want them and often will fight for them,” yet at the same time, “people find that making many choices can be [psychologically] aversive.”

 

Aversive is bad if you are wondering about the alignment of that adjective.

 

P.S I live by this rule, and written this article in the following cycles:

 

  1. first cycle (groundwork): 5 minute (99% of the article)
  2. perfecting: 10 minutes afterwards (rephrased three sentences, added this paragraph and put some commas)
  3. perfecting: 15 minutes couple of hours later

 

Because the actual task is writing, cycle number 2 which is implementing is the same as cycle one.

 

It took me thirty minutes to write this post, instead of days of proofreading each word which otherwise would have been my destiny.

 

To sum it up,  we have a limited pool of decisions. When developing software this can lead one to be stuck many too often and to lower the quality of the decisions she makes. Instead I suggest to use your notes as a bank and deposit every question there (with some constraints of course) and proceed in the meantime to follow the sketch you have done before, in so called “cycles” or “iterations”.

 

Agree ? Disagree ? You use some different technique ? Do tell.

Boolean magic

Have you ever seen obscure code with “magic” numbers all around?

Which ‘for’ would you like to encounter at a random class file of a new task you just received?

for (int i = 0; i < 12; i++)

The first one is ‘pure’ voodoo magic, we will have to decipher this using our peripheral logic, looking all around trying to make sense why something is exactly 12. Even it’s writer will stare at it a bit until he remembers what he meant.

for (int i = 0; i < 12; i++) // 12 months

The second one is a dove out of a sleeve magic, we understand how it’s done but we ponder about the dove being hours in this magicians suite. Or to paraphrase it a bit, comments are better than nothing but sometimes they can be worse. Sometimes code changes but it’s not certain that the comment that goes along with it will change accordingly, especially if it’s two different developers. No one likes to take a decision such as deleting/changing a comment.

for (int i = 0; i < MONTHS_IN_YEAR; i++)

We’re out of magic powder! I think I read in Martin Fowler’s clean code that comments are a code smell. If you feel like commenting, think how you could refactor your code in a way that will documnet itself.

I don’t think I shocked someone up until now. It’s a pretty known issue not leaving around ‘magic’ numbers. Use constants and enums whenever possible.
So how come the same lesson is not learned in the field of booleans?

which method call is clearer?

sendEvents(events, true)

sendEvents(events, true) // flag to clear the events

sendEvents(events, TO_CLEAR)

It’s not a scentific fact, and more of an opinianated view, but I really believe that the third method documents itself pretty well. In a world that magic numbers are forbidden, so should boolean voodoo being avoided.

Next post I’ll go into debugging and strategic problem solving.

Back from Thailand

Hey all, from now on I’ll be switching to engrish.

I just came back from a month trip to Thailand. It was the rainy season and me and my GF feared of heavy rains that disrupt our plans but none of that happened. Actually what did bum us out was a Sting Rey attack that put her (and her companion a.k.a me) to a hospital bed for a week. She’s gotten better and that’s what matters.

TL;DR Thailand is fun. In case of a Sting Rey attack (R.I.P Steve Irwin), put the damaged part in hot water and go straight to hospital for a proper disinfection.

I came back energized and eager to continue with my C.S antics and went to my first interview already (Android job). The company had some old age Linux magazine that led me to a decision to subscribe to a couple of magazines (Linux, Cyber Security and social hacking  scene) of my interest. Nothing beats reading Linux fan pic in the restroom. No Android magz though.

Do you have any suggestions for magz, printed or digital ?

 

 

 

 

Workshop instructions

  הסדנה עצמה תהיה מורכבת מ4 מפגשים, היא מיועדת לקהל שכבר מכיר תכנות ברמה כזאת או אחרת, עדיפות לשפות עיליות ומונחות אנחנו נתארח בתאמי – קיבוץ גלויות 45, תל אביב .Java, C#, Javascript עצמים כמו

 שיעור ראשון: הכרות עם המערכת, נתונים לגבי שימוש בעולם של הפלטפורמה, קצת על הלינוקס שבפנים. פרקטיטקה –  מעקב אחרי דף משתמש, אפליקציה ראשונה של כפתור והוספת מספרים.

 .בנייה של אפליקציה לשמירת משימות, activities מעבר של מידע בין  , xml שיעור המשך הכרות עם רכיבי הגרפיקה ו

.Game of Life שיעור שלישי: הכרות עם תכנות בסיסי של משחקים, לולאת משחק, תכנות של

  .כתיבה של המשחק פונג ,View ל SurfaceView  שיעור רביעי: הבדל בין

JDK 7 הנחיות לשיעור ראשון: כדי להתקין מראש את סביבת הפיתוח

http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

Android Studio וגם להוריד

https://developer.android.com/studio/index.html

 serjsmor@gmail.com מוזמנים לשאול שאלות, המייל שלי

My first Android workshop

I’m so excited ! And I just can’t hide it !

i-m-so-excited-meme-generator-i-m-so-excited-i-just-cant-hide-it-f7a2e3

After returning from Midburn (Israeli burning man event), I felt like giving back to our community. With that said I’ll be conducting a hands on workshop with some emphasis on basic gaming in the Android environment. It’s for programmers with at least some knowledge before hand (not that much).

We will cover the projects I’ve been working on solo and with my student.

Some of them:

  1. TODO list app
  2. Game Of Life
  3. Space Invaders
  4. Brick Breaker

 

I’m sure it’s gonna be fun for everyone. Thanks to TAMI (Tel-Aviv makers, an amazing place. For the people, by the people) for the opportunity, I’ve attended a Linux workshop before in there and I’m glad that I can contribute some.

First meeting is Wednesday 22.6, Seeya !

 

JNI GCC mac OS Yosemity tutorial notes

JNI

Developing Android apps ? Ever thought about developing a bit with the NDK (throw some C/C++ with your Java code) ? Then you have to know your JNI (the way Java interfaces with C/C++ since Java 2 – 1997).

Just finished my HelloWorld and wanted to share bottom liners that might go boom-boom.

In order to get started I read the following: 1, 2.

Another general source is the classic book: The Java Native Interface (download link).

Following the guides, trying to run java HelloWorld I’ve encountered the following exception:

Exception in thread “main” java.lang.UnsatisfiedLinkError: no HelloWorld in

java.library.pathat java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)at java.lang.Runtime.loadLibrary0(Runtime.java:849)at java.lang.System.loadLibrary(System.java:1088)at HelloWorld.<clinit>(HelloWorld.java:9)

Cause:

libtool -dynamic -lSystem HelloWorldJniSample.o -o HelloWorldJniSample.jnilib

On the mac, JNI libraries should start with the prefix lib, which wasn’t stated anywhere in the links I’ve provided.

Fix:

libtool -dynamic -lSystem HelloWorldJniSample.o -o libHelloWorld.jnilib

That’s it folks. More to come!

Later post I’ll described how I’ve built the Android eco system, a.k.a AOSP.

Flurry fury

A quick rant with facts.

I know Flurry for a while now. We’ve met during my first real coding gig at a Tel-Aviv big shot startup. It’s my goto analytics SDK, which is plain to use both on iOS and Android (yay).

I was trying to measure some feature_shape clicks, which had 3 different shapes; square, circle, triangle. Pretty simple. Flurry allows it using their logEvent method and passing a map with parameters to that method. That’s the easy part.

public void baseShapeEvent(String baseShape) {
    baseShapeParams.put(BASE_SHAPE_EVENT, baseShape);
    FlurryAgent.logEvent(BASE_SHAPE_EVENT, baseShape);
    baseShapeParams.clear();
}

Update rates:

You can notice the new event, or another aggregate of the same, pretty fast. Couple of minutes or so. But the event parameters are updated only after some 12 hours (boo), which is frustrating when you want to juggle some experiments and log different things using different methods, not wanting to wonder whether the map might be empty. Even more, the exact time is vague and varies. SO sources: 1, 2, 3.

Happy Passover ( in english it sounds like some hangover euphemism) !

GitHub projects : Fabric Azure + HDInsight Hadoop

Out of curiosity I’ve tried some backend technologies that seem to be Buzz noted. Also I’ve decided to try Microsoft’s PaaS Azure and C# in order to implement this.

I’ll write some major posts about each of the technologies, but in the meantime you could check my basic implementation sortof HelloWorld style. The main idea was counting a list of prime numbers.

It was difficult to understand all of the architecture both of the technologies due to none medium projects. I found only HelloWorld style or medium-high entry level projects. So I decided to share my non-too-complex-yet-not-basic implementations.

Azure fabric reliable actors microservices GitHub

Hadoop HDInsights PrimeReduce