Thursday, August 29, 2013

New JQuery Hottish Stuff

 It seems like we acquired some plugin fatigue, and not much happened this year in JQuery.

But here are some very nice new plugins:

http://cloudfour.github.io/SimpleSlideView/responsive.html

http://fineuploader.com/fine-uploader-basic-demo.html


Also I think we should all start to get really into JQuery Mobile and responsive design, which is the new progressive enhancement.

JQuery Mobile:
http://jquerymobile.com/demos/1.3.0-beta.1/

http://jquerymobile.com/demos/1.3.0-beta.1/docs/content/content-grids-responsive.html#

http://jquerymobile.com/demos/1.3.0-beta.1/docs/content/content-collapsible.html

Tuesday, August 20, 2013

Clean Code - Assessing Code Quality - Part 2

Clean Code starts with good names

Articulate names for your coding objects are the primary tool for creating clearly understandable code.

Do not add gratuitous context

Prefixing your code names with extra context like the business name, name space, or extra type information just add superfluous information that must be read. Give your object a good descriptive name, and leave off the code hierarchical context, you tooling can tell you how it participates in the hierarchy.

What is in a Name?

Objects and Functions

Objects should use Pascal Case, and start with a capital letter and Functions should be Camel Cased, and start with a lower case letter.  

Classes and Variables

Classes and variable names should be nouns, named after a problem domain actor, a system API or an artifact. Examples are Document, and User. Classes should use Pascal Case, and start with a capital letter.

Interface

An interface should be an adjective, or in some cases a descriptive noun.  Interfaces should be named as nouns, noun phrases, or adjectives that describe the behavior. Interfaces are prefixed with an “I” Examples are printable, and enumerable, don’t be afraid to make up your own adjectives.

Functions and Methods

Functions and methods should have names that are verbs, denoting the action they are going to take. Methods are Camel Case, and start with a lower case letter.  Examples are export, save, add, delete.

Methods Names

Method names often need to have more information to differentiate the method between implementations.  So often you will need to suffix your name with a Camel Case description of the operation details. For Example, saveToDisk, and printToClient.

Adding Method Scope Information

Often with a complex class, we can have multiple methods that perform similar actions but differ by the arguments that they take. Most often we tackle that problem with method overloading with the same name and different signature, but sometimes it is helpful to add an adverb explaining the “how” that happens to the verb.

Abbreviations

Most Abbreviations only obfuscate the meaning of the code, so in most cases use the full word. Notable cases are where the Comp-Sci Solution Domain standard abbreviations exist. Below is an example of standard names.

Abbreviation
Description
arg
argument (function parameter)
bin
binary
bool
boolean
char
character
doc
document
elm
element (dom node)
fn
function
hex
hexadecimal
id
identifier
int
Integer
max
maximum
min
minimum
num
number
obj
object
oct
octal
prop
property
seq
sequence
str
string
substr
sub-string

Adding Scope into a name

Sometimes it helps to add scope into the name of an object.  We can note an object as being internal to its parent by prefixing it with the underscore sigil, marking _tempName as private to the function. A not on JavaScript and closure, never mark a variable that you are going to be closing over as private, as this send that wrong signal.
For noting that an object is in the global scope, prefix the object with global, and for the object using camel casing. Like globalUserPrintQueue, note that we prefix with scope, include information from the problem domain, and then include information from the solution domain.

What the Name Describes

The name primarily should describe the behavior of the problem domain. If the solution domain will assist in the next programmer’s understanding then include that also in your name.  So if the item in the problem domain is the “User” and we want to make a standard assembly for creating the user. We can use the description from the solution domain. So we have userFactory.

Functions are Cohesive

A function should be both compact and cohesive.  The function body should be less than thirty lines of code, and should perform only one function without side effects. All the actions that the function should perform should form a coherent whole, and only perform one operation or just one set of coherent operations.

One Level of Abstraction

A function should contain only one level of abstraction. Like in the case of the solution, would be one level of abstraction and a separate level of abstraction, animal.  So we want our method to contain only one level of abstraction, of course polymorphism is excused from this.

Logically Organization

Your classes should be logically organized, and the flow should be from less-complex, at the top to more-complex, the implementation details, towards the bottom. Your code should progressively reveal complexity to the maintainer as your code is read, divulging intricacies like an onion.

You should group Classes that perform similar operations into Namespaces, establishing a code hierarchy.

Note on case and notations:

Pascal case: The first letter of all words is capitalized; no spaces, underscores or special characters are used. Example: BackgoundColor, Gray.
Camel case: Except for the very first letter, with is lower case, the first letter of all words is capitalized, no spaces, underscores or special characters are used. Example: backgoundColor, gray.
Uppercase: All the letters are capitalized, by common convention this is reserved for use on abbreviations of 4 letters or less.  Example:  System.IO, MSDN.Library
Hungarian notation:  The name will be prefixed with an abbreviation of the objects data type, and be in Camel case, meaning that the first letter (the abbreviated type) will not be capitalized, but the beginning of each word after will be capitalized.

So some rules from Clean Code

1.       Do not add gratuitous context.
2.       Use Names based on the solution domain first, and then names based on the problem domain.
3.       Use descriptive names.
4.       A method should be cohesive, and responsible for only one thing.
5.       Include only one level of abstraction in a method.

Monday, August 19, 2013

Assessing Code Quality - Part 1



Knowing what good is, and being able to articulate what code demonstrates quality is important in setting up a technology roadmap for the group.

"Easy is good, 
simple is better." 
-g.dirlam 2012

Eloquent is better than Elegant

A hallmark of  very good code is that it is "less." So this is a simple lesson, elegant code gets you good, removing code from the overall code footprint means you have achieved "very good."

In order to be useful to a business the code base does not have to house elegant solutions, if this was a prerequisite for business code then almost all  businesses would be closed. So if it does not need to be elegant than what does it need to be? Code needs to be maintainable. And it is easier to maintain smaller blocks of code than it is to  maintain large code-bases.

So it is true that good names are better than clever design patterns. It is in the nature of a programmer to be self satisfied with creating a clever solution of design patterns, but trust me, real accomplishment comes from giving all the objects in your solution names that everyone can understand.

"Give me some sugar baby," syntactic sugar allows modern programs to be more eloquent, to express relationships in compressed form. Keeping current with modern trends allow you to write inline lambda expressions that do highly complex things, in short segments of code. Use sugar, but just make sure to keep it legible.

In order to be eloquent, the programmer needs to choose fully articulate descriptive names for the objects in his code.

So some rules from Clean Code

  1. Do not add gratuitous context.
  2. Use Names based on the solution domain first, then names based on the problem domain.
  3. Use descriptive names.
  4. A method should be cohesive, and responsible for only one thing.
  5. Include only one level of abstraction in a method.

Needs to run and perform as expected

So business code needs to be maintainable, and it also must meet the needs of business, and thereby be functionally business complete. This means that that the solution meets all the actual requirements to be feature complete with the business. By this I mean that the program performs all the expected functions, that the program runs as expected and conducts business.

So to sum-up. Codes needs to perform and run properly, it needs to meet the immediate business need, it needs to be written in a clear and concise manner, it needs to be small and maintainable. If you are really industrious you can make sure it scales globally as far as localization, and that it can run a vast array of servers.



Thursday, August 8, 2013

What my friends from AP taught me.

"Do you know that feeling when you get a gift that you really needed, but you just did not know you needed it." That is how I think about the good times that I spent with my friends from Hyderabad.

I suppose I will never truly know what they think about the first world and U.S. culture specifically, but what I did realize is that coming from a different culture affords them different overall strengths and weaknesses. Please understand all individuals are extremely complex, and cultures are not even knowable when you have been raised in them, but if we use a broad enough brush, we should be able to paint some generalizations. 

So without future introspection we will get to "What I learned from my Friends from Andhra Pradesh."

Emotional control is important, it is a skill that you need to work on. 
So I joined an almost exclusively indian team, almost all coming from A.P. Soon on, I realized that they had much better control over when they wanted to go to argue and go on the warpath. I would run around creating chaos, and they would shake their heads and say "No Gareth" in the nicest of ways. After a couple of episodes of this, I started to feel like a clod. It took some time, and also backing down to one or two cups of coffee, but I got to the point that just because I was feeling badly did not mean that I would make a emotional mess for everyone.
 Being a good person is important, it is something you need to refine and work on.
You need to endeavor to be a good person. You need to continue to work at it. Oddly enough, the overall definition of what a good person does seems to be remarkably similar. Dutiful, honest, giving, not greedy, concerned for the welfare of others, yup, really I never found anything different in our definitions. What I did notice is the fact that my friends from AP meant it, they were not just saying, they were trying to work at it. Not always succeeding mind you, but they would like to change the world for the better with their actions. This is never too far away from their conversations. You really can't go a whole day without someone in the group pointing out how someones actions are selfless and for everyones good. Which brings us to the next point...
Working in a group involves skills and communication, you should get better at this.  
When working in the group, you need to point out successful things that people in the group are doing and praises them. Praising and teasing are strong team building activities. 
So it might not be much of a cultural exchange.  I do value the ten odd words of Telegu that I know know, and the three written words I can scratch out. I know more about the geography and the history of the different cultures and languages there. All in all an amazing experience for me.

 

 

Wednesday, August 7, 2013

Retrospectively Yours: Reviewing The Past

I just finished up a letter to a programmer mentor and friend, he will no doubt think of it as way too long, but c'est la vie. It made me wonder if we don't remember the transitional steps we go through and the important ideas we coalesce into our tool-sets and where they come from.

I like to think of engineering teams as a group that picks ideas. What ideas that are picked up by the group and "internalized" is probably the most important decision made in the development group. Ideas that functionally result in a mess, can be catastrophic to an organization, and will be a millstone around the organization long after those responsible have left.

The steps in my own professional development from script-kiddie to tool-builder, have taken me to many interesting intellectual places, from standards driven development to custom extension building, but still, even after 20 years worth of programming I am not insured of making the correct decision. That is where my team comes in, during the collaborative process we all contribute to finding a decision that results in the minimum overall institutional mess, and believe you me, the decisions I arrive at myself are considerably weaker then the team decisions.

On a good team, your team mates are just your friends, and you look to your friends to help moderate your behavior and to help you make sound judgements. Also you expect to be able to help them, and to care about the various outcomes. When I look to my past in programming, I just see groups of friends, cheerfully writing code, building websites and stuffing up managers.

Technical Team Leadership

"Being an IT team lead is allot like being a really ugly mathletics cheerleader."
-g.dirlam 2013

Collaborative teams means that the team leader is there as a discussion moderator, he has little particular power. I like to say that I team leaders power consist of moderating the discussion, and controlling the learning syllabus. These are powerful tools when used in collaborative environments, the set the agenda of the team, and establish the team's technical trajectory.

The single most important goals of a team leader should be to facilitate skills enhancement and increase unit cohesion.  You want to create a process that bakes in cross-functional skills and creates collaboration and dependencies in your team.

The discussion moderator will be rewarded for having useful discussions and for the corollary he will be punished and made the subject of derision and mocking. Teams communicate with meetings, if they are heinous, it erodes the team's cohesion. Ending your meetings on time, and sending discussions that are not useful for the whole team to the "parking lot" are activities that will result in you making friends. If you run rambling meeting, your team will make you the butt of their jokes. Also it is a useful sign that the team is broken.

It is important that you start establishing your technical roadmap as soon as possible, and that you put some love into it. You will need some organic, growing artifacts to support your thoughts, and give them life. This roadmap will dictate the development of a learning syllabus for the team.

It is hard to get to the point where you have enough trust to share what you don't know. But it is exactly here that you need to get yourself and your team. You need to be open, you need to be fair, and you need to be positive for long enough that your team sees these as personality traits, so that your team decides they can trust you with what they actually do not know.

How could you attempt to fill in technical gaps if you don't know they exist? Why should your team point out things they are not good at, if you the team leader never admits to not knowing technical things. It is easy for us to say we don't know a business process, and say, look we say we don't know things, but then when it comes to the technical, we make out as if we already knew it. It is hard to admit we don't know something that we really should have known, but if you don't as a team leader, there is no way you will establish the trust of your team. Truth is an important foundation of life-long learning, and this allows you to set the team syllabus.


Tuesday, August 6, 2013

Hip Hip 'Array

['hip', 'hip'] 
//the hip hip array.