Saturday, December 17, 2011
ccColor3B constants.... A whole bunch of them.
Tuesday, December 6, 2011
Cached Property File Enum
A cached property file enum:
How it looks being used:
Code:
Test:
The .properties file:
FEATUREA=true
FEATUREB=false
FEATUREC=true
How it works:
The Pragmatic Programmer - Review / Summary Notes.
I have to add, had I read this when it was published it would have undoubtedly saved me some pain, but even with that it's always good to reaffirm some of your good habits, and keep your bad ones in check. It covers 46 sections with 70 different tips that are generally useful to any programmer. Jeff Atwood - coding horror made a list of all 70 tips.
As with most things some tips are "more equal" than others, the ones that really stick out and probably can't be emphasized enough are:
Care About Your Craft
Why spend your life developing software unless you care about doing it well?
Think! About Your Work
Turn off the autopilot and take control. Constantly critique and appraise your work.
Don't Live with Broken Windows
Fix bad designs, wrong decisions, and poor code when you see them.
Invest Regularly in Your Knowledge Portfolio
Make learning a habit.
DRY - Don't Repeat Yourself
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
Make It Easy to Reuse
If it's easy to reuse, people will. Create an environment that supports reuse.
Prototype to Learn
Prototyping is a learning experience. Its value lies not in the code you produce, but in the lessons you learn.
Don't Panic When Debugging
Take a deep breath and THINK! about what could be causing the bug.
"select" Isn't Broken.
It is rare to find a bug in the OS or the compiler, or even a third-party product or library. The bug is most likely in the application.
Design with Contracts
Use contracts to document and verify that code does no more and no less than it claims to do.
Crash Early
A dead program normally does a lot less damage than a crippled one.
Minimize Coupling Between Modules
Avoid coupling by writing "shy" code and applying the Law of Demeter.
Don't Program by Coincidence
Rely only on reliable things. Beware of accidental complexity, and don't confuse a happy coincidence with a purposeful plan.
Refactor Early, Refactor Often
Just as you might weed and rearrange a garden, rewrite, rework, and re-architect code when it needs it. Fix the root of the problem.
Design to Test
Start thinking about testing before you write a line of code.
Some Things Are Better Done than Described
Don't fall into the specification spiral at some point you need to start coding.
Don't Be a Slave to Formal Methods.
Don't blindly adopt any technique without putting it into the context of your development practices and capabilities.
Don't Use Manual Procedures
A shell script or batch file will execute the same instructions, in the same order, time after time.
Test Early. Test Often. Test Automatically
Tests that run with every build are much more effective than test plans that sit on a shelf.
Coding Ain't Done 'Til All the Tests Run
'Nuff said.
Test State Coverage, Not Code Coverage
Identify and test significant program states. Just testing lines of code isn't enough.
Find Bugs Once
Once a human tester finds a bug, it should be the last time a human tester finds that bug. Automatic tests should check for it from then on.
Friday, November 25, 2011
Determining iOS Hardware / Device
So to not diminish the user experience I decided to remove those reflections, on the interactive CCSprite, on the older devices.
I went searching and found : UIDeviceHardware - Determine iOS device being used
I ended up just using: (platformString wasn't useful to me) I then just created a convenience method for myself to check for the version that have the Dual-core Apple A5 processor.
Sunday, October 16, 2011
Cocos2d CCSprite Reflection
What I want to share today is my little hack to reflect a CCSprite used in to cocos2d. I say hack because it does feel a little dirty, i didn't go and learn about the details of Open GL and the like, simply patched things together to get a working solution.
Below is the code for my ImageReflector, the basic idea and how it got it work was simple:
The best looking reflection example I found was Apples' example. So the methods createBitmapContext, createGradientImage and reflectedImage are directly from the above example. I wanted to use it in cocos2d so I used CCRenderTexture to create a UIImage, passed that to Apples' example code and then simply converted back to a CCSprite with the help of the CCTexture2D class.
Usage: Class:
Friday, September 2, 2011
iPhone Gmail Username / Password Error
Cannot Get Mail - The user name or password for imap.gmail.com is incorrect.
After a bit of searching, I found the solution to be simple, logon and input the Captcha phrase.
Link Below:
https://www.google.com/accounts/UnlockCaptcha
Wednesday, August 31, 2011
Mac OSX Global Git Ignore - XCode Project and State Files.
A little later, my wife joined me in working with those projects only to discover that under certain scenarios we could never actually merge or sync the branches from XCode. There were always couple files that would be "uncommited" in XCode. Nasty XCode project state files.
I had not worked with Git before this actually, so after reading up a bit about project files and the like and how a ".ignore" file would do the trick.
After I little bit of struggling, I realized that for ignore to work, the files needed to be removed from the repository first. Thankfully I did not have any important history so I could simply recreate them. You can also remove them from git with: git rm --cached
To go about creating, editing configuring a global ignore file on OSX I did the following:
First problem on a Mac, any "." files are seen as system files and those are automatically hidden from you.
To get around that open "Terminal" and use the commands below to show and hide system files (you'll need to either restart or force quit Finder for the changes to take effect).
Show:
defaults write com.apple.finder AppleShowAllFiles -bool true
Hide:
defaults write com.apple.finder AppleShowAllFiles -bool false
Once I had done that I simply went searching for a couple example ignore files and combined them into the example below.
Create a file in your user directory called ".gitignore_global", populate it with the contents required, (below is mine, that does take care of the XCode problem files)
Then in Terminal run:
git config --global core.excludesfile ~/.gitignore_global
My global ignore file:
Wednesday, August 24, 2011
Java / XML UTF-8 marshalling and validating pains
If you use a FileWriter instead of a FileOutputStream it will use your OS encoding (So cp1252, ISO-8859-1 or US-ASCII and not UTF-8... ):
A way to ensure that you are using UTF-8 is:
If you are reading XML from a stream, it is probably safer to do something like:
When validating a schema note the .getBytes("UTF-8"):
When marshalling (Use a stream rather than a writer):
Lastly if you are getting XML from some unknown source there are some chars that are outside the legal XML Unicode limits that you can not encode. To remove those:
Code below from another blog :
Tuesday, July 26, 2011
Mac Attack...
A couple months back I spent some time deciding what programming language to learn, blogged about it here. At the time I based on Tiobe, job stats, current interest and not taking the final step to actually buy a Mac, I choose C#. I spent a couple weeks messing with it, nothing serious, started a WPF clone for one of my favorite tools of all time. Baretail, but it just didn't catch my imagination, so I lacked the drive to finish.
I then got my iPhone, and that was all she wrote... I was hooked, coming from a lame excuse of a "smart phone" The HTC-Touch-Diamond-2-windows-mobile-thing, to the iPhone was a wonderful experience. It didn't take long before I could not resist the desire to program of my new toy... off to the iStore, out with the credit card, returning triumphantly with a single box, (iMac i5 quadcore 4gb 21.5"), inside the box there is a single cable, plug in the power... (spend a couple minutes looking for the on switch)... basic OS config, user and such.... done.
I had heard something about xCode, off go App Store... wait a day for the monster 4.5gb download. Stumble around hello world, and 2 or 3 other tutorials and that was that. I was hooked and with that 2 months of weekends and evenings were lost infront of the iMac. This last weekend my wife and I eventually submitted the game, and now we have to wait for probably 2 nerve wracking weeks for approval or rejection.
I'll will discuss more specific details once it is released but For now I'll share some experiences and thoughts from the last 2 months.
Objective C
I have to say, I like the language although coming for a Java / .Net background some of the intricacies of the syntax, lack of type enforcement and actually having to do your own memory management can be a little tedious when starting.
All that aside but both my wife (a C# developer) and I (Java) didn't feel too uncomfortable picking it up.
Open Source and Other resources
No. 1 most useful thing I found when writing a game for an iOS platform is:
Cocos2D
These guys have done an awesome job, and there is a decent size community / forum to help out if you do get stuck.
I haven't looked at Sparrow as I only found it a couple days after implementing Cocos2D and decided to stick with that. Another blogger did a comparison here.
Physics Engines, there are a couple out there, I figured I would gave it a skip for the first app, there would be enough to worry about without having to learn one of them either.
The 2 Main contenders I can see are:
Chipmunk
Box2D
XCode 4...
ouch, XCode just feels behind the likes of Eclipse, Visual Studio and IntelliJ. Little things we take for granted, are really missed. I am not going to go into the details, just know if you already use Eclipse, Visual Studio (with Resharper) or IntelliJ and start with XCode, you are going to be a little frustrated. To be fair, some of the frustrations were probably from a lack knowledge on my part and to top it off never having coded in the language before.
After submitting my app I decided to try App Code and loved it straight away. It's still in "beta", but using AppCode after coming from IntelliJ fells very natural. So thankfully there will be a real alternative once they release it officially.
General
I will try post useful Objective C/Game/Apple code and examples as I learn. The first 2 quick things to start with:
1. When Using Cocos2D.... and trying to incorporate UIScrollView from the SDK, prepare yourself for some pain. The CCScrollLayer however, is completely painless. We extended it and completely customized it to our game look and feel, it was very simple to do.
2. If you want to sort an array of integers in descending order use a NSSortDescriptor, very hand class actually:
Monday, May 23, 2011
1 Year and 70 000 views later, the stats...
The actual reason for this post is for some discussion on the stats... There were 1 or 2 interesting percentages I would not have expected.
Views By Country
No big surprise that the US has the most views, this being a English technology based blog, it is however interesting that Germany is second, beating out the UK and India, both with larger populations. South Africa on the list is probably only there because I force my colleagues and friends to read it :)
Views By Browser
With this being an Java-technical-open source oriented blog makes FireFox the obvious choice to lead the browser war. However with Chrome in 2nd by a such large percentage was a bit unexpected.
Views By OS
On OS Windows is still number one. Apple is competing nicely with Linux / Unix combined, this is probably due the large apple following in the US and the boom of the iPad.
Monday, May 16, 2011
Java Compression.
Compressing Files
So above the usual IO classes BufferedInputStream, FileOutputStream and File there are:
ZipInputStream - An input stream for reading files in the ZIP file format. Zip entries are not cached, unlike ZipFile.
ZipOutputStream - An output stream for writing files in the ZIP file format. This has a default internal buffer of 512, a BufferedOutputStream can be used to increase this.
ZipEntry - Represents an entry int a zip file.
ZipFile - Used to read entries from a zip file. The entries are cached.
CRC32 - Used to compute the CRC-32 of a data stream.
Below is an example showing how to compress and decompress files in a folder, with and without a checksum:
Compressing Objects
We didn't end up using object compression but I had a look at it anyways. I did a little generic compress / expand util, don't know if it will ever be useful. I left the input params as OutputStream and InputStream as this could theoretically be used with any stream implementation from socket communication to string manipulation.
The compression related classes being used here:
GZIPInputStream - An input stream filter for reading compressed data in the GZIP file format.
GZIPOutputStream - An output stream filter for writing compressed data in the GZIP file format. Default internal buffer of 512, use BufferedOutputStream if you require more.
Tuesday, April 5, 2011
Little Spring Gem: ReflectionTestUtils
One little thing I discovered in my last project, which I am a little embarrassed about, being a Spring nut, is the little gem that is : ReflectionTestUtils.
I mostly try write unit tests that do not include Spring, for the reason, that you should be testing your code and not Spring config. However sometimes it's really useful and quite beneficial to have your test code wired up with Spring, be that for integration tests or just to extend your test suite.
One issue was, I always found myself adding "setters" to my component interfaces, I always hated doing it, but I would con myself by saying: "It was for more testing, and more testing is always a good thing", and move along. I eventually (while procrastinating on work I didn't really want to do) went searching for a cleaner solution.
1 search and 1 minute later, a little red faced, I kicked myself. I should have guessed straight away that Spring would have thought of this scenario From 2.5 Spring had the ReflectionTestUtils class, which simply lets you set your dependencies / mocks via reflection.
So easy, tell it which object, the name of the field and set the mock / value you want to set. Neater interfaces, good times.
Below is an example using EasyMock interfaces and inject them for my test.
Sunday, March 13, 2011
The simple Big-O Notation Post.
Big-O:
- Describes how the algorithm scales and performs, in terms of either the execution time required or the space used.
- Is relative representation of complexity. This allows you to reduce an algorithm to a variable which in turn allows you to easily compare it to another.
- Describes an upper limit on the growth of a function, in the other words the "worst case scenario".
There is also Big-Omega notation which looks at the lower bound / "best case scenario" stating that the algorithm will take at least X amount of time and Big-Theta which is tight bound to both lower and upper / "average".
Some quick observations in determining Big-O:
- A Sequence of statements, or things like conditional checks are constant: O(1)
- A loop of statements result in : O(n) n being the number of loop executions.
- Nested loops are multiplied together: O(n2) where n is the times the outer loop executes and m is the times the inner loop executes.
Comparing the common notation examples:
(Thanks to Algorithms: Big-Oh Notation.)
n | Constant O(1) | O(log n) | Linear O(n) | Linear Logarithmic O(n log n) | Quadractic O(n2) | Cubic O(n3) |
---|---|---|---|---|---|---|
1 | 1 | 1 | 1 | 1 | 1 | 1 |
2 | 1 | 1 | 2 | 2 | 4 | 8 |
4 | 1 | 2 | 4 | 8 | 16 | 64 |
8 | 1 | 3 | 8 | 24 | 64 | 512 |
16 | 1 | 4 | 16 | 64 | 256 | 4,096 |
1,024 | 1 | 10 | 1,024 | 10,240 | 1,048,576 | 1,073,741,824 |
1,048,576 | 1 | 20 | 1,048,576 | 20,971,520 | 1012 | 1016 |
Java code example:
Show examples of notations in the table above.
Common Data Structures and Relative functions: Lists and Sets:
Structure | get | add | remove | contains |
---|---|---|---|---|
ArrayList | O(1) | O(1)* | O(n) | O(n) |
LinkedList | O(n) | O(1) | O(1) | O(n) |
HashSet | O(1) | O(1) | O(1) | O(1) |
LinkedHashSet | O(1) | O(1) | O(1) | O(1) |
TreeSet | O(log n) | O(log n) | O(log n) | O(log n) |
Thanks to reader comments, the add method on an ArrayList should be: O(1) amortized (and O(n) in worse case). Useful reference links:
Maps:
Structure | get | put | remove | containsKey |
---|---|---|---|---|
HashMap | O(1) | O(1) | O(1) | O(1) |
LinkedHashMap | O(1) | O(1) | O(1) | O(1) |
TreeMap | O(log n) | O(log n) | O(log n) | O(log n) |
Algorithmic Complexity and Big-O Notation.
Sunday, February 20, 2011
Selecting a new programming language to learn.
Now to get myself to not redirect the "new language" energy into Y.A.F (yet another framework) I decided to give the languages out there a proper look and see which would be the best fit and most beneficial to my work, marketability and just general 'IT Zen'.
So what do I require from a language:
IDE... my number 1 thing is an IDE, if there isn't a decent IDE for a language it is frankly not worth the time and effort. I don't see myself as a "scientist" where I feel the need to cause myself pain and inconvenience to be "pure". I want a comfortable productive working environment, and VI or Notepad with a command line utility ain't it.
Established... Every couple years someone somewhere tries to define some new language, and most of those die in obscurity for example brainf*** or anything listed on Esolang.
Popular / In Demand... As with most things, popularity is good, it means:
open source community, support and most importantly jobs. If you ever want to see the current popularity of a language Tiobe is the site to visit.
So who are the contenders out there?
Based on Feb 2011 Tiobe index:
Java is still the no.1 most popular, it has awesome IDEs and it's been around for just more than 15 years (January 23, 1996), but thankfully I know Java reasonably well :)... so moving right along... To narrow down the list quickly, I won't look at any languages that are losing popularity, for obvious reasons, so from the top 20 on the Tiobe list that excludes: C, C++, PHP, VB, JS, Perl, Ruby, Delphi, Go.
(
Which leaves behind:
Python, C#, Objective-C, Lisp, NXT-G, Ada, Pascal, Lua, RPG
Now there is a line between established and old, I am going to make a call that could offend some people and say Pascal and RPG are just old. (
Ada, don't know much about it, after reading the ADA overview, it seems okay, going to exclude it based on popularity. (
Lua, from a quick read it is a scripting language. (
NXT-G has something to do with lego or some robotics, not very mainstream. (
Lisp again like Ada, at first glace seems fine, just not popular enough. (
Then there are the "New, built on other platforms" functional languages: Scala, F#, Clojure. Although very temping being on the bleeding edge, it's not all that profitable or marketable yet. I'll give them some time to standardize, settle down and see if they are widely adopted. They do appeal greatly to my inner geek, so will always be keeping an eye on them.
So this leaves me with:
Python, C#, Objective-C, (and Java).
Straight away based on the above list we can Tick: IDE, Established and Popular / In demand. We all know they have decent IDEs: Eclipse, XCode, Visual Studio, (IntelliJ and Netbeans). They have also been around and are well known.
Now looking at number of jobs:
Found a site (Simply hired) with a graph displays the percentage of jobs with your search terms anywhere in the job listing. Since June 2009, the following has occurred:
Python jobs increased 72%
C# jobs increased 77%
Objective-c jobs increased 268%
Java jobs increased 76%
With the recent boom of iPads and iPhones the Objective-C percentage is not all that surprising. I do have a problem with Apple, Objective-C and XCode and that problem is you need a Mac to run it. Once you start down that road you end up having to change everything to Apple, and I am not ready to do that. So for now I am going to drop
Leaving me with Python and C#, looking at their salaries compared with Java:
(Data from Payscale).
US Data
Java
PayScale - Java Skill Salary, Average Salaries by Years Experience
CAREER TOOLS: Salary Calculator, Career Path Tool, Cost of Living Calculator, Meeting Miser
Python
PayScale - Python Skill Salary, Average Salaries by Years Experience
CAREER TOOLS: Salary Calculator, Career Path Tool, Cost of Living Calculator, Meeting Miser
C#
PayScale - C# Skill Salary, Average Salaries by Years Experience
CAREER TOOLS: Salary Calculator, Career Path Tool, Cost of Living Calculator, Meeting Miser
South Africa Data
Java
PayScale - Java Skill Salary, Average Salaries by Years Experience
CAREER TOOLS: Salary Calculator, Career Path Tool, Cost of Living Calculator, Meeting Miser
Python
PayScale - Python Skill Salary, Average Salaries by Years Experience
CAREER TOOLS: Salary Calculator, Career Path Tool, Cost of Living Calculator, Meeting Miser
C#
PayScale - C# Skill Salary, Average Salaries by Years Experience
CAREER TOOLS: Salary Calculator, Career Path Tool, Cost of Living Calculator, Meeting Miser
Based on the US data, I would have gone with Python, it's not as popular as C# but the pay is slightly better, I would also get to keep using Eclipse (PyDev) and Spring, but as soon as I looked at the South African data, I realized something, Python is really not big here. I manually went searching for Python positions advertised.. and found a grand total of 2 and the salaries were not good.
(
Leaving C# as the last language standing.
It's got Visual Studio (even a free version Visual Studio Express), It has proven itself over the last couple years, it's out innovating Java at the moment, there's a ton of jobs, a whole range of certifications and the salaries have closed the gap on Java.
Seems quite a logical choice to me.
To top it off, I have also used C# many years back, so it won't not entirely new. Most of the successful Java open source projects (Spring, Hibernate etc etc) have been ported so all that knowledge is reusable, which also counted a little in my decision. Now I just need to stop working 12-14 hours a day, and I can focus on getting back to my Microsoft roots with little C# as a Java developer. Hopefully a couple months after that I can go through this process again, looking at Python, Objective-C, the mobile platforms (iOS, Android, windows) or maybe rather a concept change to functional with the likes of Clojure or Scala.
Monday, February 14, 2011
Validate XML against its XSD
Monday, February 7, 2011
Surviving the Wild West Development Process
But in the real world what sometimes ("sometimes" being quite often actually) happens is:
What I like to call the Wild West Development Process (WWDP)... the main principle is basically “promise first and ask questions later”.
Getting started with WWDP is pretty simple:
1. You need someone, somewhere in a place of power and influence in your organization to promise software by some unachievable date.
2. Add in a eager marketing department and some press releases…
3. stir and leave to simmer.
4. After simmering for a while inform the software development department that they must have something, that does "stuff" and the release date can not change.
I am not sure if this is a result of a immature IT industry in my country, but I have spent many years in environments like this. It even seems to find me in the most unlikely employers, the large corporate organizations like insurance and banking institutions, where general red tape and corporate processes should limit this. I started my career in one of those “startup-sell-information-tech-and-business-processes-to-anyone-cheaper-than -anyone-else-type-consultancies". Which means every project was driven by WWDP so I started in the deep end, and for about 4 years I knew no other way of developing software. I currently find myself in another one of those projects. I'd like to share some points that I found helpful in actually delivering some software in unimaginable unmovable deadlines.
(to be fair some of these are in the standard development processes mentioned earlier, maybe with just different priorities)
Pick the right developers
Not everyone can cope in this environment, knowing your staff / team is very important: late nights, constant crisis, constant changes and bucket loads of pressure and stress aren't for everyone. Some people thrive, some survive and run for the hills after, some just end up whimpering in the corner and need to be replaced (which is a disaster).
Have the developers involved.
Projects like these don't allow for the usual requirements / design / develop / test paradigm, all of these functions run concurrently. Having the developers know as much detail as the architect, analysts and testers is vital. Developers will have to make decisions affecting the architecture and business functionality constantly, if everyone has the same picture you'll save time.
"Prototype" early
I say "Prototype" in quotes because unlike an actual prototype there won't be time to throw this code away. This "prototype" is to have the system in it's entirety up and running very early in the project. It can be a "shell" but having it up means testing can start early even if it's just the basics and no business functionality. Since there are no real requirements, make sure the design caters for adding them as they are defined.
Integrate early
If the system has any integration points, between systems, teams or external parties, make sure this is also in the "Prototype Shell", integration always takes longer than you think, having the interfaces up and available to test is crucial.
Keep track of communication
When the shock of not meeting an unachievable deadline kicks in, someone will always look for a scapegoat, always keep at least an email trail making sure you aren't that goat.
Automated builds and deploys
The standard agile practice of continuous integration is as important as ever, and even if you skip other parts of you software development cycle this is something that should not be dismissed.
Focus
With hundreds of things that need to happen a matter of days or weeks, it's very easy to try do 6 things at a time. Don't. Micro manage your time and tasks and focus. It's easy for us developers to start a task, see something, change something and lose a day which you don't have in the first place. If you have to, have someone keep an extensive list of "TODOs" that can be used in the cleanup phase.
Clean up
Once the unachievable deadline has been met, before starting the next phase, have at least one "cleanup" release. This cleanup phase should add very little or preferably no new functionality, but will allow for design and development decisions made in haste to be reviewed and refactored.
Pace Yourself
No matter how super human you may think you are, all of us have a limit to how many hours we can keep going. At some point you are actually being counter productive and a couple more hours sleep will actually help the project a lot more.
Know your limits.
I am sure there are a couple more, but currently being on a WWDP project I need to re-focus and leave that for the clean up phase later :)
Sunday, January 9, 2011
Joda Time == Good Times
We all know the whole Java date thing is ugly, and I sure most people have the own "implementations" and extensions like Period objects and utility Date Diff classes. I know I've written my fair share over the years. I won't be doing that again...
I am not going to go into too much detail as the Joda documentation is pretty good.
I just wanna highlight some of the very usual functionality that won me over:
Setting the "System" time, very useful. The financial systems I have worked on throughout my career always had some concept that required the "Current Date" mostly for data and rules with effective date periods.
Joda lets you statically set the "Current Date" making it a pleasure to test with, ensuring that any new DateTime objects used will be based off the set date:
Intervals:
The classic Date diff:
Working with "parts", just the date or the time:
Popular Posts
-
I have recently been slacking on content on my blog, between long stressful hours at work and to the wonderful toy that is an iPhone, I have...
-
I make no claim to be a "computer scientist" or a software "engineer", those titles alone can spark some debate, I regar...
-
I saw an article (well more of a rant) the other day, by Rob Williams Brain Drain in enterprise Dev . I have to say, I do agree with some o...
-
This series of posts will be about me getting to grips with JBoss Drools . The reasoning behind it is: SAP bought out my company's curre...
-
Update: Check out my updated re-certification on the new 2019 exam... here Let me start by saying, for this certification I studied and...