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.
Decisions and implementations – different mind states
- Color of the title
- Text of the placeholder
- Refactoring legacy method, or leaving it be
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:
- Not sure if singleton is the right way, ask Walt
- Duplicating that code because I want backward compatibily and afraid to screw up, ask Walt
- This graph looks shitty, ask Walt why are we plotting number of stars against day of the year
- first cycle (groundwork): 5 minute (99% of the article)
- perfecting: 10 minutes afterwards (rephrased three sentences, added this paragraph and put some commas)
- perfecting: 15 minutes couple of hours later
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 !
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:
- TODO list app
- Game Of Life
- Space Invaders
- 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.
OMG I’ve been forked !
My sample project for Hadoop prime calculations have been forked. I’m a proud contributor 🙂
https://github.com/serjSmor/HadoopPrimes-Azure
That reminds one of the most memroble scenes of the epic first American Pie.
“I’ve been used !”
Fork, and be forked.
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.