Code Analysis with NDepend

When our projects reach a certain size it is very hard to determine the complexity of our code. It gets harder and harder to see the overall picture. It also becomes very easy to introduce unnecessary complexity to parts of our system that we don’t want to. In simple words, it’s easy to get lost. Especially if there are may people working on the project.

On top of many other tools, practices and principles like unit tests, integration tests, acceptance tests, continuous integration, it is static code analysis tools like NDepend that come into play.

Continue reading “Code Analysis with NDepend”

Code Analysis with NDepend

Find Stored Procedure by Name

There are several ways to find a stored procedure in the server by name: we can query sys.procedures, syscomments, or information_scema.routines. Respective examples would be:

select * from   sys.procedures
where    name like '%name_of_proc%'

or

select text 
from 
    syscomments c
    inner join sys.procedures p on p.object_id = c.object_id
where 
    p.name like '%name_of_proc%'

or

select * 
from
    information_schema.routines
where
    routine_name like '%name_of_proc%'
Find Stored Procedure by Name

The Story of the Modern Day Developer

Software Developer, a “Programmer” even an “Engineer” or a “Craftsman“, although there are substantial differences between these according to some people, when we say any of them we mean one thing….an organism that transforms coffee into code 🙂 so I will continue with the term “Developer” and I wouldn’t like to go into that discussion right now because it can turn out to become a book.

We have come a long way from being the “basement” nerds, that nobody wants to talk to, to the modern day mixed media served image of super-rich-enterpreneur-programmer(which is sadly just a few lucky ones). So where is the truth? What are we, where are we? How do we manage to form a picture of ourselves and waht we want to accomplish in todays diversity of technologies and approaches to software development?

I know it maybe not much. But, having been there for quite a while both as amateur since I was a little kid typing random programs in Basic on my Commodore 64 back in the 90’s, then professionally since 2005, all the way until today. I will try to share my view and experiences of what I consider the most important values of a modern day developer by answering dozen of questions.

So, here we go.

Continue reading “The Story of the Modern Day Developer”

The Story of the Modern Day Developer

Sql Server: datetime vs datetime2 recap

The MSDN documentation for datetime recommends using datetime2.

datetime2 has larger date range, a larger default fractional precision, and optional user-specified precision. Also depending on the user-specified precision it may use less storage.

Furthermore, datetime2 has a date range of “0001 / 01 / 01” through “9999 / 12 / 31” while the datetime type only supports year 1753-9999. If your need is precesion, datetime2 can be more precise in terms of time; datetime is limited to 3 1/3 milliseconds, while datetime2 can be accurate down to 100ns.

Both types map to System.DateTime in .NET – no difference there.

Sql Server: datetime vs datetime2 recap

Get all stored procedures related to a table

To get all stored procedures related to a table:

Option 1:

 SELECT DISTINCT so.name  
 FROM syscomments sc  
 INNER JOIN sysobjects so ON sc.id=so.id  
 WHERE sc.TEXT LIKE '%tablename%'  

Option2:

 SELECT DISTINCT o.name, o.xtype  
 FROM syscomments c  
 INNER JOIN sysobjects o ON c.id=o.id  
 WHERE c.TEXT LIKE '%tablename%'  
Get all stored procedures related to a table

Sql Server: Delete duplicate rows with CTE

Here’s a code snippet to remove duplicate rows in a table:

 WITH CTE (Column1, Column2, DuplicateCount)  
 AS  
 (  
 SELECT Column1,Column2,  
 ROW_NUMBER() OVER(PARTITION BY Column1,Column2 ORDER BY Column1) AS DuplicateCount  
 FROM TheTable  
 )  
 DELETE  
 FROM CTE  
 WHERE DuplicateCount > 1  
 GO  

More on Common Table Expressions(CTE) can be found here:

http://msdn.microsoft.com/en-us/library/ms190766(v=sql.105).aspx

Sql Server: Delete duplicate rows with CTE

Filtering duplicates out of an IEnumerable

Problem: Filtering out(removing duplicates) from an IEnumerable

One possible solution with using linq would be to group by key and take the first element of each group. Here’s an example:

enumerable.GroupBy(x => x.key).Select(g => g.First())
Filtering duplicates out of an IEnumerable