Friday, December 23, 2005

Awesome, Apple Market Share Increasing!

I just found this article on "The Unofficial Apple Weblog".

After the January MacWorld I'll be making my first Apple Computer purchase. I'm hoping I can order the following configuration (might be a dream): 17" Power Book (love the new resolution!) with a dual-core CPU, 7200 RPM hard drive, backlight keyboard, and integrated iSight. (I'll stick at least 1.5 gigs of RAM into, and definitely make use of the Wifi and Bluetooth!)

Can't wait to see what they have in store for '06!

Wednesday, December 21, 2005

Objects Are Your Friend, Encapsulation

For those of you who are already masters of the Object Oriented paradigm you may find this article rather entry level. I'm writing this for the web developers out there that have been writing procedural code for a while, and are feeling the headaches of dealing with their code base as it grows.

This isn't a complete, "Why Objects Totally Own", article. But I hope it's enough to spark some interest in the procedural programmers out there.

One of the easiest concepts to grasp in OO is something that took me a while to SEE. I've noticed that I do it by default now, I don't even think about it. If you asked me about it 2 years ago I wouldn't have been able to point it out, but now I evangelize it's use.

I'm referring to the encapsulation of a business rule within it's appropriate object.

Plain English version:
Solve a problem once and never ever repeat it by using an object.

Quick Note:
Generally speaking an object is great for representing various entities in the system you are building. The classic example you'll see over and over again (in OO tutorials) is the "Person" object inside of a Human Resources/Payroll/Employee Management system. When you make a "Person" object you can act on all the data and business rules related to people using the abstract concept of "a person". I don't want to use the Person example, because I'm tired of it. ;)

Let's use an object I've created for my designer application.

My application deals with pieces of work that designers upload to the application. A piece of work can be a logo, an advertisement banner, etc....

I've got an object in my system called "Piece". The Piece object is an abstract representation of the piece of work the designer uploaded. All of the business rules pertaining to a Piece are encapsulated within the Piece object. EVERYTHING!

I'm not going to tell you how or where my system stores the file that is uploaded by the designer. I'm not going to tell you how or where my system stores the name of the file. I'm not going to tell you how or where my system stores or retrieves the file path of the file (for display in a browser).

I'm not going to tell you any of that because outside of the Piece object, there isn't another bit of code on our entire planet Earth that knows those business rules.

I'm only going to share with you the same information the rest of my application has. The API of the Piece object.

Let's say you're a developer on my team and you want to build a web page that displays one of the pieces of work a designer has uploaded to the system. Let's say that the ID of the piece, excuse me, "Piece", is sent through the URL to this new page you're working on. You're going to get a Piece object using the ID and whatever object fetching mechanism your application/framework has. With Ruby on Rails, you'd do this.

(This is language specific, and it's just used to illustrate a point. As you develop in your Object Oriented language of choice you'll find out how to create new instances of objects and get the specific one you want based on certain criteria. In this example, the criteria is the ID of the Piece.)

URL is this:
http://michaelsica.com/piece/?id=23

The object fetching/loading code is this:
@piece = Piece.find_by(params[:id])

You see the "@piece" part? In Ruby that is simply a variable. That particular variable now contains the specific "Piece" object that relates to the ID we passed in. (If that doesn't make sense, leave me a comment and I'll explain further.)

Now, you as the developer have this "Piece" object that represents the piece with an ID of 23. All you have to do is reference the "@piece" variable when you want to know something about or do something to that Piece.

What was the requirement again? Oh yeah, "build a web page that displays one of the pieces of work a designer has uploaded to the system."

Before you can do that you need to know how to work with the Piece object. You need to know the API. All the business rules and information about the Piece is contained within your "@piece" variable. You're a smart developer so you decide to look up the documentation (API) for "Piece". You see that there is a method (a function on an object) named, "url_path" on the Piece object.

In your web page you can now call that method to get the path to the image, and display it on your page. Like so....

(Again this is Ruby on Rails specific code, but the concept applies to all OO languages.)



When Ruby runs this code it will generate the proper HTML. It could be something like:



The "@piece.url_path" is a call to the method, "url_path", on the Piece object, "@piece". But you already knew that, right? ;)

Now, why is this soooooooo neat-o?

You have absolutely NO idea how the image is stored, where it is stored, or how the information was brought together to serve up image's url path. It is all contained within the Piece object. You're now dealing with the abstract concept of a Piece.

I can go into that object at any time and COMPLETELY change how it works and all of the code using the object, i.e. your image displaying code, won't know the difference. I could store the image in a DB and then cache it to a folder under the web site's folder structure on launch day. Then 3 months later, I can decide to store all the images on a file server that is outside of the webroot. The Piece object could then fetch it from there and stash it under the web site's folder structure.

I'm sure some of you are thinking, "I can do this now with a function global function. I'll just pass in the ID and it will return the url path."

Well, let's talk about that for a moment....

Let's say you write this one function to encapsulate the URL path of a piece based on it's ID. Then you find out you have more business rules related to a Piece. You're a good developer so you write more functions so the logic can be encapsulated and re-used. Then you find out you have more business rules related to a Piece. You're a good developer so you write more functions so the logic can be encapsulated and re-used. Then you find out you have more business rules related to a Piece. You're a good developer so you write more functions so the logic can be encapsulated and re-used. Then you find out you have more business rules related to a Piece. You're a good developer so you write more functions so the logic can be encapsulated and re-used. Then you find out you have more business rules related to a Piece. You're a good developer so you write more functions so the logic can be encapsulated and re-used.

Most systems have more than one entity. Let's say you're still working on this application with me. My designer application has the concept of "Clients". You're a good programmer and you want to re-use business logic through functions. So you start writing functions to encapsulate the business logic of all the Client related stuff. With each business rule, you write more functions. And more functions. And more functions, etc.....

The question I now have for you is, "How are you organizing these functions?"

Are you making seperate files that have all the related functions in them, and then making them globablly accessible? Are you going to make files named, pieces_functions.lang and clients_functions.lang?

Guess what.

You've just created groupings of functionality that are closely related to one another that are encapsulated within a single file. That description is pretty damn close to the definition of a "class". A "class" is the name of the file your object code is written in. You put all your methods (i.e. functions) in the class file along with all the data related to the class/object. (My Piece object, before it is instantiated, is a Piece "class".) But since you're not using objects, you don't get any of the power of Object Oriented programming. You'll be missing out on inheritance and polyphorism. Not to mention the ability to work with your system at a higher level of abstraction, i.e. this is a Piece, this is a Client, a Client can view a Piece.

I've just scratched the surface of OO in this post. If you'd like me to continue writing about OO programming, please let me know (contact me or leave a comment below).

Tuesday, December 20, 2005

Objects rule

I was chatting with Max tonight about how our department (day job) is moving toward Java from PL/SQL. We're not big fans of procedural code, we like objects. I typed the quote below while chatting. He suggested I place this on my blog.

"As soon as you have more than 1 variable in your application, you need objects."

I'm going to be posting an "Objects are you friend" blog entry in the near future. It won't nesicarrily support the above quote. But I wanted to get all my PHP4 coding buddies all riled up! ;)

Promotion, Climbing the corporate IT ladder

It's been in the works for a couple of months, but today the annoucement was made at my "day job".

I've been promoted from Project Coordinator to Web Application Manager.

I'm now the manager of a FANTASIC and TALENTED group of people! 2 programmers + 1 starting in 2 weeks, 2 designers, and a business analyst. Plus I'll be the psudeo manager for a developer that is a dedicated resource for one my company's marketing departments.

The opportunity became available to me once my (now previous) manager got the go-ahead to create a new department within our IT department. Maxim Porges (said manager) will now be managing the department's software architecture team. .... In addition to that role Max will also be managing one of the department's largest software development teams.

Max has been a great help to me over the years, and now that we're going to peers I'll have to start buying him lunch. ;) (There was no way I was picking up my manager's bill! Thanks for all the free ones Max!)

Ataraxis Software is still going strong. It just may slow down over the next 2 weeks. A combination of the holidays and my new role at my company are definetly putting a strain on my productivity.

'06 is going to rock. ~out.

Ian's, "4 Rules for the Practical Entrepreneur"

If you're trying to start your own business, you might be interested in Ian Landsman's lastest blog post, "4 Rules for the Practical Entrepreneur". Ian contrasts a "visionary" and a "practical" entrepreneur.

My journey toward my own software company has been a mix of both. Bouncing between the two. My first idea coming out of college was a "visionary" new service, today it would be called a social networking service. Unfortunately my grand "idea" was a lot better in my head than it was when I tried mocking up the UI. It was also so frigg'n big (and complex) that I didn't (at the time) have the ability to implement it.

After that expierence kind of blew up in my face I decided to go the practial route. Web-based Project Management software. The first few months of this blog covered the start of my journey, so I won't rehash the canceling of the PM project.

My latest project is a web-based service for design companies to upload their work so their clients can review, comment, and eventually approval the pieces. I think it fits into the "practical" mindset. I don't think it is as safe of a bet as PM software, or Ian's own Help Desk software. But, I've identified it as a need of real people I've spoken to, and I think it's small enough of a project to finish in a relatively short time frame by 1 person (me).

I'd love to act on more of my "visionary" ideas, but frankly I need a revenue stream that can support me while I work on the riskier stuff. That's what I hope to achieve with my first few products/services. Get something out, and build from there...

Anyway, just wanted to share the link to Ian's story and give it a little of my own context.

Wednesday, December 14, 2005

Did everyone hate my other blog?

This is weird. My ataraxissoftware.com/blog barely generated any comments/discussion. I've posted three times tonight and I've already had two discussions with Collin and Ian.

The posts on this blog have always generated good conversation. Which I like!

Does everyone just hate the other blog? Or were my posts just that un-inspiring?

Tuesday, December 13, 2005

Random JavaScript Comment

Just throwing this out there...

Does it ever bug anyone that when you need to change an attribute of an HTML tag in JavaScript you have to figure out which of the following ways will work across all the browsers for the particular element attribute you're working with? (Does it ever bug anyone that I use run-on sentences? ;) ).
  • this.element.setAttribute("width", "100") [Generic setter method call.]
  • this.element.style.display = "inline" [Direct access to attribute.]
  • this.element.id = "someId" [Direct access to attribute.]
  • this.element.className = "someClassName" [Direct access to attribute, but you have to append "Name" to "class".]
Annoying, isn't it?

JavaScript headaches...

Alex King is dealing with the hell that is JavaScript development.

I really feel bad for him. I know the torment. I bitched up a storm back when I was developing a web-based Project Management application, and then announced I was ditching XHTML/JavaScript for OpenLaszlo. I've since canceled the Project Management application and instead I am concentrating on something smaller. I'm also going back to an XHTML/JavaScript front-end.... at least for the first version. Ruby on Rails makes the stuff I'm doing with JavaScript/DHTML a lot easier to deal with. But I've got some crazier ideas that I want to build into the new application, and I'm thinking OpenLaszlo would be easier to implement them in. Version 2.0 might get some OpenLaszlo treatment.

Yeah! Ruby on Rails hits 1.0!

Friday, December 09, 2005

Back to flying solo.

This just in.... And then there was One.

Wednesday, December 07, 2005

Update on Designer Project

The "designer" project is coming along nicely. I'm about half way through programming the application. (I haven't started thinking about the billing and other "business" stuff yet. I'm concentrating on "the app".)

I'm actually at the point where I can create an account for a design company, add client companies and clients, and upload images. I need to implement a few more features, but as of tonight the foundation of the application is finally cemented. (All my user security plans, URL schemes, and relationships between my model objects are finalized.)

I've been working like crazy these last two weeks, and I'm making tons of progress. I know I've said it before, but I'm really impressed with Ruby on Rails. The claims about it making you more productive (especially over J2EE) are dead on. Here are the points I feel are saving me time and making me "more productive".

  1. Smart defaults and a convention-based approach (duh, that's what everyone says about Ruby on Rails)
  2. The Active Record ORM framework. WOW. I'm soooo loving Active Record. I never actually used one of the ORM frameworks from the Java world (but I read about Hibernate and I know what ORM frameworks do). I was working with the Spring Framework's JdbcTemplate library on the cancelled PM project. The JdbcTemplate stuff in Spring kicks ass if you want to write SQL. I'm now completely sold on the idea of ORM solutions, which means no SQL. From what I understand, there are a couple of key differences between something like Hibernate (from the Java world) and Active Record.
    1. It's all convention-based, so there is NO external configuration. I say "external" because when you start joining tables together you have to tell your model objects who is related to who. But there is NO mapping of columns to member variables.
    2. You can call methods that don't exist until runtime. I've never seen this before and I was blown away when I came across it in Dave Thomas' book, Agile Web Development with Rails. Allow me to explain.... Let's say you have an object called Person. You've got a database table named, People, that stores all your Person objects. The People table has the columns, "id", "first_name", "last_name", and "favorite_color". Now let's say you want to find all the people that have a favorite color of blue. You would call the following method, Person.find_all_by_favorite_color("blue"). And it would return and array of Person objects who have "blue" stored in their "favorite_color" column. This is impressive for the following reasons.
      1. I didn't have to write any SQL to look up the information and populate all the data in the Person objects.
      2. I didn't have to write the method, find_all_by_favorite_color. The method doesn't even exist in the class file. It's interpreted (or created) at runtime on the object.
      What's even cooler? You can combine the column names with the "find_by" method. So you can call this method (again, without having to write the method in the class file): Person.find_by_first_name_and_last_name('MICHAEL', 'SICA'). Active Record then goes and looks for a record in the People table that match the criteria and then returns to you a fully populated Person object!

    Active Record is saving me a TON of time. Not having to think about fetching the data and populating the objects is a huge time saver.

  3. Extremely simple form binding. I'm not going to go into the details, but it's just as powerful as what Spring MVC offers, but it's about 1/3 less complicated. That, coupled with the rest of the Rails framework (especially Active Record) adds up to a HUGE time-saver.
  4. Built-in Ajax view magic. Again, I'm not going to go into the details. But the "link_to_remote" function rules! :)
I'm really glad I decided to go with Ruby on Rails over Java. This gained productivity is just ridiculous.

Well, this blog post turned into a much longer post than I though it would! Thanks for reading it!

Good Newbie Ruby on Rails blog, (24)slash7

I'm working with Ruby on Rails these days and I ran into an issue with some form-related code. I did a Google search to try and figure it out. In my search I not only found the answer on (24)slash7, but I've now got a new blog to read! Thanks Amy!

If you're working with RoR (especially if you're new to it), I recommend checking out her blog.

Ruby on Rails, CDBaby.com

Is there anyone left who thinks Ruby on Rails is just for small, simple web applications?

Second largest online music store converts to Rails