Over the weekend we decided to visit the occupy Toronto camps
Here's some pictures at ground zero (Tent City).
Monday, November 14, 2011
7 Hour Boat Cruise
Here are some photos from the 7 hour boat cruise
We're pretty sure we caught some sort of Mafia action going on above.
Monday, November 07, 2011
Programming definition: Fragile Code
I've seen variations of the programming term "Fragile Code" lying around but I thought I'd formalize it in a post so that other programmers can get an idea of what this means. For me fragile code is defined as follows:
Generally speaking fragile code is not discovered until a strange bug occurs that was caused by violation of one of the assumptions in the original fragile code. What makes fragile code dangerous is it makes time estimates increasingly difficult as a small feature ends up breaking the fragile piece of code despite it having no direct relation to the feature being added.
On the internet Fragile code is referred to as copy and paste code but I frequently find that too specific in fact some programmers in my profession I find write fragile code by nature because they can have access to the entire code base so they assume the contents of other classes and methods won't change.
How do you not create fragile code?
#1 Never trust the contents of methods always assume that anything inside a method may change the only thing you can rely on is the method name to indicate what the methods should do.
If you encounter this scenario you should either indicate the dependency through the method names or (preferred) have automatic function call dependency. I.E. add code so that if you detect func2() was called without func1() then have func2 execute func1. However it would be preferable that if you have this scenario to not expose the utility functions altogether.
Fragile Code: Code that is hard to service, modify or improve without introducing many bugs. Fragile code tends to rely on too many assumptions that quickly become no longer true a features are added.
Generally speaking fragile code is not discovered until a strange bug occurs that was caused by violation of one of the assumptions in the original fragile code. What makes fragile code dangerous is it makes time estimates increasingly difficult as a small feature ends up breaking the fragile piece of code despite it having no direct relation to the feature being added.
On the internet Fragile code is referred to as copy and paste code but I frequently find that too specific in fact some programmers in my profession I find write fragile code by nature because they can have access to the entire code base so they assume the contents of other classes and methods won't change.
How do you not create fragile code?
#1 Never trust the contents of methods always assume that anything inside a method may change the only thing you can rely on is the method name to indicate what the methods should do.
#2 Don't even trust yourself. Ok so you wrote a function and you know that you only call it with a non null condition. The problem is this assumption that you made quickly falls flat when working with a team. Other people modify your code and your original assumption that you can expect a certain call order I.E. function 2 will always be called after function 1 and therefore funciton 1 will make a class level variable not null is not a stable assumption.
There is a way around this however. If you absolutely need function 1 to be called before function 2 stick an assertion that says that. Assertions are NOT program logic they are programmer tools an assertion states the programmer's assumptions at runtime. If you are assuming something and you know you can't handle a situation where your assumption isn't true stick in an assertion. This will at least make your fragile condition easier to track down in the future.
#3 Never rely on call order. One type of fragile code is function call order reliance this is when a programmer creates utility functions func1() func2() func3() and they must be called in order func1() func2() func3() calling any one of these out of order will cause a failure. The problem is to an outside observer func1() func2() func3() look like independent functions and don't look like they have anything to do with each other so in theory they may think you can call func2() and it should be fine.
There is a way around this however. If you absolutely need function 1 to be called before function 2 stick an assertion that says that. Assertions are NOT program logic they are programmer tools an assertion states the programmer's assumptions at runtime. If you are assuming something and you know you can't handle a situation where your assumption isn't true stick in an assertion. This will at least make your fragile condition easier to track down in the future.
#3 Never rely on call order. One type of fragile code is function call order reliance this is when a programmer creates utility functions func1() func2() func3() and they must be called in order func1() func2() func3() calling any one of these out of order will cause a failure. The problem is to an outside observer func1() func2() func3() look like independent functions and don't look like they have anything to do with each other so in theory they may think you can call func2() and it should be fine.
If you encounter this scenario you should either indicate the dependency through the method names or (preferred) have automatic function call dependency. I.E. add code so that if you detect func2() was called without func1() then have func2 execute func1. However it would be preferable that if you have this scenario to not expose the utility functions altogether.
Wednesday, October 19, 2011
Friday, September 16, 2011
utorrent server linux startup script
Here's a linux utorrent script so you can start utorrent server like a service on linux machines!
Currently tested working on ubuntu and debian systems but should work on most linux boxes.
Currently tested working on ubuntu and debian systems but should work on most linux boxes.
Tuesday, August 16, 2011
MKV2M2TS script for linux lovers
I found a pretty good script to base mine off of from mediatomb the problem is it has a pretty significant flaw when dealing with AC3 files that causes it to miss the AC3 file entirely half the time and give me a null audio track.
So I've patched it up and here's the fixed version:
So I've patched it up and here's the fixed version:
Tuesday, July 12, 2011
The importance of intuitive interfaces
Good user interfaces aren't just for users. We programmers forget that nice intuitive interfaces actually prevent programmer error. For whatever reason GXT chooses to have the most unintuitive interface in the world take this for example.
The selection model affects what happens when a user tries to make a selection on a grid (think excel table). The method accepts any selection model as well as null. If a programmer wanted to disable selection on the grid they would intuitively do:
That would be what you and I would and without any prior knowledge of the library we would think this means that the selection model is disabled when it is not provided.
Obviously this doesn't work otherwise this post would be pointless if you try the above you get a null pointer exception. So how do we disable selection at all? Will through this obscure post we find out that in order to disable selection on the grid you must first provide it with a selection model and then disable it.
or in a more compact way
What's the problem? Well for one you still have a selection model in the system and all selection models have to implement this "locked" mode which means disabled. You can't just disable a selection model.
But you say "It is documented when you dig through the documentation" that much is true their documentation has this to say:
But the point is when there is such a thing as the interfaces behaving in an intuitive way. A programmer should take into consideration their fellow programmers and add convenience methods in order to give other programs an intuitive way of doing things. For example if the grid itself had a:
Which sole purpose is to set the selection model locked or unlocked this would be much easier to use.
Grid.setSelectionModel(SelectionModel m);
The selection model affects what happens when a user tries to make a selection on a grid (think excel table). The method accepts any selection model as well as null. If a programmer wanted to disable selection on the grid they would intuitively do:
Grid.setSelectionModel(null); //Sets the selection model to null (disabled)
That would be what you and I would and without any prior knowledge of the library we would think this means that the selection model is disabled when it is not provided.
Obviously this doesn't work otherwise this post would be pointless if you try the above you get a null pointer exception. So how do we disable selection at all? Will through this obscure post we find out that in order to disable selection on the grid you must first provide it with a selection model and then disable it.
SelectionModel sm = Grid.getSelelctionModel();
sm.setLocked(true);
or in a more compact way
Grid.getSelectionModel().setLocked(true);
What's the problem? Well for one you still have a selection model in the system and all selection models have to implement this "locked" mode which means disabled. You can't just disable a selection model.
But you say "It is documented when you dig through the documentation" that much is true their documentation has this to say:
setLocked
public void setLocked(boolean locked)
- True to lock the selection model. When locked, all selection changes are disabled.
-
- Parameters:
locked- true to lock
But the point is when there is such a thing as the interfaces behaving in an intuitive way. A programmer should take into consideration their fellow programmers and add convenience methods in order to give other programs an intuitive way of doing things. For example if the grid itself had a:
Grid.disableSelection(boolean disabled)
Which sole purpose is to set the selection model locked or unlocked this would be much easier to use.
Subscribe to:
Posts (Atom)
Hobbies
I need new hobbies. Two years into COVID-19 my hobby became everything COVID related everything from keeping up with the latest restriction...
-
Here's a linux utorrent script so you can start utorrent server like a service on linux machines! Currently tested working on ubuntu a...
-
It's time to switch up the wallpapers again so I've come up with a new concept for everyone to enjoy Hex WallPapers (in the same vei...



















































































