From the ViewController’s viewDidLoad we configure the view by doing the following:
1. Create a game view by casting the ViewController’s view to SKView
SKView has some properties like:
showsFPS, showsNodeCount, showsDrawCount
2. We create game scene via instance of a class that derives from SKScene
3. Then we call game view’s presentScene to present the game scene
A game scene extends SKScene. On game scene’s initialization:
1. We can set the size of the scene, from the scene we can also set the background color.
2. We can add a player (instance of SKSpriteNode) on game scene by calling the game scene’s addChild which has a parameter of SKSpriteNode
Tuesday, March 11, 2014
Making sense of Sprite Kit and iOS's MVC
Sprite Kit flow in English-speak
Friday, February 28, 2014
NoProgramming
Can we survive the onslaught of frameworks that makes our job easier and could potentially make our jobs obsolete?
First, there's No Software, then there's NoSQL, now No Programming is needed when making an application. Ok I exaggerated a bit, in this stage of technology we can now learn to make applications with almost no programming background required.
You got a complete list (no paging) of data a user wanted to filter, it would be overkill to re-fetch the data from the server as all the data being used on filtering are already at the client-side. We can use some jQuery skills or some good ol' DOM manipulation skills to do that task. But who would do that when the No technologies are all the rage now?
Here's one of the many ways to do no programming with AngularJS, enjoy! Active filtering: http://docs.angularjs.org/api/ng/filter/filter
Programming required to fit the filter requirement of clicking the search button first: almost no programming required http://fiddle.jshell.net/G8z9Q/
First, there's No Software, then there's NoSQL, now No Programming is needed when making an application. Ok I exaggerated a bit, in this stage of technology we can now learn to make applications with almost no programming background required.
You got a complete list (no paging) of data a user wanted to filter, it would be overkill to re-fetch the data from the server as all the data being used on filtering are already at the client-side. We can use some jQuery skills or some good ol' DOM manipulation skills to do that task. But who would do that when the No technologies are all the rage now?
Here's one of the many ways to do no programming with AngularJS, enjoy! Active filtering: http://docs.angularjs.org/api/ng/filter/filter
Programming required to fit the filter requirement of clicking the search button first: almost no programming required http://fiddle.jshell.net/G8z9Q/
Thursday, February 13, 2014
When DEFAULT doesn't default
I almost gave a wrong code review to a colleague:
Spotted the wrong thing on the above advice? The above advice is correct if we are using PostgreSQL. However we are using SQL Server, the newly-added IsTransferred field will default to null if the field is nullable regardless of the above DDL indicating a default value of false(0).
So the UPDATE above is not a superfluous code, at least on SQL Server, the UPDATE is still needed despite the DEFAULT 0 clause. PostgreSQL (and other RDBMSes for that matter) is intuitive in this regard, it honors the DEFAULT clause regardless of the field is nullable or not.
Further read: http://sqlblog.com/blogs/hugo_kornelis/archive/2007/07/06/null-ndash-the-database-rsquo-s-black-hole.aspx
PostgreSQL-related news: https://twitter.com/spolsky/status/433323487961178113
Happy Coding! ツ
It's better to use NOT NULL:
ALTER TABLE dbo.blah
ADD IsTransferred BIT NULL DEFAULT (0);
Is there a business or technical reason why IsTransferred should be nullable?
On the above DDL for IsTransferred, nullable or not nullable, IsTransferred defaults to 0, hence this is a superfluous code:
-- initialize new column, i.e., NULL columns, to "not transferred"
UPDATE dbo.blah
SET IsTransferred = 0
WHERE IsTransferred IS NULL ;
Further read: http://sqlblog.com/blogs/hugo_kornelis/archive/2007/07/06/null-ndash-the-database-rsquo-s-black-hole.aspx
The code could be shortened and optimized but I'm not inclined to advise it; this query is just a one-time thing, no need to micro-optimize. The code is good enough
Spotted the wrong thing on the above advice? The above advice is correct if we are using PostgreSQL. However we are using SQL Server, the newly-added IsTransferred field will default to null if the field is nullable regardless of the above DDL indicating a default value of false(0).
So the UPDATE above is not a superfluous code, at least on SQL Server, the UPDATE is still needed despite the DEFAULT 0 clause. PostgreSQL (and other RDBMSes for that matter) is intuitive in this regard, it honors the DEFAULT clause regardless of the field is nullable or not.
Further read: http://sqlblog.com/blogs/hugo_kornelis/archive/2007/07/06/null-ndash-the-database-rsquo-s-black-hole.aspx
PostgreSQL-related news: https://twitter.com/spolsky/status/433323487961178113
Happy Coding! ツ
Wednesday, January 22, 2014
Mac OS X
If you love your health and time, when you outgrown Linux as your choice of Unix, especially when father time is catching up, opt to use a Unix that cares about your sanity and taste, use Mac OS X
I once needed to compile a WiFi driver (written in C language, C is a first-class assembly language in Unix) for my Ubuntu-toting laptop, it was cool then. In our modern times, the hardware and software are now tightly integrated, who has a time to compile drivers? Think iPad or Surface Pro requiring users to compile drivers for the device's WiFi, users will go batshit insane if they have to endure performing this task.
I still think compiling non-kernel softwares as kinda cool though, on my first work a colleague introduced MySQL to us, we used MySQL we compiled ourselves, no installer, just C source code. It feels so empowering having the source code and knowing that we can introduce functionalities that integrated well to the RDBMS's bare metal.
I once needed to compile a WiFi driver (written in C language, C is a first-class assembly language in Unix) for my Ubuntu-toting laptop, it was cool then. In our modern times, the hardware and software are now tightly integrated, who has a time to compile drivers? Think iPad or Surface Pro requiring users to compile drivers for the device's WiFi, users will go batshit insane if they have to endure performing this task.
I still think compiling non-kernel softwares as kinda cool though, on my first work a colleague introduced MySQL to us, we used MySQL we compiled ourselves, no installer, just C source code. It feels so empowering having the source code and knowing that we can introduce functionalities that integrated well to the RDBMS's bare metal.
Wednesday, January 8, 2014
Monday, December 2, 2013
Domain Modelling a.k.a. Object-Oriented Programming
Our industry created a new term for Object-Oriented Programming (combination of noun and behavior), it's called Domain Modelling. There's no problem with that, it gives us a richer vocabulary for something that closely resembles the real-world or the problem-at-hand. It will just be a source of confusion when we misuse the same vocabulary for something else.
Domain model models both nouns and behaviors. However, many thought that domain models are just all about nouns. This is where the confusion starts, if we remove the behavior from the domain model where do we place the behavior/business logic that acts on the noun? Should the domain model really just be a mere state repository?
With that confusion, a new term is coined to emphasize a domain model without behaviors, this kind of domain model is now called anemic domain model. And the domain model (that should inherently have behaviors in the first place) with behavior is now called rich domain model.
Had we not invented the term domain modelling; we might call the new OOP, that is an OOP with behavior, as Rich Object-Oriented Programming.
Modelling the real world is getting funny :-)
Here's the anemic computer model:
Its behavior is in ComputerService.
The problem with separating the behavior from its object is it's more difficult to identify the codes we can re-use. We tend to make duplicate codes if we don't know that there's an existing implementation already that act as an intelligent front-end(e.g. service) for the anemic domain model. Trying to discover the code we can re-use on a domain model(er.. rich domain model)? It's right there on the class! Just type dot character after the class instance, the model's behavior jumps out on intellisense/autocomplete, the model's intelligence is integrated right there on the model, a one-stop-shop feel.
This is the proper domain modelling for computer, this is now called a Rich Domain Model. A model with behavior, an object with behavior yay! Should we call this Rich OOP too?
Let's practice Domain Model, er.. scratch that, let's practice Rich Domain Model! let's practice OOP!
Happy Computing! ツ
Domain model models both nouns and behaviors. However, many thought that domain models are just all about nouns. This is where the confusion starts, if we remove the behavior from the domain model where do we place the behavior/business logic that acts on the noun? Should the domain model really just be a mere state repository?
With that confusion, a new term is coined to emphasize a domain model without behaviors, this kind of domain model is now called anemic domain model. And the domain model (that should inherently have behaviors in the first place) with behavior is now called rich domain model.
Had we not invented the term domain modelling; we might call the new OOP, that is an OOP with behavior, as Rich Object-Oriented Programming.
Modelling the real world is getting funny :-)
Here's the anemic computer model:
class Computer
{
public int ComputerId { get; set; }
public double Speed { get; set; }
public double BaseSpeed { get; set; }
public double MaxSpeed { get; set; }
}
Its behavior is in ComputerService.
class ComputerService
{
public bool Overclock(Computer c, double multiplier)
{
bool safeToOverclock = false;
double newSpeed = c.BaseSpeed * multiplier;
if (newSpeed <= c.MaxSpeed)
{
c.Speed = newSpeed;
safeToOverclock = true;
}
return safeToOverclock;
}
}
The problem with separating the behavior from its object is it's more difficult to identify the codes we can re-use. We tend to make duplicate codes if we don't know that there's an existing implementation already that act as an intelligent front-end(e.g. service) for the anemic domain model. Trying to discover the code we can re-use on a domain model(er.. rich domain model)? It's right there on the class! Just type dot character after the class instance, the model's behavior jumps out on intellisense/autocomplete, the model's intelligence is integrated right there on the model, a one-stop-shop feel.
This is the proper domain modelling for computer, this is now called a Rich Domain Model. A model with behavior, an object with behavior yay! Should we call this Rich OOP too?
class Computer
{
public int ComputerId { get; set; }
public double Speed { get; private set; }
double _baseSpeed = 0;
public double BaseSpeed
{
get
{
return _baseSpeed;
}
set
{
_baseSpeed = Speed = value;
}
}
public double MaxSpeed { get; set; }
public bool Overclock(double multiplier)
{
bool safeToOverclock = false;
double newSpeed = this.BaseSpeed * multiplier;
if (newSpeed <= this.MaxSpeed)
{
this.Speed = newSpeed;
safeToOverclock = true;
}
return safeToOverclock;
}
}
Let's practice Domain Model, er.. scratch that, let's practice Rich Domain Model! let's practice OOP!
Happy Computing! ツ
Subscribe to:
Posts (Atom)


