Monday, June 26, 2006

100% Reusability?

As developers, we often speak about "Reusability". We all want to make our code and components "reusable", to make life easier. Do we really have to make things "reusable"? In reality, how "reusable" are things? Well.. I am not an expert developer, but, I guess I learnt a lot from what I see around me..and.. almost 60% of what I see doesnt really fit into the reusability bracket. Ok, its time I mentioned that I am a Flash Developer. In the Flash world, we used to replicate behaviour to make things reusable back during the earlier versions. "Smart Movieclips" became an interesting concept and most people used it to a good extent. The capabilities of Flash has grown significantly, and, with MX 2004 came ActionScript 2.0.

AS 2.0 changed a lot of things - the way we thought and the way we did things. It brought in "Classes" and all those things that came with it! In a broader bracket - OOPS (Object Oriented Programming). AS 2.0 is not perfect OOPS, but, it is Object-oriented nevertheless. Anyhow, many people I know started to over use Classes and pushed it in whereever possible. "Frame Scripting", they said, wasnt the way to go, since, things have to be reusable and AS 2.0. This has been argued quite a few times and it is still misunderstood. The way a lot of people in the community use OOPS is foggy! Well.. to me, code isnt and shouldnt be 100% reusable. You need to have a good degree of flexibility in it. As human beings, the way we think about something changes every now and then. As a developer, we look at a piece of code after a week and feel that it could have been done in another, simpler and more efficient way. This is where "Flexibility" kicks in! I've seen code..which is resuable only as long as it keeps doing the same kind of things in the same way. Its more of a fireline..u cant cross it to do something a bit different. Its also about how easy it is to make it work. This is a reason I used to like the V1 components (shipped with MX) a lot more. The components were easy to use and easy to customize. It was as easy as editing a movieclip. V2 components do provide a whole lot of kewl features, but, I guess that the simpler things and things people want to do..have been made difficult.

The way I code has changed quite a lot from the time I started on my AS feeding bottle. My coding really depends on the functionality. If I have a 100 buttons that do the same thing, I'd link them to a class and make merry. If I feel that the buttons need to be dynamic in some ways, I use Properties, which can be defined. I also use Frame AS quite a lot. Parts that are solely meant for that SWF go into the frame. I am building a library of classes I reuse, so, I have it all in one place and accessible anytime. They are not always reusable as is..but..modification needed is minimal. Well, this wouldnt be the way you might look at it..lets say, as a web developer or an RIA developer. In my line of work, it isnt quite often that you can reuse a whole class, for example. Specification and functionality can differ quite a lot. It sometimes is easier to create from scratch than customize code. Common behaviours, custom events and functions that are common to all projects are being reused. We also reuse code internally within the product. But, here again, this code falls behind the fireline. You maynot be able to use it for other projects that vary in features and functionality
quite a lot.


So, code needs to be Reusable and Flexible. It doesnt mean that you need to use AS 2.0 to make things REUSABLE! Smart Clips wasnt AS 2.0!! It was Frame Script all the way! I am not trying to go back in my ways. Just trying to say.. use 'em both in the right way!

No comments: