Archive

Archive for the ‘Tips’ Category

Violet UML Editor

March 2nd, 2010

I use UML to do quick brain storming and when exploring software. While I’ve not posted many write ups here (grad-school!),  I generally don’t want to invest a lot of time in my UML diagrams and only sometimes do I even want to save them.

Often times, especially lately, I’ve been drawing on a whiteboard that I keep in my office.  I find this to be efficient (even over paper because I’d end up throwing it away).

OO Design & Patterns, 2nd Ed Book CoverIn one of my current grad-school classes, we are using “Object-Oriented Design & Patterns” by Cay S. Horstmann as the class text book. I’ve enjoyed the book and it provides some decent examples. I bring the book up because apparently the author of the book created a UML package called Violet UML. I’ve found this to be the best software based UML brain-storming software I’ve ever found. Here are my reasons:

  • It loads quickly
  • I can efficiently draw diagrams without warnings or complex menus to navigate though.
  • The lack of UML rules enforcement means that I can draw partial diagrams; diagrams that mean nothing out of context.
  • It’s open source
  • So far, its more stable / reliable to ArgoUML

If you are looking for a UML package, I must recommend this. I searched and searched for a UML package a while back and I never came up with this. I looked at everything, no matter what and still never found it. So, if you like it, please spread the word (via your own blog, twitter, facebook, etc). I think it is well done software and worth some attention.

http://violet.sourceforge.net/

Design Patterns, Design Tip, Graduate School, Open Source Project, Tips , , , ,

ORM patterns which are ‘Invisible to the eye’

February 10th, 2010

The more I work with design patterns*, the more I come to respect them as a design tool. For grad-school, I’m writing a DVCS and I needed some information on ORM patterns. While I’m not sure if this is a real term, I Googled it and found a great article on Invisible to the eye.

The article can be found at: http://giorgiosironi.blogspot.com/2009/08/10-orm-patterns-components-of-object.html

For my project, I’m mainly interested in the Data Mapper and the Table Data Gateway. Both are patterns from Martin Folwer’s book Patterns of Enterprise Application Architecture.

While I’ve not read the book yet, I think I might… After classes…. Anyway, I mostly wanted to share on the 10 ROM patterns listed at Invisible to the eye.

*If  you’d like a good intro to design patterns, I love Head First Design Patterns

Invisible to the eye

Design Patterns, Design Tip, Graduate School, Tips , , , ,

Using COALESCE to Build Comma-Delimited String directly in SQL

October 27th, 2009

The following article covers a great should-know piece of information for any SQL Server developer. Though, comma delimited strings are not usually desired in database, it can be nice to receive data this way for things like embedding in to a query string or passing over a web service*.

http://www.sqlteam.com/article/using-coalesce-to-build-comma-delimited-string

*I don’t necessarily suggest the web service idea. I was just saying for illustrative purposes…

SQL Server, Tips

Python Memory Performance

October 8th, 2009

I’ve been studying Python because it is extensively used in open source projects to script certain types of work or actions. I think Mozilla uses it to verify build time requirements, for example.

But, python itself is a full fledged programming language — not really a scripting language. In fact, Mercurial is written in Python which at first amazed me.

So, anyway as part of my pursuit of studying Firefox, I thought I should (at least) learn the basics of Python so that I could read any relevant scripts. Python is quite different from other languages I’ve encountered.

One thing I started to notice about python is that it seems to use more memory. I’m not sure, nor am I suggesting that it uses more than other languages. I just noticed that memory consumption seemed to grow rapidly when running a python script.

The following article seems to explain why. Instantiating a class is expensive. According to the article, a class is 336 bytes. Since in general, a class will use multiple other classes, I can see why memory consumption was growing rapidly.

Ultimately, I don’t think it matters. You just need to be aware that it happens. A modern computer will run the script without any notice to this phenomenon. You’d need to create a lot of objects to cause a problem. But I do beleive it is worth acknowledge that it happens so that you can be aware of the memory usage. It’s mostly noticeable on my work computer (the company provided) which only has 1 GBs of RAM (it runs Windows XP).

http://www.valuedlessons.com/2008/10/blog-post.html

Python, Random, Tips

Debug VBScript with Visual Studio

May 21st, 2009

For a project that I work on at at my primary employer, we use VBScript inside of DTS packages. Until this project, I’ve not had too much experience with VBScript. What I’ve found most frustrating about the language is the inability to step though the code… until a recent discovery. I’ve found that if I save the target code to my local machine as a VBS file and execute it with WScript.exe, I can attach a debugger to it.

I’ve discovered this by poking around and I don’t know too much about WScript.exe. I’m sure if you Google it, you can find more about it.

For this to work, you’ll need a copy of Visual Studio installed. I am not sure if any of the express editions will work. Drop a line in the comments if you find it will. As a quick walk though:

  1. Save your code as a VBS file. Don’t forget to call Main (or your main) function as wscript won’t automatically call main.
  2. Open a command prompt.
  3. Navigate to the location of the file.
  4. Type: WScript.exe FileName.vbs //D //X
  5. You should be prompted to select a debugger, select a new instance of either Visual Studio 2003, 2005 or 2008.
  6. Visual studio will open up and break at the very first line.
  7. Step though the code.

For an example, save the following as “Example.vbs” on your desktop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
MsgBox "Starting Script!"
Dim i : i = 0
Const C_Max = 100
Dim sPrimeNumberList : sPrimeNumberList = "Prime Numbers: " & vbCrLf
For i = 0 to C_Max
  If IsNumberPrimeNumber(i) Then
     sPrimeNumberList = sPrimeNumberList & cStr(i) & ", "
  End If
Next
MsgBox sPrimeNumberList
MsgBox "Script Completed."

Public Function IsNumberPrimeNumber(ByVal iNumber)
Dim bIsPrime : bIsPrime = True
For j = 2 To iNumber\2
  bIsPrime = iNumber Mod j > 0
  If Not bIsPrime Then Exit For
Next
IsNumberPrimeNumber = bIsPrime
End Function

Open a command prompt and navigate to your desktop:

Command Prompt for Debugging VBScript from Visual Studio

Command Prompt for Debugging VBScript from Visual Studio

Once there, type in the following:

1
 wscript Example.vbs //D //X

You should then be presented with a dialog similar to the following:

Visual Studio Debugging VBScript

Visual Studio Debugging VBScript

Once you make a selection, you should get something like the following:

Debugging VBScript from Visual Studio

Debugging VBScript from Visual Studio

From here, I’ll assume you are familiar enough with Visual Studio to play with the debugger and learn how it works. When debugging VBScript, I’ve found that you don’t have all the options that you might be used to such as Step In To, but for me simply having this much is a life saver.

To get around the step-in-to thing, I simply use Run to Cursor. It works like a charm.

Update: I just found that (at least on this computer) and in Visual Studio 2003, I have all my standard code-stepping buttons available. I’m not sure why on my work computer I only have Step-Over but either way, this is still a life saver.

Random, Tips , , , ,

Object Relational Mapping > A ‘Design Pattern’ Solution

April 23rd, 2009

There has been a lot written about Object Relational Mapping — or ORM but I came up with a design that I intend to apply to my own projects and wanted to publish and share the idea.

This idea was my own; when I wrote this I hadn’t seen this idea published elsewhere. However, the idea is derived from a set of very common design patterns. It would not surprise me in the least if another designer/developer already implemented a similar idea. However, I digress…

Preliminary Information

The ORM is a method to take data stored in a relational database-type structure and represent the same data as object orientated classes.

I feel that the ten thousand foot level the idea is straight-forward. Assume that we are using the MVC (Model-View-Controller) design pattern for your application. Furthermore, lets assume that we’ve got a simple object to which will represent our Model (part of the MVC).

Lets assume our model object is the following:

Data Model Example

Data Model Example

The idea is to take a mix of the strategy and the decorator pattern. The strategy pattern is a design pattern that allows you to define the interface for an algorithm which can be different depending on the implementation.

The idea of the decorator pattern is to simply add responsibility to a class (through inheritance). My ORM is a combination of the two patterns.

The Design – a Class Diagram

The pattern is simple.

Diagram with OR Design

Diagram with OR Design

We use the interface to represent the ability to write out or read in with the Encoder. You’d implement the interface on to a derived class of the target class.

Why do we implement this interface on a derived class? Strictly speaking, we don’t have to. Though, this is intentional and part of the pattern that I’m trying to describe. This is the part of the strategy pattern working for us. This would allow us to implement different encoders for different types of storage mediums.

This means that we could create a set for SQL server, XML and perhaps a web service if so inclined.

Usage

The usage, I imagine, to be simple. Setup your basic interface and then derive a target class and apply the interface. Implement your interface to write the object and read the object to/from your storage medium.

One point of doing this, is that if a model object contains a collection  or an instances of another model object, you can use this interface to write and retrieve that object.

An Example

In all honesty, I had hoped to put together a simple but working example of this. I’ve not had the time and I’ve been sitting on this post for a while. I wanted to get this post out. I still hope to get together a simple example but for the time being the description is all I’m posting.

If you have specific interest in an actual implemention of my concept here, please leave a message below. The interest will help modivate me to take the time to get something together.

Design Patterns, Design Tip , , , , ,

“Windows OOP” vs. “Cocoa MVC”

March 23rd, 2009

While I don’t agree with the following article that windows developers (the author is looking at .NET, I believe) can’t implement the MVC design pattern, I do agree with the article that MVC is probably a better way to implement one’s interface. I want to direct your attention to the following article.

http://www.cimgf.com/2008/07/29/cocoa-tutorial-windows-oop-vs-cocoa-mvc/

.Net, Cocoa, Design Patterns, Design Tip ,

CLR (.NET) Strings in Memory

February 25th, 2009

The following is an interesting article related to how .NET handles strings. I’m not sure if the same thing might apply to Java; I’d be interested to find out.

Anyway, I’m posting this here for safe keeping and to share it…

http://www.simple-talk.com/community/blogs/jcrease/archive/2009/01/16/71678.aspx

.Net, Coding Tip, Technologies, Tips , ,

9 Examples » Fast and Responsive UI (Link)

February 3rd, 2009

One thing I’ve yet to really learn is how to make a well designed responsive user interface in .NET (or any other language).

I came across this article and I thought I’d share it (and save it here for myself). I’ve yet to delve in to Graham’s example but I trust it will be valuable and hence I’m posting it here.

9 Examples of creating a fast and responsive UI with multi-threadinghttp://goneale.wordpress.com/2009/01/27/9-examples-of-creating-a-fast-and-responsive-ui-with-multi-threading/

Graham’s article also points us to another interesting article; an article he recommends: Give Your .NET-based Application a Fast and Responsive UI with Multiple Threadshttp://msdn.microsoft.com/en-us/magazine/cc300429.aspx

.Net, Design Tip, Multi-Threading, Tips

@@SERVERNAME

January 20th, 2009

I was working on a SQL Server project and came across a piece of code that I wanted to only execute if the code was running in production. This is a fairly common problem — code that should only execute if on a specific environment.

Most of the time in my career, I’ve seen people just comment out the code in a given environment. [And yes, I've seen bad mistakes with this method.] While this has obvious potential side effects I didn’t have time to give it much thought… Until recently.

I realized that SQL Server 2000 has a system variable called @@ServerName that will always give you the server name for the active connection.

Using this system variable, you can write some very simple code that will only execute other code in a given environment.

How can you use the variable?

Usage of the system variable (and any system variable) is easy. You can use either Select, Print or any logical statements (such as If or While loops).

All of the following are validate:

1
2
3
4
5
SELECT @@ServerName
PRINT @@ServerName

IF @@Servername = 'Me' BEGIN
END

How to Implement It

How I implemented it was a bit unique; I will first start with a very simple example.

1
2
3
4
5
6
7
Exec ValidateData

IF @@ServerName = 'ProductionSrvr' BEGIN
    UPDATE Users
    SET Processed = 1
    WHERE UserID = @UserID
END

To quickly walk though this code, it is executeing a stored procedure call ValidateData and then we check the @@ServerName variable to find if it matches “ProductionSrvr”. If @@ServerName does, it will execute the update; otherwise the code would go right over the if. This would be great if you didn’t want to update the Users table in the staging or development environments but you did in production.

My twist on implementation

My primary employer does a thing where they lease their servers (and desktop stations) from a provider. The leases expire every 4 years. This means that every four years we migrate databases and web servers to new machines (or virtual machines, as of recent). To my knowledge, we have hundreds of Servers, serving all sorts of software and information (Web sites, databases, Cubes, etc)

Since our SQL Servers are no exception, I wanted to be prepared for such a switch but I still wanted to implement this because of it’s obvious benefits.

I obviously didn’t want to do a find and replace on all of my Stored Procedures and DTS packages (don’t ask) and so I used a function to check the @@ServerName variable against. The function was simple and an example definition follows:

1
2
3
4
5
6
CREATE FUNCTION dbo.fn_ExampleServer ()
RETURNS VARCHAR(100)
AS
BEGIN
    RETURN 'ExampleServer' --Simply return a constant with the server's name
END

My @@ServerName example above would simply become:

1
2
3
4
5
6
7
EXEC ValidateData

IF @@ServerName = dbo.fn_ExampleServer() BEGIN
    UPDATE Users
    SET Processed = 1
    WHERE UserID = @UserID
END

That’s it! I hope others will find this useful.

Coding Tip, Design Tip, SQL Server, Tips , , , , ,