Software By Richard Life and Coding 2008-06-09T14:48:45Z WordPress http://www.softwarebyrichard.com/blog/feed/atom/ rbezemer http://www.softwarebyrichard.com/blog <![CDATA[Telus is Evil]]> http://www.softwarebyrichard.com/blog/2008/06/telus-is-evil/ 2008-06-08T18:41:11Z 2008-06-08T18:24:30Z Does this article scare anyone else as much as it scares me? I’ve seen this mentioned for a while, but it really hit home when it’s companies you are used to dealing with in Canada. This subscription based internet site business model goes against the very foundation of what the internet was based on. But I can see how the corporate world loves this idea of how they can partner and sell content to each other.

Remember all you Telus and Bell customers out there are supporting this kind of garbage and every dollar you send them gives them another dollar to push this kind of subscription based internet. This is why Canada needs to support Net Neutrality legislation. Don’t forget your member of parliament is only an e-mail away. Don’t hesitate to contact them concerning your views on any piece of legislation. that’s exactly what they are there for! I know I’ve e-mailed my mp many times over the past few years, I may not have voted for him but he was elected to carry my voice to parliament.

Do you really want the internet to be like cable TV? Just imagine when this is what we are reduced to when signing up for a broadband subscription:

]]>
0
rbezemer http://www.softwarebyrichard.com/blog <![CDATA[Why do people still dislike C++]]> http://www.softwarebyrichard.com/blog/2008/06/why-do-people-still-dislike-c/ 2008-06-08T05:36:25Z 2008-06-08T05:32:57Z Recently this article from Mark Roulo from way back in 2001 made the rounds on reddit. He talks about how difficult c++ is as a language and why it should never be used for a large project. He goes into great detail about his interview questions designed to frustrate the most seasoned of C++ developers and spends a lot of time berating the use of pointers in C++.

I have a real problem with kind of article. They focus way to much on the c side of c++ and not the ++ part. There’s a reason why I have several Scott Meyers books on my reading list. Real C++ developers should never be relying on such antiquated techniques as manipulating a char* string directly. If a large c++ project has a tech lead who is not familiar with and not promoting stl and boost I would be terrified, even though I have worked on such projects in the past.

When I was the architect behind a major drawing application, doing a complete refactoring of our legacy codebase it was a real eye opener to see just how much these libraries simply C++ software development. It really lets you focus on the software development part of coding and not the bashing your head against the wall, I hate Bjorn Stroustroup kind of software development.

but anyway I feel any C++ tech / architectural lead should be familiar with these libraries at a minimum:

Plus there are many more libraries I would be lost without such as Xerces, Cairo, Unittest++ and many others. C++ is a powerfull language and part of the reason I love using it so much, but you have to be carefull. Remeber shared_ptr is your best friend!

]]>
0
rbezemer http://www.softwarebyrichard.com/blog <![CDATA[Flex Item Renderers]]> http://www.softwarebyrichard.com/blog/2008/05/flex-item-renderers/ 2008-05-20T14:35:00Z 2008-05-20T06:08:36Z So I’ll admit it, I’m still getting into the ActionScript programming frame of mind, and going from hardcore c++ to Flex takes a bit of a mind shift and I’m still getting used to flash doing everything for me, all though it is a nice change of pace.

An item renderer in flex is a relatively simple concept, basically for every item in a collection, here’s a set of components that can draw this data to some kind of human readable format that’s somewhat pleasing to the eye. Now the difficultly that I ran into was that I tried to get to smart for myself. I had a dataProvider that contained a tree of UIComponents that I wanted to manage in a list component, or more specifically a TileList. These components were generated by another in house library and I very much wanted to keep them in tack and not redraw everything out every time a change happened to the list (such as changing the number of columns from 4 to 8). Easy I thought, the behavior that makes the most sense is when the data provider is created it associates the item renderer with that index in the data provider so I did something like this in my item renderer:

override public function set data(value:Object):void
{
   _data = value as MyCustomContent
    //...
}
private function init():void{
    this.addChild(_data);
}

So what’s wrong with this…

Data item renderers were not meant to work this way. They very much rely on a UIComponent taking a temporary piece of data and having the component decide how to dynamically interprete this data. Many list componets are very “green” and recycle item renderers accross cell positions. While my above solution worked fine initially, when I started changing the number of columns all my data appeared in the wrong order. The List was shuffling item renderers between cells and when I associated content as a member variable in the renderer it was traveling to where ever the list decided to recycle an item renderer instead of having it travel with the index of the data provider. What makes me even madder at myself is if I had bothered to pay more attention to the documentation I’m sure I read that section about 20 times without realising what I was doing.

So moral of the story, always pay attention to what you are reading and make sure you properly update all your visual content each time an item renderer changes your data variable, don’t assume the same item renderer will use the same data each time it is rendered.

]]>
0
rbezemer http://www.softwarebyrichard.com/blog <![CDATA[What is the Best Source Control for My Team?]]> http://www.softwarebyrichard.com/blog/?p=11 2008-05-14T14:36:17Z 2008-05-08T06:48:11Z All software development teams are hunting for that perfect source control system that perfectly handles every case. But lets face it source control is confusing and it’s a huge investment of time to investigate which source control system to use, and if you pick wrong, it can be very costly to your project. This is probably the biggest reason new Source Control Systems take so long to take traction, Why would any business manager take a known risk of changing the source control system when the current one works. It worked for our last release…Right.

Source control is a confusing endeavor which is made more difficult by the fact the majority of developers do not have a lot of experience with it. It’s frustrating, we all use some form of source control on a daily basis but how many of us actually understand what is going on in the back end? At most companies source control setup and administration is handles by a select few and is so shrouded in mystery developers are hesitant to ask to many questions (probably due to the fact if they understand it to well they will be seen as the “expert” everyone in the office bugs about their checkin and why my commit broke the build…)

InfoQ has a fantastic write up about comparing the benefits of distributed source control systems here. I am personally not convinced distributed source control is the way to go. They have received a lot of press recently with Linus Torvalds pushing how great git is and how “real” developers should be only using distributed source control. While distributed source control is great for open source projects where one person tends to own the code and you have a few external developers working on the odd feature, yes distributed is probably the way to go. However in a corporate environment where you have a team plugging away towards a release I would be very worried to go away from a centralized system. I’m going to build on the differences between the two different systems.

Centralized source control systems (such as Subversion) have a lot of good things going for them. It represents the progression of code in a very linear way. It’s easy to see how the code got from point A to point B and track how a piece of code evolved during the development cycle. The one draw back is on a very large, or well established project you can have very deep trees to represent all the development branches that occurred during the development cycle.

The repository has a well defined owner, which would be your centralized server. If you have a new person joining the team you can just point them to the one central server and one main branch that they can work from. Build integration systems ( such as Cruise Control or Hudson ) are simple to set up with centralized source control as well. You can simple create a new build project for each branch and all code can be verified and unit tested, and potentially released from on of these systems.

The biggest draw back of a centralized system is there tends not to be as dedicated owner of the codebase which makes branching and merging more difficult. Each individual user is expected to have a rudimentary understanding of merging and be able to merge their changes in with everyone elses on the main development branch. This causes much more havoc when you have the cowboy developer on your team who is always blowing away your changes with their latest and greatest code produced during their last all nighter coding session. These developers tend not to play nice with the stable branch and like to think their code is more important than everyone elses and push the responsibility of integrating their code to everyone else using the branch.

You also pay for this in size, since you are tracking everyone’s changes all on one server as you can imagine it eats up a lot of space both on the server and on each users individual development machines.

Distributed source control (such as Git, Mercurial, or Bazaar )  basically follows the philosophy that everyone owns the code. There does not have to be a central server and everyone is basically working on their own branch of the code. This works well if your teams uses the one feature per developer methology and as you can imagine plays right into the hand of the cowboy developer as they don’t have to pay attention to what other are working on and “getting in the way” of their code.

Developer changes are tracked individual, and it basically works like you think it would. If you want to work on a piece of code, you basically go to each developer working on the project and say I need your changes to work on my code, and go round and round until you have all the code you need. Of course this makes it easy for developers to show other developers exactly what the code looks like on their system without polluting the trunk with testing or debug code, or for extreme programmers to synch two developers changes together. Quite often in a distributed system there is a maintenance or production “user” which takes care of creating a view of all the independent developers changes into one cohesive released project.

One side effect is distributed source control offers you the option of having localized commites. Since you are basically working on your own version of the code, you can check your code in offline and not have to report you changes back to a centralized server. While this is handy if you are testing and want to undo changes you accidentally added or remove code that didn’t work, I find it’s almost redundant now as lately ide’s  tend to have this feature built in to them (like Eclipse). It’s a handy feature to have but may lure developers into thinking their code is backed up when it may not be.

So what is the best system for a team to use? The short answer is anything. Any source control is better than none. In my experience for a well defined team of developers you can’t beat a centralized system where all developers must ensure their code plays well with everyone elses. You can plan a release schedule around a branch and simply build off that branch to periodically release trial software to testing or for demo purposes. There is no running around involved to merge together individuals code, it is done for you by design.

The biggest advantage is code ownership. In a centralized system your development branch is the ultimate authority on the current state of the codebase. All developers must ensure their code integrates well with everyone elses before it is able to be used by anyone, and if you have a new developer to the team you can point them to one location for everything they need.

It is missing the nice feature of being able to share the exact state of code on your system, but with a little bit of planning this can be accounted for with feature or research branches where developers can share code without having to worry about breaking the build. If you have the strong developer on your team who has a definite ownership of the codebase, the distributed system is definitely more advantageous and you can see how it would make enforcing code reviews easy as all changes whould have to be pulled together by one lead developer.

The biggest key to getting source control figured out is to just keep trying new things with it. Until you create that feature branch and merge another developers changes in, you will always be scared of doing it. Source control is one area where each developer should push themselves to learn the system and terminology and not be afraid to try things with it. It is source control after all, you can always revert your changes :)

If you want more information of source control basics, Kalid Azad has a great introductory article here and a good distributed source control article here. Also I take no credit for the fancy source control diagrams, they are straight from the linked article.

]]>
1
rbezemer http://www.softwarebyrichard.com/blog <![CDATA[The Perfect Manhattan]]> http://www.softwarebyrichard.com/blog/?p=8 2008-05-07T06:36:25Z 2008-05-05T15:29:07Z So to take a break from coding. Here’s a recipe to make the perfect Manhattan.

Stir over ice( I find it works best if you have your rye in the freezer for a while before you make them, the colder the better). Rim a cocktail glass with lemon , add a cherry and pour. I find it works just as well with lime instead of lemon as an alternative.

Enjoy!

]]>
0
rbezemer http://www.softwarebyrichard.com/blog <![CDATA[Iterating through a directory with Ant]]> http://www.softwarebyrichard.com/blog/?p=7 2008-05-05T15:19:14Z 2008-05-05T15:19:14Z Ant is a great build system, but often it can be very confusing trying to wade through all it’s documentation and find out how to do something you could write in a batch file in minutes. Case in point, iterating through a directory.

The easiest way to do this is to use the ant-contrib tasks. These add some very usefull functionality to Ant that really improves your productivity. You can find full details of all the packages here.

How to use foreach. It looks really complicated but it’s not that bad.

<target name="parse_directory" description="Parses out all the files from the directory">
	<foreach target="build_my_file" param="the_file">
    	    <path>
    	        <fileset dir="path/to/buildfiles">
    			<include name="**/*.mxml"/>
    		</fileset>
    	    </path>
    	</foreach>
</target>
<target name="build_my_file" description="Builds a mxml file">
	<mxmlc file="${the_file}"/>
</target>

So to break down what it’s doing, in the first target (parse_directory) it is passing a fileset tag to the foreach task to iterate over, it doesn’t have to be a fileset, you can also iterate over directories as long as you wrap it in a path tag. the foreach task takes two important attributes. target specifies the ant target that should be called for each item in the fileset and param specifies the name of the variable that will contain the variable for the iteration. In the build_my_file target you can see where we reference this variable with the ${the_file} statement.

Hope that helps anyone to make Ant a little more usefull.

]]>
0
rbezemer http://www.softwarebyrichard.com/blog <![CDATA[Create a Photobucket Image Gallery]]> http://www.softwarebyrichard.com/blog/?p=4 2008-05-05T13:29:26Z 2008-05-04T06:11:10Z Photobucket has a tonne of images that you can use to create some interesting content. I’m going to show you how to create a simple photobucket image gallery using Flex.

I love to reuse existing code where possible, probably one of my biggest sticky points as a software developer. In this case Doug Mccune has an awesome image dispaly component written using papervision and I’m just going to reuse his code. You can download his cover flow component here and link it into his code. I’m not going to go into a bunch of details on how to use his component, he has many links on his site on how to get it up and running.

After the coverflow component is linked in we’re going to create a light wrapper around it. Within your flex application go to new->Flex Component and create a component based on a Vbox.

The code looks something like this :

<mx:VBox createComplete="init()">
<containers:CoverFlowContainer
		id="coverflow"
		width="100%"
		height="100%"
		horizontalGap="40"
		borderStyle="solid"
		backgroundColor="0x000000"
		segments="10"
    	reflectionEnabled="true" />
	<mx:HScrollBar
		id="scrollbar"
		width="100%"
		pageSize="1"
        scrollPosition="{coverflow.selectedIndex}"
        scroll="coverflow.selectedIndex = Math.round(scrollbar.scrollPosition)" />
</mx:VBox>

Now the next thing we need is some script to dynamically add images to this component. Usually you can just add the objects you want to display in the coverflow component as child objects, but if we’re going to load them from Photobucket we need to be able to dynamically change them. Here is the code I use to dynamically add images:

	<!--[CDATA[
	public function addURL(url:String) : void {
		<!--
			Creates a canvas to display the image on
			and adds the canvas with the image as a
			Child of the coverflow component
		 -->
 		var cv:Canvas = new Canvas();
 		cv.width = canvasWidth;
 		cv.height = canvasHeight;
 		cv.verticalScrollPolicy="off";
 		cv.horizontalScrollPolicy="off";
 		var thisImage:Image = new Image();
 		thisImage.setStyle("verticalCenter","0");
		thisImage.setStyle("horizontalCenter","0");
		thisImage.addEventListener(Event.COMPLETE, imageLoaded);
		thisImage.load(url);
		cv.addChild(thisImage);
		coverflow.addChild(cv);
		numChildrenAdded++;
		scrollbar.setScrollProperties(1,0,numChildrenAdded-1,1);
		scrollbar.scrollPosition=coverflow.selectedIndex = Math.round(scrollbar.scrollPosition);
		coverflow.selectedIndex = numChildrenAdded-1;
	}			 	

	private function imageLoaded(event:Event):void{
		<!--
			Image Loader function to center the image
			after it has been loaded
		 -->
		var thisImage:Image = event.target as Image;
		if(thisImage.contentWidth>(canvasWidth-20) || thisImage.contentHeight>(canvasHeight-10)){
		var scaleAmt:Number = 1.0;
		if(pbImg.contentWidth>pbImg.contentHeight){
			scaleAmt = canvasWidth /(pbImg.contentWidth-10);
		}else{
			scaleAmt = canvasHeight /(pbImg.contentHeight-10);
		}
		pbImg.scaleX = scaleAmt;
		pbImg.scaleY = scaleAmt;
	 	}
	}
	]]–>

Now the next thing we need to do is to add the Photobucket content. For this example we are just going to display the 10 newest images on Photobucket using their RSS feeds. They have a API that allows you to really get detailed Photobucket information but that is a whole other article in itself. Any way the simplest way to do this is with a HTTPService Flex object:

<mx:HTTPService id="httpRSS"
		 url="http://feed.photobucket.com/recent/images/feed.rss"
		 resultFormat="object"
		 result="imagesAvailable(event)" />

Next you need to grab the image from the RSS XML:

 private function imagesAvailable(event:ResultEvent) : void {
	<!--
		This function simply pulls out the image guid from the
		RSS feed and sends the first 10 to the component
	-->
	for(var i:Number=0; i<10;i++){
		addURL(httpRSS.lastResult.rss.channel.item[i].guid);
	}
}

One final piece is to fill out the creationComplete function and tell it to load the rss feed at startup. Add the following to your components VBox tag:

creationComplete="{httpRSS.send()}"

And that is pretty much it! Hope this helped get you started creating a Photobucket image gallery.

]]>
0
admin <![CDATA[Start of My Blog]]> http://www.softwarebyrichard.com/blog/?p=3 2008-05-03T18:26:36Z 2008-05-03T18:26:36Z Hi my name is Richard Bezemer, and I am a Software Consultant based out of Calgary, Alberta, Canada. I hope to blog about technology, consulting and coding.

]]>
1