2014-06-27

Level Up - Dev: Codestyle Quote

    "Any fool can write code that a computer can understand.
    Good programmers write code that humans can understand."
    
      --- Martin Fowler, Refactoring: Improving the Design of Existing Code

~ Danial Goodwin ~



2014-06-23

Research says Work and Study Harder to be more Successful

Research shows that people who work and study harder tend to be more successful.


~ Danial Goodwin ~

ps - I have absolutely no sources to back this up, but it's something nice to believe in. ;)



2014-06-21

Book: The Inner Game

The actual title of the book that I just read is called "The Inner Game of Tennis", but this post is not about tennis.

This was a great read, and you should read this book if you play sports and have ever wondered why you play good one day and bad the next. This book may help you have a more consistent and higher gameplay.

I wrote a whole bunch of notes as I read, and you can read them on GitHub.

If it's too much trouble to click a link, then here's the TLDR (Too Long; Didn't Read) that shares just a few of the biggest points:

  • There is an inner game and outer game. There are already many great resources on the outer game.
  • During practice, analyze your movements (methods includes "feeling" it, mirrors, video playback) and don't try to force any change. During game play, just let it happen naturally; trust yourself.
  • Experiment with many different playing styles. The "right" style may be different for different people.
  • You still may need some good outer game practice in order to gain more from these inner game tips.
  • If you dislike competition, then you have the wrong idea about it.
  • When playing, if you have any anxieties or frustrations, then you aren't a player of the inner game.


And, if you have already read this book or any of the other "Inner Game" books, then I'd be happy to hear your biggest take-aways.

~ Danial Goodwin ~



2014-06-18

Level Up - Dev: Integer Overflow Not Overflowing

An integer overflow (or wraparound) occurs when a number larger than the max integer value or smaller than the min integer value is tried to be stored in the integer's memory. You could imagine a circular number line.

Ex: If you have an integer at the max positive value and add one, then the integer will wraparound and be set to the most negative value (if using a signed int. An unsigned int will wraparound to 0). And, vise-versa.

Today, I experienced a bug where I wanted to get a (signed) integer overflow, but unfortunately the int value was just going to zero instead of going to the negative numbers. Thankfully, I knew the memory/bit representation of int and was able to figure out what was going on.

Here is some simplified code, with only one small change:

    // Test #1 - has wraparound
    int wrap = 1;
    for (int i = 0; i < 34; i++) {
        print(i + ": wrap: " + wrap);
        wrap = wrap * 3;
    }

    // Test #2 - no wraparound
    int wrap = 1;
    for (int i = 0; i < 34; i++) {
        print(i + ": wrap: " + wrap);
        wrap = wrap * 2;
    }

Here is the relevant output from running the code above:

// Test #1 - has wraparound
...
13: wrap: 1594323
14: wrap: 4782969
15: wrap: 14348907
16: wrap: 43046721
17: wrap: 129140163
18: wrap: 387420489
19: wrap: 1162261467
20: wrap: -808182895
21: wrap: 1870418611
22: wrap: 1316288537
23: wrap: -346101685
24: wrap: -1038305055
25: wrap: 1180052131
26: wrap: -754810903
27: wrap: 2030534587
28: wrap: 1796636465
29: wrap: 1094942099
30: wrap: -1010140999
31: wrap: 1264544299
32: wrap: -501334399
33: wrap: -1504003197

// Test #2 - no wraparound
...
20: wrap: 1048576
21: wrap: 2097152
22: wrap: 4194304
23: wrap: 8388608
24: wrap: 16777216
25: wrap: 33554432
26: wrap: 67108864
27: wrap: 134217728
28: wrap: 268435456
29: wrap: 536870912
30: wrap: 1073741824
31: wrap: -2147483648
32: wrap: 0

33: wrap: 0

If test #1 were to continue, then the values would keep wrapping. If test #2 were to continue, then the values would stay the same at 0.

The easiest way for me to make sense of this experiment was to know that multiplying by a power of 2 (2, 4, 8, 16, 32..) is the exact same as a bit shift in the binary computer. And, the bits that made up the int were all just getting pushed out of memory in test #2 until there were no more set bits to manipulate. In test #1, more int memory bits are being flipped in order to continue the wraparound.

I would explain this at a lower level, but there are already many great resources for "bit representation of integer".


~ Danial Goodwin ~

ps - This post was mainly for myself and written quickly. If there are any questions about this, then I'd be happy to elaborate.



2014-06-04

Level Up - Android Dev: KeyboardlessEditTest

Today, I've released a new open source project that has help me build my latest app. I needed an EditText with full capabilities, except for the keyboard showing up. All of the possible answers that I found on StackOverflow and GitHub all had their limitations, especially the lack of native editing (cut/copy/select/paste) options.

All of the problems have been abstracted out to a simple subclass of EditText that you can use easily in any project.

You can try it out on GitHub now: https://github.com/danialgoodwin/android-widget-keyboardless-edittext
Or, you can go directly to test the APK: https://play.google.com/store/apps/details?id=net.simplyadvanced.simplytonegenerator

If you have any questions or need clarifications on how to use the project, then please let me know.



~ Danial Goodwin ~



2014-06-03

Self-Driving Cars are Horses

I just finished reading an article introducing me to the idea that riding horses and "driving" self-driving cars are similar. I expand on that idea here and introduce practical applications of that knowledge, i.e, a fun way to promote the cars and showing them to be practical.


Basically, one example precedent for self-driving cars is the horse. When horse-back riding, you can either choose to (1) Do nothing, (2) Provide gentle directions (3) Strongly urge a direction. When the rider is doing nothing, the mode of transportation can instinctively go somewhere. When the rider provides directions, the mode of transportation will do them at the earliest convenience, typically immediately. But, the ride won't run into a wall or crash into other rides (a sensible default).


Armed with this knowledge, I think it would be a fun idea to make a video commercial about this. First, the ending to a spectacular action scene, then have a closeup of a cowboy (read: horseback rider) texting and riding. Then zoom out to show all the hard work that the horse has to do to keep the rider safe, like avoiding potholes and other horses. Then, zoom out again to show a parent and child enjoying watching that video inside the self-driving car that is doing the same things.


Random follow-up questions:
- Do we need to hardcode into the car to want to always safe itself from crashing or having a certain threshold or acceleration and deceleration?
- Should the cars think all objects are immovable solids to avoid, or should it use more computer vision (CV) to determine densities (and object types), just in case? Ex: Run into brick wall or bushes?


~ Danial Goodwin ~