Practicing vs Preaching

There are good practices and then there are those that work, but are not necessarily good. There is a difference between a good programmer and a programmer, and NO the difference is *NOT* "Good and Evil" but the methodologies employed by the developer/programmer. In the 80's and the 90's when Computing was kind of new and mostly non GUI, there was great emphasis on practices and methodologies. It is almost such that at one glance of the code, you can tell if the developer has any coding vices.

Now with mobile development, the developers want to squeeze every bit from the device. However said, when posting code on the forums/blogs/magazines the code has to be easy to understand. Optimised code is good for compiling where as *generally* non-optimised code is what is shared. The difference can be in ms but these few ms can be very critical in a screen/animation/audio jitter and smoothness.

It is nice to inculcate good habits, but it is easier to inculcate Bad Habits and retain them. The things that gets me is that the Staff at Ansca, that recommends and writes articles on optimization and good techniques miss the most basic of them all, this has been discussed and it still remains. Donning the Hat of an Academic, I would say that if this definitely is a person that has not been through the rigorous shaping via code writing. If a person has not attended University specific to development related programs, but has written enough code, they can at a glance know what the issues are and will not repeat them and will take extra precaution dealing with those areas. If the person is a university graduate, then they would have studied the fundamentals of programming to the extent that they *will* not make the silly mistakes. However, we are all human.

I look back at some of the code I have presented, there can be some typos, both in the code and the text, now who said writing code in a webpage is easy specially when there is no autocomplete or highlighting or autocorrect. Plus this interface highlights every other word as a typo given the British English and American English differences, like Color and Colour.

However I cannot help notice this glaring *ERROR* found on http://developer.anscamobile.com/forum/2011/12/03/tips-optimization-101
tip #5 and the irony is that the discussion is about *Bad Practices*

The offending code that has sparked this blog post is

local tRemove = table.remove
 
for i = 1, #mySheets do
    mySheets[i]:dispose
    mySheets[i] = nil
end
 
tRemove(mySheets)

This by no means is the acceptable way to deal with removals in loops. Irrespective of *in this context* this is a practice *never* to be employed when removing items

the *correct* method is to use a reverse loop, from the max to the first item and removing them that way. so the code *should* look like

local tRemove = table.remove
 
for i = #mySheets,1,-1 do
    mySheets[i]:dispose
    mySheets[i] = nil
end
 
tRemove(mySheets)

if this code was removing items from a group or display objects, the code as per *Ansca* staff is

for i = 1, theGroup.numChildren do
    theGroup[i]:removeSelf()
end

and this will cause errors where as if the same was used with a reverse descending loop as

for i = theGroup.numChildren,1,-1 do
    theGroup[i]:removeSelf()
end

it will work without errors and problems.

What gets me is that this is *Ansca* Staff that writes these kind of posts, these are then read by the magnitude of developers that cling on to every word just because there is that Ansca Logo/badge that says "Ansca Staff". Just yesterday I had blogged about how another *Staff* member has been prompting users/developers to either use the paid options for code review or post to the community at large. So is this the quality of the Code Review and assistance that developers shall be getting if they were to pay Ansca in excess of $150-225 / hour? Is this what they are spreading as *official* tips.

I have always maintained that there should be a delineation between Official Capacity and Personal Capacity. That is one of the reasons why many emails have a disclaimer at the bottom that states that the opinions of the person are theirs alone and not of the organisation. However in this case, Ansca stands by every staff member, which is a good thing but that is of concern given the events.

This is one example, there have been and are plenty more examples of such anomalies. I get a feeling that the good stuff that CoronaSDK was made of is now getting diluted, not because of the complexity, but because of the quality of code that goes into it. Walter, Eric and Tom have worked hard to being this to a stage it is, but instead of becoming rock solid, it is more temperamental and shaky. I do hope that it does become stable and is adopted, but then I am also critical as it does affect me and the developers that might be or not be aware.

Comments

  1. I have been asking on the forums for an updated and organized "best practices" section (instead of case by case forum threads or blog posts).
    I am not able to judge the quality of code provided, but as I am willing to invest some business time in it, this could become a growing concern for me.

    ReplyDelete
  2. Mr. Mells, Optimization is good, as mentioned, specially when you want to squeeze that last bit of performance from the mobile CPU's. However the difference between rock solid code and buggy code are small oversights like this.

    There were no patches for software in the 80's and what was burned onto ROM was burned for ever. Ricardo has this wonderful Director Class that worked for a very long time without updates (had a few bugs, yes), however Ansca has started with their own alternative that has bug fixes every other build, they do because they can. They do not sit and look at it properly like software development should be...

    ReplyDelete
  3. Please tell us more about your 'secret plan coming soon'.
    How much will it impact the use of the framework and what's your target (seasonal developers? etc...)

    That becomes interesting when people try to move forward and build upon what's already good (from my understanding of your opinion about the framework despite the frequent use of 'disappointment' in your tags).

    ReplyDelete
  4. Mr. Mells, one thing is for sure, you cannot be disappointed with something if you did not have hopes on it. So, yes despite my tag disappointment as I did mention, I have a Love/Hate relationship with CoronaSDK.

    As for the *secret plan* between the bread&butter jobs, I am working on it. If I feel to severely impaired by the limitations of Corona I would have to scrap and start with objective-C or similar.

    Who will it impact, it would have two layers, so it will impact both the beginners and the advanced developers based on how they use it. Think of it as the difference between GUI based development (that generates the code) and writing the code.

    ReplyDelete

Post a Comment

Popular Posts