Thursday, June 27, 2013

Stand Up to Building a Better Product

Okay, this post is related to developing our desktop to web app but in a different way – health. I sit all day and sketch wireframes, explore UI designs, read emails, and then sit some more for research and creating mockups, then some more for lunch, and then in meetings, as well as the commute to and from work. Sit, sit, sit.

Transition: I made a conscious effort to get up more by putting a timer app on my computer that reminded me to get up and move, but really, I needed a reminder to stand, c'mon? I tried stretching at our daily stand-up meetings and doing the occasional squats, but nothing consistent. Reading emails and articles while standing was okay, but hunching over wasn't the most comfortable. I needed to go a step further.

All in: So after a while I thought, how about the opposite. Why not stand all day? Get the blood moving, muscles working, and sit when I need a rest. Now stretching happens more regularly, and although I do have to sit once in a while I'm standing a good 6.5-7 hours per day. Mentally I feel better, I think I'm more focused and less lethargic which I believe makes me think clearer. And if I'm thinking better, then my roll in helping to build the software will be that much better as well. 

I started a blog (standing@work) with really short entries to give people a sense of how I feel during the transition period and what thoughts I'm having while trying this new life style. I sure hope it lasts!


Here are some articles that discuss the problems of sitting all day.
What are the risks of sitting too much?

Monday, June 17, 2013

One benefit of using DeftJS in an ExtJS project.


Sencha has advanced ExtJS over the last several years. While many improvements were implemented, the introduction of MVC – model, view, controller pattern - has greatly added in code maintainability and in creating clear separation of concerns. The model represents an entity, an object where the fields of the entity are defined. The view concentrates on providing a definition of visual components. The logic then is handled in the controllers.

Given this breakdown, let’s look at the controllers and the views. The controllers in the MVC are singletons which means there is only one instance of any given controller in the application. Then that instance is responsible for handling, what may often be, a complex view, consisting of many components and sub views. Since all the logic and event handling is done in the controller, the class can become quite big. It becomes an art to know how to best break down the complexity of one controller into multiple ones. However, aside from that, what emerges as a bigger problem is the ability to unit test the controller. Singletons, as we know, are not unit test friendly. Additionally, traditional ExtJS controllers don’t support injecting dependencies that would provide an ability to use mock data on demand.

This is where DeftJS can help. DeftJS is a component that works with ExtJS and provides extra functionality including dependency injection. Controllers in DeftJS are light view classes that are view specific. By default, they are not singletons (but they can be if desired). Specific views are  controlled by controller classes, which are destroyed when views are destroyed.  This modular approach, coupled with the dependency injection, provides much better support for unit testing ExtJS applications.

Sencha has endorsed DeftJS by including DeftJS documentation on its website and presenting DeftJS at the Sencha Con.

More information can be found at:

Tuesday, June 11, 2013

MSSQL 2012: flattening a parent-child relationship using an XML 'CSV' trick

Ever been faced with a scenario where you know that a particular data relationship will 'always' have a limited number of children, and your UI requirements require tight coupling of parent data with the child collection?  

Sounds like we're about to travel thru a longish diatribe of data normalization do's and don'ts.    Dont worry, bee happy, we's not!

I'm writing this simply to document something that employs a fairly obscure but quite useful T-SQL "XML" technique.. that does just this, putting some powerful 'data-shaping logic' in your hands.

Example:   you have a parent table called 'parent' (and a child collection, called, of all things, 'child').  

The parent table has this structure:

id
parentName
address

The child table has this structure:

id
parentId
childName


Your current app requirements, for example, describe a read-only display, where there is no need for 2 related 'models' to be carried down from server to client.

You want to return, in one stored proc call, a result set that looks like this:

id, parentName, address, "childname1, childname2, childnameXX"

To make life super-easy for UI rendering, we want to return 4 columns.. the 4th being a concatenated 'CSV style' list of related children-properties.. in this case, their names).

Here's the Parent Table

the Child Table

the Stored Procedure ResultSet

And finally, working code follows for the T-SQL Stored Procedure:

Hope you find this as useful as I have.   Enjoy!      -bob



CREATE PROCEDURE  getParentsWithChildrenNames
AS

-- first, we declare a table-var to shape the final result set:

declare @tbl TABLE 
 (
id int,
parentName varchar(100),
address varchar(100),
        childNames varchar(max)
 )

 declare @tblChild TABLE 
  (
parentId int,
childName varchar(100)
  )

INSERT INTO @tbl (id,parentName ,address ,childNames) 
SELECT id, parentName, address, ''
FROM Parent

INSERT INTO @tblChild (parentId, childName ) 
 SELECT  parentId, childName
  FROM child C   
  INNER JOIN parent P on C.id = P.id

-- use 'group-by concatenation' to flatten: (this trick relies upon a well-known XML PATH undoc'd feature, which allows children to be efficiently concatenated) 
UPDATE @tbl
SET childNames = C.childrenString
FROM (SELECT p1.parentId,
  ( SELECT (rtrim(childName) + ',')  
  FROM @tblChild p2
 WHERE p2.parentId = p1.parentId
 ORDER BY childName
FOR XML PATH('') ) AS childrenString
 FROM @tblChild p1
 GROUP BY parentId) C

SELECT * FROM @tbl ORDER BY parentName


-- getParentsWithChildrenNames