Sunday, January 04, 2009 #

Do I put this method into a New Class? Decisions Decisions…

Technorati Tags: ,,

These days I’m working a lot more on not just code features, but also more architecture from scratch.  That is, creating many new Abstract classes, Non-Abstract classes, Interfaces and utilizing more and more Design Patterns.  Thus every field, member, property, etc. created in the class or interface heirarchy tree becomes very important in how you define them and where you define them as well as any dependencies that they may be carrying.  You try to create a class or interface structure with as least # dependencies as possible, so that a change to one object will not affect the other (thus a good separation of concerns in your design).  You’re not just creating a class here and there, but you’re creating the architecture (class trees, foundations for which developers on the team will utilize later). 

With that said, decisions often come down to the simplest & smallest forms when you look at architecting classes or interfaces. It’s not all about the big decisions every time.

The goal is to create good software right?  At least that is what your team & management should have in mind other than just meeting deadlines to please the customer & spitting out code at lightening speed which seems to be the expectations today from the business which often turns into horrible architecture (code & run) as a result.  I’m an advocate of true Agile methodology but not really into Extreme programming personally.

So what defines good software?  An excellent measurement to continually check your code by running it through the ISO/IEC 9126 Standard list which states a very nice list that measures the following in terms of design and determining if your software is meeting business requirements. 

I’m going to reference a table from the book Microsoft® .NET: Architecting Applications for the Enterprise (PRO-Developer) based on the  ISO/IEC 9126 Standard:

(I also appended some of my own thoughts in parenthesis below, and highlighted what I thought was most important from a technical standpoint)

Functionality

- Indicates what the software does to meet expectations

- It is based on requirements such as suitability, accuracy, security, interoperability, and compliance with standards and regulations defined by the customer

Reliability

- Indicates the capability of the software to maintain a given level of performance when used under special conditions

- It is based on requirements such as maturity, fault tolerance, and recoverability

- Maturity is when the software doesn’t experience interruptions in the case of internal software failures

- Fault tolerance indicates the ability to control the failure and maintain a given level of behavior

- Recoverability indicates the ability to recover after failure

Usability

- Indicates the software’s ability to be understood by, used by, and attractive to users. 

- It dictates that the software be compliant with standards and regulations for usability

Efficiency

- Indicates the ability to provide a given level of performance both in terms of appropriate and timely response and resource utilization

Maintainability

- Indicates the software’s ability to support modifications such as corrections, improvements, or adaptations.

- It is based on requirements such as testability (unit testable), stability, ability to be analyzed, and ability to be changed (example: can you easily change out the current DL and create for example your own custom DL?)

Portability

- Indicates the software’s ability to be ported from one platform to another and its capability to coexist with other software in the environment and sharing common resources

Now anyone could easily just skim over the bolded list and really never understand them unless they take time and really care to engage in this list and apply to the development shop. It’s easy to just gloss over the bullets above and say “yea, yea, I know what they mean”.   But do you really?  I bet you that you don’t unless you really take the time to understand what each is and in context to creating maintainable and extensible code.  And I bet if you think you do know, that it’s most likely not even being applied in terms of a team standard or some form of checks & balances on your team often.  If it is, I applaud you and the team.  This would be a very good list for code reviews as well as part of a team standards doc.  While it’s general, it also specifies specifics as you can see above so that there is no confusion what they mean at a high level.

In my opinion, every development lead or manager should ALWAYS use this list as part of your overall tools to make sure that your shop is producing is GOOD software and underlying code and patterns support these points above.  And I think one of the best ways to start doing this is to analyze your codebase to see if it’s easily Unit Testable as it stands today.  If not, then you have some work to do to refactor or make sure new classes or interfaces are going foward.   Checking if it’s unit testable is a very good measure to see if your code is maintainable and extensible at the same time.  Using the SharePoint API with DataSets is not easily unit testable.  It’s tightly coupled which goes completely against unit testable frameworks.  That’s just one example of bad software.

I once had a manager in a past employer (whose extend of technical knowledge miserably failed with the expectation that his team can only use DataSets) who totally disregarded this list.   After a few of us Sr. developers got together and created a PowerPoint as was expected by us from management in order to create some new development standards for the team, the manager responded by laughing & saying “Oh, the ilities (as he chuckled)”.  It was as if he was amusing himself by degrading that slide somehow and wanted to go home for the day.  It was as if he was absolutely annoyed that we had those on the slide and that they were some kind of joke.  This was a PowerPoint for proposing new development standards for a team which was being driven by a bunch of consultants producing Spaghetti code on-site from Clarity Consulting.  And my fellow colleagues and I in that meeting were mutually NOT amused at this development manager’s reaction and his total disregard for good coding standards. 

It’s managers like these which should never be allowed to run a development team to begin with if that’s they carelessness/response that he/she paints to the team and its stakeholders.  Needless to say, I was only there for 2 months thank God, because of the unprofessionalism amongst management as a whole.  Unfortunately, there are people who do just skim over a great requirements list like this, not even thinking about how much it really has to offer in terms of measurement and is a great tool as a manager or lead who really wants to help the business and the team to succeed and to lead projects down the right path (Agile or not).

Now for a simple example at work the other day where a small routine decision in architecture really becomes an all too common very important decision for extensibility, testability, and maintainability hit me again.  I am currently working on creating a small framework that will allow us to utilize the Facebook REST API in order to offer some new features & functionality to our customers for a very good reason via our public e-commerce website.  This project probably will consist of around 20-40 classes or so, and maybe a couple interfaces if it makes sense for some code that we may be able to reuse between some projects.  Fairly small but definitely challenging and complex to say the least based on some of the things we’ll have to incorporate on our side and also get working on the Facebook side of things.

Anyway, it came down to when I created an APIRequest.cs class in my project.  This class would represent an HTTP API method call request to the Facebook API server in order to call a method which resides in the Facebook SOA REST API.  This class will not only hold the data (fields) in the request but help to form the request string itself.   I had to make a decision whether or not to put a method of mine SendAPIRequest() in my APIRequest.cs class or move it to a separate class that would do the sending of the request itself.  In the end, I thought about the Single Responsibility Principal (part of the SOLID Principal) that a friend had reminded me of.  That principal states that a class should only have a single responsibility.  And the responsibility that I defined for my APIRequest class was only to hold the state of a request (the data) and to form the string for the request.  If you find your class starting to do other things (via methods) that doesn’t really make sense to the original class’s purpose (and hence it’s name should also communicate its purpose), then it’s time to break that method(s) or those fields out into a new class.  Breaking it out into a new class made sense was to represent the request data, not to do the work sending the actual request.  So that called for a separation of logic into a new class to handle the actual work to send the request.  This ensured that I was satisfying the SRP principal as well as are easily testable in the future.

That is just one example of a simple decision that I had to make but in the overall scheme of things is a very important decision to:

1) Ensure quality software is produced not only for the business

2) Ensure that the “team” can change the code easily and maintain those classes later without affecting each other (breaking change) down the road

I would not put this method in a utility class because I know that for sending the request, I’m going to need several methods that separate out the logic to do so possibly.  And I also want the fexibility to test the logic as well as extend that functionality later for sending a request.  I want that extensibility to be there in the future so by putting that method in a regular class, not a utility class.  I’m very careful about Utility classes.  You do not want to use a Utility class as a bucket to put all of your business logic in.  They should be held in logical classes unless those utilities are general enough to be reused elsewhere or does not make sense anywhere else.  Do not put all your business logic methods in Utilities is what I’m saying.  You’ll end up with one Utility class with 1000+ lines in it which makes it a big pile, hard to read, and non-testable.  That’s why we use classes, inheritance, and thus separate concerns in terms of logic.  Utility classes have their place but be careful what and how much you put in them.

Conclusion:  Such a small decisions have huge impacts later down the road and one of them is determining where certain class methods should lie in your overall class structure.


   kick it on DotNetKicks.com 

posted @ Sunday, January 04, 2009 10:28 PM | Feedback (0)  

Thursday, January 01, 2009 #

My NHL Winter Classic Preparation & Schedule

For all of you who are going to be watching or attending the NHL Winter Classic, I’d like to share my prep & schedule just for kicks. 

You’ll see what I mean when you see the crowd sitting in 20-30 degree weather with 20-30 mph winds Thursday January 1st, 12 noon

wrigley_preperation_and_schedule

Boy this is gonna be a great time!

Be there!  It’s on NBC, a Historic Event!


posted @ Thursday, January 01, 2009 1:57 AM | Feedback (0)  

Tuesday, December 30, 2008 #

Vantec Hard Disk Enclosures = Poor Quality

I’ve bought 3 Vantec external hard disk cases.  And I have to say I have been very disappointed and I just had to post about this even though it’s unrelated to code.

I have taken very good care of these cases.  I have not mishandled either the cases nor the cords but from my experience each one has failed fast.

Specifically I have had the following problems:

1) Power.  Either the power cord fails, or the actual inlet to the box fails.

2) USB Inlet fails.  It becomes very loose over a short period of time resulting in failure with any USB cord you try.  It ultimately renders your unit worthless

3) Connector to the Hard Disk is very weak.  If you try to take out the hard drive several times, eventually the serial connector rips apart even when you are careful

The 3 (2 different models) of their products in all that make up this boiling pot of poor manufacturing which include the following:

NexStar 3 nextstar3

(I’ve bought 2 of these and both failed miserably.  Bought this a few months ago from Fry’s.)

NexStar MX  nextstarMX

(After a few weeks, I no longer get any power unit even though the cord shows a power light and cables are property in tact.  Bought this 1 month ago from Fry’s.)

Remember that these cases are pretty cheap.  So you get what you pay for as opposed to I would assume as opposed to a case such as a Simple Tech External Array simpletech which runs around $250.  Maybe I just need to spend the $250 and forget these cheaper brands.  But I have yet to pocket out that much money for an external box.  Is it worth it to me?  yes…but have not tried an expensive box like this yet.  Maybe it’s time.

Do not be fooled by the looks and sleekness of Vantech cases.  Buyer Beware on this particular company.  I also suppose you get what you pay for at $30-50 a pop.  To me that’s not that cheap but then again we’re talking about data security and reliability here so that might be a bit cheap if you think about it.

I’m looking for any recommendations for other brands.  Specifically cases that support Dual Hard disks for on the go that you have personally owned, and your experiences with Vantec cases as well.


Share this post :

posted @ Tuesday, December 30, 2008 9:49 PM | Feedback (0)  

Tuesday, December 16, 2008 #

Lhotka’s Post is Pointless – Please Get Rid of VB Microsoft!

Technorati Tags:

I was reading my incoming mail today.  Got another .NET Insight email.  Decided this time to read it and not push it off to my article folder in Gmail.  One of the first lamest articles I’ve ever seen from Visual Studio Magazine which definitely can have good articles, was “hotka’s Labyrinth: The End of the Language Wars”. 

What’s the point of this post?  How does this benefit anyone?  It’s a null point. He claims that this will end the wars against which language is better because .NET is language independent.  As far as I am concerned (someone who started in VB.NET and moved to C# thankfully), this is not the end and language DOES matter because syntax makes my life easier and more productive in terms of typing AND reading (“oh boy here we go again” you may say… but YES IT’S TRUE PEOPLE & IT MATTERS).

You see VB.NET is a verbose pile of **** especially as languages have progressed.  And it’s the truth (now let me here all the flames come in).  There’s absolutely no need for the VB language anymore.  For God sakes, now we have VB, C# and F#.  Lets trim out VB please! 

It reminds me of another point…why do we still use these in US currencypenny ?  It’s pointless and just fills my pockets with unnecessary bulk just like VB.NET fills your classes with overly verbose code to make the compiler happy and a fake sense of “being easier” to those developers who have never had the opportunity or tried to use C# instead.  And for some reason, there are managers who are intimidated by C#’s syntax and the {} which I just do not understand.  It’s a naive view because they most likely have never tried C# to make that statement.   I used to think that way until I had to move to C# and was delighted to work with a much cleaner syntax when this happened in my career.

I dislike VB and its syntax so much now, that I really wish Microsoft would just get rid of it now and forever and stop supporting it making yes, everyone convert their VB code to C# or F#..something NOT verbose.  In fact I  have in the past turned down any opportunities in the workplace that say they use any VB at all period, even if they are refactoring it to C# because I just hate it.  Same for any lingering classic ASP still out there.  If you think I’m limiting myself, sorry, I am glad I don’t have to touch either of them anymore and am very happy because of it.

Microsoft feels obligated to continue to support VB not because people have used it in industry, but because Bill Gates still wants it because he is stuck on it.  All their apps are coded in C or C# anyway internally I believe for the most part. Most developers who have had to code in C# (came from C++ or not, or did not and moved to it) don’t want to touch the verbose pile VB ever again.  If they can both do the same thing, why the hell do we have VB?  Cause it’s easier syntax?  I can tell you that you are blinded if you think this is true.  Try moving to C# then back to VB.NET and you have to add so many words to your syntax that you’ll get carpel tunnel in a matter of minutes.  Make everyone convert their pile (VB pile that is) to C# if they both can do the same thing so we can all just work with cleaner less verbose piles of code.

This war is not over until VB is laid down to rest forever as far as I’m concerned…it’s an old language that just needs to go away for good (same with COBOL, Cold Fusion, etc.)…may its verbose pile of shit rest in piece.  I just can’t stand coding in it anymore let along looking at it anymore.  More characters also means more to remember because the damn syntax is so long and is much harder to read.

examples (from another very old site) :

C#

VB.NET

string a = String.Empty;

(21 chars)

 

Dim a as String = String.Empty()

(27 chars)

while (c < 10)
  c++;

(15 chars)

While c < 10
  c += 1
End While

(21 chars)

int[] nums = {1, 2, 3};
(18 chars)

Dim nums() As Integer = {1, 2, 3} 

(26 chars)

delegate void MsgArrivedEventHandler(string message);

(50chars)

Delegate Sub MsgArrivedEventHandler(ByVal message As String)

(55 chars)

void TestFunc(int x, ref int y, out int z) {
  x++;  
  y++;
  z = 5;
}

(48 chars)

Sub TestFunc(ByVal x As Integer, ByRef y As Integer, ByRef z As Integer)
  x += 1
  y += 1
  z = 5
End Sub

(77 chars)

\r    // carriage-return
\n    // line-feed
\t    // tab
\\    // backslash
\"    // quote

 (10 chars)

vbCrLf, vbCr, vbLf, vbNewLine
vbNullString
vbTab
vbBack
vbFormFeed
vbVerticalTab

""

(74 chars)

 

public int Size {
get {
    return _size;
  }
set {
    if (value < 0)
      _size = 0;
    else
      _size = value;
  }

  (71 chars)

Public Property Size() As Integer
Get
    Return _size
End Get
Set (ByVal Value As Integer)
    If Value < 0 Then
      _size = 0
    Else
      _size = Value
    End If
End Set
End Property

(130 chars)

(carpel tunnel is creeping in!

AND my eyes are hurting from reading code)

The red I added semi-outlines of some of the the extra what I call “fluff” that you just do not need and do not have to put up with in C# or other languages.  You multiply these extra chars, lines, and just compiler required trash per page, and you’re wasting your time as well as it’s just a pain in the ass to read.  One might argue that the C# syntax requires an extra ; but so what!!  Sure beats writing 1/3 of the page with more chars!

If they both do the same thing and I had a choice, why the hell would I pick VB when it just makes more work for me both in readability and code?   I like my classes as tight as possible, and as less code as possible.

Please, if you ever have a choice in your career or as a team, please do yourself a favor and go with C# and just forget VB even exists.  You will find in about 2 weeks transitioning over to C# is actually much easier.  I’ve experienced it.  This illusion that C# is some sort of harder language is just not true.  You will not get this until you get out of your VB world and try it for a couple weeks.  Looking up any of the examples above you’re gonna find that hey, really it’s just less characters mostly for C# and minor difference otherwise that takes no learning curve at all!

For those who read my blog don’t let this offend you, but I have a real strong opinion where VB can be put, and that is in the grave.  Rest its little soul.  It’s pointless to have around when they “both do the same damn thing”. 

Again, this comes from someone who has experienced the change and wonders why the hell MS still supports VB.  It DOES matter to this programmer and to a lot of others out there who have been there and know what I’m talking about.  Angry about VB?  I guess yea I am at that point with VB, I’m really tired of seeing it around.


     kick it on DotNetKicks.com 

posted @ Tuesday, December 16, 2008 9:55 PM | Feedback (22)  

Sunday, December 14, 2008 #

Speed Dial for FireFox – A Must Have In Your Browser ToolSet

Technorati Tags: ,

Speed Dial has been around for quite a while.  But have you really tried it out and seen how useful this is?  While it may slow down FireFox a little bit (small inconvenience if you manage it right), I love it.  Rather than hunt through a ton of favorites or even use Google’s tabs on my Google homepage, I like this even better because I don’t have to do anything to find my most used sites.  It’s right in my browser after I launch Mozilla.

Speed Dial saves me a lot of time because I can do several things:

1) Logically separate out my most frequently visited sites in tabs without hunting through the tedious & time consuming favorites menu.  I’m not a huge fan of favorites because for me even though organized, it just gets way too much to manage in the long run.

2) See thumbnails of them.  The visual aspect at least for me is nice and I love this

3) Create a tab for “things to read later”, where I can get rid of opened FireFox tabs/pages that I have open for the day (the more FireFox tabs you have open obviously will slow down FireFox).  Just throw the URL into a Speed Dial Tab called “Read later” and just follow-up with those great reads later

4) Ability to export my entire Speed Dial settings to another PC with just a couple clicks.

5) Complete control on # rows, # columns, and a ton of other values to control rendering quality, etc. to speed it up if I choose to make it more efficient

Here’s a small glimpse of how I’m using it to my advantage currently:

speeddial_printscreen

Notice you’re still going to have your standard FireFox tabs above it (I am just showing one at the moment “Speed Dial”).

Some may say it’s too resource intensive/heavy but I guess that depends on how you are using it and set it up in my opinion; Just make sure you don’t set it up to auto refresh though on each opening of FireFox.   Only force a manual refresh when you feel it’s necessary.

it’s pretty useful…give it a try. 

You can get it here.


     kick it on DotNetKicks.com

Share this post :

posted @ Sunday, December 14, 2008 9:27 PM | Feedback (0)  

Saturday, December 13, 2008 #

Visual Studio Themes

I would like to expand this post with your themes.  I will start with mine and if you send me yours I will edit this post & put it up for you and I will include your name (if you do not want your name given just tell me), settings file for download, and a screen shot

Please make sure they are original (your own work) and you did not get them from Scott Gu, Scott Henselman or any other site for that matter.  I think it would be cool to get some more original what I call artistic templates for people to have fun with.  I will grow this post indefinitely.  Hopefully this becomes a very cool/fun post as it grows.

Here’s mine (here’s the file):

daveschinkel_vssettings

To participate, please email your .vssettings file to vsthemes@gmail.com. 

I will create a snapshot of it and include it in this post.  Please do make an effort to get yours to me.  I would love to see this become a huge list.

     kick it on DotNetKicks.com

Share this post :

 


Contributors


Theme Name: Vlko Black

Contributor: Vlko (Marián Vlčák)  | download

Námestovo in Slovakia Europe

vlko_vssettings

Looking for yours…please send me an email to vsthemse@gmail.com with your name & location and whatever other info you want to share

posted @ Saturday, December 13, 2008 10:15 PM | Feedback (0)  

Wednesday, December 10, 2008 #

Be a Keyboard Guru, not a Mouse Guru

Technorati Tags: ,

For a long time, I used my mouse rather than my keyboard as a primary means (with exception to the basic keyboard shortcuts) to move around in Visual Studio.  Obviously I knew that this was not efficient even though I’d lie to myself and say to colleagues I was just as fast with my mouse and my few pile of shortcuts as with anyone who used keyboard shortcuts as a primary means to navigate around windows or code.  Since then I’ve picked up a ton of shortcuts and realize just how fast it really is.  The time you take to drag your mouse, click, and then open a window alone is just really inefficient.  But you won’t see this until you start using shortcuts more and more.

If you are a developer who wants to improve your skills, do not just think of code & syntax.  Have you ever been in front of a team lead or architect lead and they look like magicians when they code and you feel embarrassed when you pick up your mouse?  I know I have.  Well, it’s not really anything fancy.  They are not musicians even though it’s intimidating when you are not that fast with the keyboard;  it’s just that they have accumulated skills throughout the years by building first and foremost on their shortcuts.  Just like what you type is second nature so will the shortcuts be.  In fact, have you ever tried to ask one of your star programmers what shortcut they just used when you see them flying across the screen?  Chances are they can’t tell you because it’s become intuitive.

I used to think it was a hassle to have to learn all those shortcuts.  But when you just take a few and work with them, you’ll be surprised how fast they become second nature.  My advice is take 5-10 a month.   Build on it.  After you start to know those 5 without having to remember, then move on to the next 5.  Eventually you’re productivity over time will just improve like you cannot believe.  The trick is not to try to master too many at one time.

Like anything skills build rapidly on top of each other.  And we spend enough time navigating, that it’s really not fair to ourselves when we think that’s suffice.  You think you are just as quick with a mouse and I can tell you stop kidding yourself and get working on your keyboard skills now!  One of the first things as a developer starting out would be to master your keyboard shortcuts, especially in Visual Studio.  It’s one of the best gifts that you can give to yourself so make it a plan to start that as a new years resolution if you have never taken them seriously for 2009.  Your time is valuable from the time you start work till the end of the day. Why not shave some time off every day that you are programming which leads to faster completion of your projects.

One of the best books out there right now is Sara Ford’s new book.  I have this and I can say she starts out with basics.  Basics everyone that you’ve seen knows.  Every architect you see probably knows every single shortcut she is talking about (Ctrl X, Ctrl L, etc.).  I highly advise this read if you have not invested in it already. 

It’s a very easy read and you get instant results from this book:

Microsoft Visual Studio Tips

ISBN: 0735626405
ISBN-13: 9780735626409

Also visit her website which deals mainly with improving your productivity with shortcuts.  However, this book has the most commonly used shortcuts out there so it will save you time rather than search her entire blog or the hundreds of other blogs out there.


    kick it on DotNetKicks.com

Share this post :

posted @ Wednesday, December 10, 2008 9:34 PM | Feedback (6)  

Monday, December 08, 2008 #

Cyclomatic Complexity Standard for Methods

Technorati Tags:

I think one of the best standards any team could have in their pocket is the Cyclomatic Complexity metric by Thomas McCabe.  It sounds fancy but really it’s just a very good guideline that every developer on your team should use and think about when creating a method every time in code.

It’s simple, your methods get a risk rating based on the following forumual:number of decision points +1

a decision point is just a line in the method where you had to make a decision with code (see the example in Wikipedia).

cyclogrid

And part of this metric says to try to have no more than 7 parameters in your methods.  Sometimes you may go over but if you are finding that you have so many incoming parameters, you are most likely trying to do too much in that method OR you should have put a lot of those parameters into an object for example, or used an existing object that maybe you did not know exist.  Maybe there is a pattern already setup in your code by other developers that you could use.  Or there may be another bad design reason why you’re sending more than 7 parameters into your method.  But definitely too many parameters is sloppy.  There are better ways to do this, again such as sending in an object or whatever else the case may be that you can rid so many parameters.

Keep in mind Methods are meant to organize your code.  They are meant to be a UNIT of work.  Not an entire process!  If you find your method getting beyond 50 lines it may be time to start moving a lot of that logic into reusable methods and calling those methods from your method that you just cleaned up.   The whole point of code is not just encapsulation, inheritance, etc.  but also that it’s readable for you and others.  Who wants to read a 50+ line method every time and multiply that times several that you may have to debug.  You are basically making the code as hard to debug as a damn stored procedure with 500 lines at that point.

Reflector has a plugin which will perform Cylcomatic Complexity analysis on your assembly also, so check that out.

Check out the full details about Cyclomatic Complexity.  It’ a simple solid metric that you should never disregard and truly enforce on your team and yourself.  This is a discipline that’s i