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-18
2014-06-16
Level Up - Android Dev: Useful and Productive Android Methods
Great Android tidbits that developers should know to be more productive. Included are simple useful classes and methods that may not be well known.
http://blog.danlew.net/2014/03/30/android-tips-round-up-part-1/
~ Danial Goodwin ~
http://blog.danlew.net/2014/03/30/android-tips-round-up-part-1/
~ Danial Goodwin ~
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 ~
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 ~
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 ~
2014-05-29
Android: New Google Camera App
Good options for trade-offs between aspect ratio and size of each of the images for both the front and back camera.
~ Danial Goodwin ~
2014-05-17
2014-05-03
2014-05-02
(Game) Achievement Design
Fun little article I just read on Achievement Design 101.
The article mainly uses the game context to help explain good and bad achievement designs.
While reading it, I thought of a new game that I would like to see or create myself: The main idea is to have an RPG with skills for things that aren't in any other game. And, there would be plenty of achievements, like "You clicked on a button", "You made a choice. +1 to design making skill". and "You stood still! Great job!"
~ Danial Goodwin ~
The article mainly uses the game context to help explain good and bad achievement designs.
While reading it, I thought of a new game that I would like to see or create myself: The main idea is to have an RPG with skills for things that aren't in any other game. And, there would be plenty of achievements, like "You clicked on a button", "You made a choice. +1 to design making skill". and "You stood still! Great job!"
~ Danial Goodwin ~
2014-05-01
Software Companies Can Create Anything
"For software companies, the question isn't can it be built? The question is, should it be built?"
~ Danial Goodwin ~
~ Danial Goodwin ~
2014-04-30
It turns out that nurturance is the killer app.
"We don't just nurture what we love. Human beings are programmed to love what we nurture."
~ Danial Goodwin ~
~ Danial Goodwin ~
2014-04-18
Memory Match Theme Popularities Compared
Hi, here's my first go at building a Construct 2 (hybrid game app creation program) memory match template. I decided that I wanted to create many different versions to see which topics get the most popular so that I would spend more time developing the popular ones. So, which theme do you like the most?
Please try them all and let me know what you think. Or, maybe just 1-3 of the most interesting ones to you.
- Memory Match 3
- Memory Match: Roman Numerals
- Memory Match: Color Names
- Memory Match: Colors
- Memory Match: Numbers
- Memory Match: Alphabet
- Memory Match: Letters
- Memory Match: Wildlife
- Memory Match: Cartoon Animals
Results so far:
- Wildlife theme has the highest amount of downloads.
- Colors theme has second highest amount of downloads.
- Color names theme has second lowest amount of downloads.
- Roman numerals theme has the lowest amount of downloads. (Sidenote: These cards took the longest to create also, so good thing I didn't make more)
- My favorite, "Memory Match 3", is getting close to 100 downloads
This information could be good for any of your app that you may want to theme. Seems like people prefer the basics of wildlife and colors, rather than things that require more thinking like color names and roman numerals.. And, I have about 10 different versions that I need to organize.
~ Danial Goodwin ~
Please try them all and let me know what you think. Or, maybe just 1-3 of the most interesting ones to you.
- Memory Match 3
- Memory Match: Roman Numerals
- Memory Match: Color Names
- Memory Match: Colors
- Memory Match: Numbers
- Memory Match: Alphabet
- Memory Match: Letters
- Memory Match: Wildlife
- Memory Match: Cartoon Animals
Results so far:
- Wildlife theme has the highest amount of downloads.
- Colors theme has second highest amount of downloads.
- Color names theme has second lowest amount of downloads.
- Roman numerals theme has the lowest amount of downloads. (Sidenote: These cards took the longest to create also, so good thing I didn't make more)
- My favorite, "Memory Match 3", is getting close to 100 downloads
This information could be good for any of your app that you may want to theme. Seems like people prefer the basics of wildlife and colors, rather than things that require more thinking like color names and roman numerals.. And, I have about 10 different versions that I need to organize.
~ Danial Goodwin ~
2014-03-22
Level Up!: Do Users Need To Click "I Agree" to TOS Button To Give Consent?
(TLDR: No. Courts decide these cases simply by whether the person had reasonable notice of the Terms & Conditions. If you have a website/app and plan on collecting personal info or just have customers in general, the I highly suggest you read more about this topic. Disclaimer: IANYL.)
As a UX designer, I try to make things that are as simple and painless as possible for users to use. One pain (and protection) that almost every product/app needs is a Terms of Service (TOS) agreement, aka Terms of Use (TOU), aka Terms And Conditions (T&C), aka End User License Agreement (EULA).
The current "best practice" for showing TOS to users is by providing a clear link near the "continue to use app" button (which could be a register or purchase button). This is so that most users don't have to go through the extra step of clicking "I Agree" to something that they likely didn't read. Also, having the TOS pop-up interrupts users' flow (and can sometimes be quite scary-looking).
But, unfortunately, before today, I never really thought about the legal consequences of the different methods to show users the terms and conditions. I just used methods that I noticed many other great UX designers and companies using. So, I wasn't able to explain the legal-ness (to my satisfaction) to concerned client.
I took it upon myself to take the time to do some research around this area and organize it into this post, with sources and references cited.
In my research, I have found that the courts also know that most users don't read the TOS, and clicking "I agree" doesn't mean that the user has read it. What the courts look for is mainly that the user has had the easy opportunity to find and read the TOS, if they wanted to.
There are two main ways that users "agree" to TOS:
My Summary (Just from my research (links below), though more can always be done.)
A few sources I read, in order of my recommended readings (Yes, there is a "Good" before "Great", just because of what this post was supposed to be about):
- Great: How Zappos' User Agreement Failed In Court and Left Zappos Legally Naked (Forbes)
- Great: The Clicks That Bind: Ways Users "Agree" to Online Terms of Service (EFF)
- Good: Terms Of Use And Privacy Policy Best Practices (UpCounsel)
- Great: Website Terms and Conditions: Some Best Practices (JDSupra)
- Miscellaneous, but good: Terms of Service; Didn't Read (TOSDR)
- Good: Browse wrap (Wikipedia)
- Okay: Clickwrap / Browsewrap Agreements: It’s the Notice, Stupid!
Further Reading:
- Terms of Use and the Digital Millennium Copyright Act (DCMA)
- Search "Clickwrap vs browsewrap"
Disclaimer: I am not your lawyer (IANYL). This post's only intention is to help point readers in the right direction to learn more about this topic.
~ Danial Goodwin ~
ps - Bonus info! The terms "click-wrap" and "browse-wrap" come from physical goods/software that was "shrink-wrapped". Manufacturers had license agreements that basically said users agree to TOS by removing the shrink-wrap. (Source: Wikipedia)
As a UX designer, I try to make things that are as simple and painless as possible for users to use. One pain (and protection) that almost every product/app needs is a Terms of Service (TOS) agreement, aka Terms of Use (TOU), aka Terms And Conditions (T&C), aka End User License Agreement (EULA).
The current "best practice" for showing TOS to users is by providing a clear link near the "continue to use app" button (which could be a register or purchase button). This is so that most users don't have to go through the extra step of clicking "I Agree" to something that they likely didn't read. Also, having the TOS pop-up interrupts users' flow (and can sometimes be quite scary-looking).
But, unfortunately, before today, I never really thought about the legal consequences of the different methods to show users the terms and conditions. I just used methods that I noticed many other great UX designers and companies using. So, I wasn't able to explain the legal-ness (to my satisfaction) to concerned client.
I took it upon myself to take the time to do some research around this area and organize it into this post, with sources and references cited.
In my research, I have found that the courts also know that most users don't read the TOS, and clicking "I agree" doesn't mean that the user has read it. What the courts look for is mainly that the user has had the easy opportunity to find and read the TOS, if they wanted to.
There are two main ways that users "agree" to TOS:
- Click-wrap Agreement, aka "click-through agreement": This means that users must take some sort of action that signifies their consent to the TOS. This action could be a button that says "I Agree". Also, near the call to action, it is sufficient to say "By [continuing], you agree to our Terms of Service", with the TOS having a direct link.
- Browse-wrap Agreement, aka "not a contract": Basically, saying users agree to TOS by browsing website/app, and the link to TOS is not extremely easy to find in regular use. A link at the bottom of the website could be considered hard to find, especially when there are many other links down there too.
My Summary (Just from my research (links below), though more can always be done.)
- If your app collects or uses personal information, then use the click-through (clickwrap) agreement.
- Remove any clauses about unilaterally editing contract at any time.
- Add ability for company to modify terms, with prior notice. [More research needed for exact words to use]
- Add ability for users to reject TOS, e.g. by terminating account.
A few sources I read, in order of my recommended readings (Yes, there is a "Good" before "Great", just because of what this post was supposed to be about):
- Great: How Zappos' User Agreement Failed In Court and Left Zappos Legally Naked (Forbes)
- Great: The Clicks That Bind: Ways Users "Agree" to Online Terms of Service (EFF)
- Good: Terms Of Use And Privacy Policy Best Practices (UpCounsel)
- Great: Website Terms and Conditions: Some Best Practices (JDSupra)
- Miscellaneous, but good: Terms of Service; Didn't Read (TOSDR)
- Good: Browse wrap (Wikipedia)
- Okay: Clickwrap / Browsewrap Agreements: It’s the Notice, Stupid!
Further Reading:
- Terms of Use and the Digital Millennium Copyright Act (DCMA)
- Search "Clickwrap vs browsewrap"
Disclaimer: I am not your lawyer (IANYL). This post's only intention is to help point readers in the right direction to learn more about this topic.
~ Danial Goodwin ~
ps - Bonus info! The terms "click-wrap" and "browse-wrap" come from physical goods/software that was "shrink-wrapped". Manufacturers had license agreements that basically said users agree to TOS by removing the shrink-wrap. (Source: Wikipedia)
2014-03-21
How To Be A Good Programmer
Being a good programmer isn't about memorizing how to do everything. It's about being able to quickly research whatever you need to do.
~ Danial Goodwin ~
~ Danial Goodwin ~
2014-03-19
Always Create an API When Programming
Every time you develop a computer program or app, you should basically be building an API.
Getting in the habit of this will vastly improve modularity of your code, which in turn makes maintenance and future additions greatly simplified.
And, imagine, if you ever want to reuse code from one project in another project, then with proper abstractions you will be able to just quickly import the file(s) and carry on without worry, theoretically. ;)
~ Danial Goodwin ~
Getting in the habit of this will vastly improve modularity of your code, which in turn makes maintenance and future additions greatly simplified.
And, imagine, if you ever want to reuse code from one project in another project, then with proper abstractions you will be able to just quickly import the file(s) and carry on without worry, theoretically. ;)
~ Danial Goodwin ~
2014-03-15
Challenge to Self: Daily Creativity
Challenge to self: Be creative at least once per day and share with the world.
ps - My more creative side can be found at http://chaoticdan.blogspot.com/ ;)
ps - My more creative side can be found at http://chaoticdan.blogspot.com/ ;)
Subscribe to:
Posts (Atom)

