Wednesday, December 05, 2007
http://www.aspfaqs.com/webtech/042606-1.shtml

One of the best (not to mention easiest) paging methods I've seen.  In fact it requires no temp tables or table variables. 

Paging is something that is so common yet seems to hard to get right and keep performant that it pays to have a nice easy template to start from.  I've posted this mainly for my own benefit so I have a permanant bookmark to this code.

The example uses a stored procedure, but its important to understand that a stored procedure is not required to make this work.

Here's the code:

CREATE PROCEDURE [dbo].[usp_PageResults_NAI]

(
@startRowIndex int,
@maximumRows int
)
AS

DECLARE @first_id int, @startRow int
    
-- A check can be added to make sure @startRowIndex isn't > count(1)
-- from employees before doing any actual work unless it is guaranteed
-- the caller won't do that

-- Get the first employeeID for our page of records
SET ROWCOUNT @startRowIndex
SELECT @first_id = employeeID FROM employees ORDER BY employeeid

-- Now, set the row count to MaximumRows and get
-- all records >= @first_id
SET ROWCOUNT @maximumRows

SELECT e.*, d.name as DepartmentName
FROM employees e
INNER JOIN Departments D ON
e.DepartmentID = d.DepartmentID
WHERE employeeid >= @first_id
ORDER BY e.EmployeeID

SET ROWCOUNT 0

GO






 |  | 
Wednesday, December 05, 2007 2:43:40 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Saturday, November 24, 2007

In my previous post about what people use computers for, I stated that computers are for saving state.  Duh.  I felt I needed to make that clear to myself as I explored functional programming languages like Erlang, F# and Scheme.  State seems to be a dirty word relegated to second class citizenry in a functional world.

I think that functional language have an uphill battle for mainstream acceptance.  A bit bolder, I think they are a small niche and always will be a small niche.  In fairness, I think most of literature on functional languages portray them as a special purpose languages.  As the saying goes, the right tool for the job.  Microsoft is looking for F# developers to write driver validation software. 

My goal is to find languages that are applicable to general purpose problems.  I'm not a mathematician and I don't need so solve theorems.  Most of the programming jobs I've completed involved storing and manipulating some shared stated, a database.

Yet another realization courtesy of a man seeking to explain the failure of the best language on earth

Local state in programming is just like scratch paper for mathematics.  Some rare gifted individuals don't need it and can do the calculus in their head.  For the rest of us scratch paper and number two pencils are the only alternative.

While debugging, I can inspect the state of the system, either with the debugging facilities or with well placed print statements. 

So local state helps us understand our systems.  Global state, again databases, are the reason our systems exist.  Some in the Erlang camp want to wish this away.  However, I think Erlang advocates understand that Erlang was built for telecom switches.  Erlang's usefulness in general purpose programming is yet to be determined.  If you're building a system that manipulates global shared state (most of the web applications in existence), choosing a language that waves its hands at shared state in the name of concurrency might not be your best choice.

Now we come to the revelation stage of our journey.  What can we do in mainstream languages to deal with global  shared state (databases) effectively?  I've found something in my own development work that is effective for me.  It's not a new language, but in fact, works in many languages, including C# and Python.

My solution may not be a silver bullet, but then I might not be hunting werewolves.  I can't claim to have invented it.  For from it.  All I can claim is that I've seen this pattern work across languages.  I can also tell you that it might be a wooden stake, useful if you are hunting vampires.

 

Saturday, November 24, 2007 10:16:25 AM (Central Standard Time, UTC-06:00)  #    Comments [2]
 Friday, November 23, 2007

For a (brief) while, I was learning F#.  It proved an interesting excursion.  If you into mathematical correctness F# and OCaml maybe just the languages for you.  Myself?  Well I'm looking for something with a little more to offer in the functionality department.  I want a language where I can do most anything.  I'm willing to sacrifice mathematical niceties.

Python seems to be that language.  Python is one of the languages I knew I would love when I tried it, so I've held off diving into it until I had gone through almost every other one.  I've journeyed through Lisp, Scheme, C++, C#, Java, Ruby, F#/OCaml and dabbled in a few less known like Factor and Cat. 

Python Advantages:

  • Available and almost every platform (every platform I'm interested in)
  • Terse clear syntax
  • Whitespace (yes, I do enjoy the whitespace!)
  • Easy to learn, easy to teach (I taught C++ to undergrads during my time in Hell)
  • More complete than Ruby
  • Better documented than Ruby
  • Good riddance to the Edit/Compile/Wait/Debug loop (hello Edit/Test, Edit/Test, Edit/Test...)
  • Python is available on the CLR as Iron Python and on Java as Jython.

Disadvantages

  • It's not C# (heh)
  • It's not Java (heh, heh)
  • Performance (slower than the above)

I believe that Gabriel is correct and that worse is better.  Worse as in Python is not Lisp.  Even Dr Norvig, chief brain in a jar at Google, thinks Python is good for something.

Note that Python is one of the four languages in use at Google.  Google has, in fact, hired the Frost Giant.

Python is used in game scripting.  My favorite game series of all time uses Python as the scripting engine.

I've also found one of the best Web Frameworks to date to use with Python.  I'll detail that it a future post. 

Right now Project X is moving forward on rockets fueled by Python.  This is the most complete proof of concept I've completed in an alternate language (not C#) and I'm LOVING it.

 

Friday, November 23, 2007 9:59:18 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Tuesday, October 30, 2007
This is an interesting article from the 1920's written by a proprietor of a grocery supply business.  What the author considers brilliant may not fit the definition that many of us have.  I think a better term would be "schemer" or "dreamer" or something similar.  Anyway my main interest in the article is based on my assertion that many in the software profession are "brilliant." 

I myself find it hard to finish projects but easy to start them.  If you believe in personality tests than I am an INTP.  This means I have a tendency to live in my head.  I need to constantly fight to finish things and to stay interested in projects.  I'm always exploring new languages and technologies.  This is both a boon and a burden in the technology field.  I'm usually up to date on the latest technology but I have to push myself to finish projects that become a little too mundane.  I also read many articles from programming.reddit.com and similar sources.  If I'm not careful I can consume a whole night or day reading such articles.  The plus side is that I'm a sponge for information.  The negative is that I may have a hard time applying it as I'm always trying something new.

I believe that we must understand ourselves to be successful.  I am aware of my weaknesses and by my awareness I am able to realize what I must work on to be successful.  I must force myself to complete current projects and to apply my research.  When I am able to do this I can produce results that are amazing.  However, I always have the potential to waste days and nights reading.  However, it may be debatable whether reading is really ever a waste.  I watch very little television as I prefer to read and program instead.

In my opinion, this article can be summed up as "find hard workers."  Not brilliant by any means but a good read none the less.

Article:  Why I Never Hire Brilliant Men

Tuesday, October 30, 2007 9:26:17 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Friday, October 19, 2007
Nullables always felt not quite done.

Here is a technique to add an extra minute to the microwave timer and get a more fully compatible conversion function:

http://blog.pumacode.org/2006/05/18/using-convert-changetype-on-nullable-types/

Nullable types are awesome for dealing with databases.  Its a fact of life that most databases are going to use null and you need to deal with it in your code.  However what does null map to for a value type? 

The answer is unknown.  If C# were truly object oriented then wouldn't value types be reference types instead.  I'm guessing there are some big performance implications to this.  So we have nullable types.  A solution that is almost ready for prime time. 

Side Note:  If you truly wanted a consitent web front end for a database then null would map all the way through to things like dropdownlists where they would map to the default "please choose" option.  This would be an awesome rails like feature.  I'll have to do that when I get around to building my own web framework.

That's not likely to happen anytime soon.  I actually built server controls that did the above.  However, the overhead of maintaing server controls and making them behave just like regular built in server controls is just too much of a burden at this point.  I'll have to revisit this at some point.

Friday, October 19, 2007 10:28:47 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
The one thing that irks me about compiled code is the compilation tax.  It takes a while to re compile everything even if there is only a small change in a page or class.

Here are some tips to reduce those build times.

http://weblogs.asp.net/bradleyb/archive/2005/12/06/432441.aspx


I have to say that it certainly seems faster after I've used these tips.

One improvement I have made is to not debug using Visual Studio.  I simply start app and stop it right away.  I then just browse to my web site with another browser instance and test that way.  The development web server will just sit there running and serving up content. 

I find this way that I use logging much more than debugging.  Of course, there are some problems where debugging just can't be beat but those instances are few and far between. 

This method works really once especially if you have seperate assemblies for each page/folder.

I find that I only build the whole site if I make signifigant structural changes to the site like renaming classes. 

In the end, faster edit, test, debug cycles are what we are after.  We want the advantages of a dynamic language without the penalites. 

Friday, October 19, 2007 2:24:38 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Wednesday, October 17, 2007
Michael Feathers asks if syntax is important.

I think the answer is maybe.  Certainly a language with a familiar syntax will allow you to pick it up faster if you have already learned a language with similar syntax.  For example, I found Java very easy to understand since I had a background in C#.  

Of course, there are the countless winers who complain about lisp's syntax or lack thereof. 

One tricky point is syntax that is legal in one language but not so in another.  I constantly found myself typing foreach in java just to be kicked in the head by the compiler.

I think syntax really matters for the first month or so of learning a new language.  Once you get beyond that you are able to "think" in the new language and your ideas start showing up in your new language.

Wednesday, October 17, 2007 12:35:21 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Monday, October 15, 2007
Technically its more like a few hours spread over a week but so for so good.  I've come to begin to understand functional concepts.  Currying and partial application now seem to be rather easy to understand but hard to explain to someone else. 

However, what I really love is not necessarily the functional aspects, rather the terseness of the language.  I especially like type inference.  I'm not sure why we couldn't have had that sooner in C#.  In languages like C# you expect an IDE to be present so it works really well in situations where you have a toolset to back you up.  It also works really well in scripting languages (Ruby, Python, etc).  However, with F# (and OCaml) you get the benefits of strong static typing with the benefits of less typing.  I really like it.

It seems that many concepts are just simpler in F# rather than C#.  I also see cases where it is easier to define a smaller single use type (like when you query a small set of data from a database) than to declare a full blown class.  I think many times I've found it a pain to create a whole class when I really don't need to reuse it.

Again, these are just first impressions.  Things may change as I get farther into the tutorials and learning processes.  I find F#/OCaml very easy to learn.  As I was working on Scheme/Lisp it syntax always felt alien.  I was learning a lot but it didn't fell quite right.  F# just seems to feel good.  Probably because it is close to C# in some ways.

I really need to get into a small project with it to see if I really like it.  Once I have a real world application under my belt I can usually tell if I'm going to keep a language in my toolbelt or put it back on the shelf for another time.

I also think I have a solution for the ASP.NET development.  I'm going to use ASP.NET without ASP.NET...  (I'll explain more in the future, but if you read some of my previous posts, you can probably figure out what I'm going to use.)

Monday, October 15, 2007 7:39:46 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Friday, October 12, 2007

ProMesh is too immature at this point to complete the project I am working on. I think given a few weeks or months this framework will be top notch.

Right now however I am constantly getting the latest version to get around some bug only to discover another bug. I don't want to come across as negative about ProMesh.Net, again I think it will be one of the best frameworks out there once its matured a bit.

-- Update --
Again, to make it clear I think ProMesh is a good framework.  I have released a small project with it and it workds great.  My problems are with the validation scheme that changed and a looming deadline.  I am still using it for other projects.  My rants below are about me screwing around too much and finding myself short on time and having to use WebForms.
-- End Update --

Back to the present, I need to get work done. I have spent a little too much time playing with ProMesh and some various other languages and frameworks. I neeed to get some work done. So I'm back to ASP.NET WebForms.

It's telling how poor WebForms are as I can barely get a simple form working correctly. Control postbacks and the whole business is absolutely frustrating. I want to make a form that changes which controls are displayed based on the value in a drop down box. Simple right? Wrong. I'm once again battling the stupid page lifecycle. Is this really the best we have?

I'm looking forward to seeing Microsoft's MVC for ASP.NET. I hope that takes .NET web development in the right direction.

Many people compare WebForms to WinForms. Something about WEbForms being VB6 on the web. Well I can tell you VB6 was never this unecessarily complicated. Good grief.

I think it's a bad sign when you spend 80 percent of your development time working around your framework instead of with it.

Friday, October 12, 2007 1:02:04 PM (Central Standard Time, UTC-06:00)  #    Comments [0]

My latest language is F#. After considering PLT Scheme for my latest side project I thought I should do some more investigation first. I had briefly considered Factor. While Factor is coming along quite well, It's not quite ready for prime time.

I remember looking at Ocaml because of the speed and type safety of the language. However I was initially turned off by the syntax. I then moved onto Python. I think Python's syntax is clean but I miss compile time checking for errors.

So after seeing another post on F# on Reddit, I decided to check it out. At this point it all come back to me. F# has a Visual Studio plug in. You get intellisense and all kinds of nice features. There is even a top level REPL (Read Eval Print Loop) that lets you test out code very easily. I had decided against Boo because it lacked Visual Studio support and #Develop doesn't quite do it.

I dug into a few Ocaml tutorials (yes, these work very well for F#). I soon found myself loving the language as I began to understand the power that these ML derivatives have. All I can say is wow.

F# lets me use the years of built up C# libraries and expertise I have, yet also write powerful and elegant code. I do say I like the syntax quite a bit better than Scheme. I hate typing all those () as they tend to make your fingers hurt:-)

Now I just need to figure out the web story for F#. It appears that you can use it with ASP.NET but I need to do some more research.

Friday, October 12, 2007 12:50:03 PM (Central Standard Time, UTC-06:00)  #    Comments [1]
 Thursday, October 11, 2007

Everytime I try a new language or technology I eveluate it based on what it can do for me. Will it make more productive or will it teach me something. I'm not a big believer that learning language X will make you a better programmer in language Y. I think there is some truth in that but not as much as some would lead you to believe.

Above all else, I look for pragmatic solutions. What can technology do for me? I think Ruby on Rails is a decent example of pragmatic software. It has its flaws but in the right scenerio I think its a very practical solution.

So when I go down the rabbit hole with some new language/platform, etc, I'm looking for benefits. I know what C# and ASP.NET can do for me. I've used them long enough to know the ups and downs and i'm constantly looking for ways around those low points. ASP.NET webforms is a great example. I hate using them. In anything but the most simple situations, they break. They "leak" in that they are not the best way to abstract the web. They represent the underlying web server event cycle more then anything. And they are painful to use.

I've looked at Boo, Nemerle, F#, IronPython, L#, Cat and probably some that I can't remember JUST in the .NET realm. This doesn't include my research into Lisp, Scheme, Scala, Factor, Ruby, etc. These .NET technologies have other benefits like cross platform abilities that make them attractive. With the .NET languages/tech, I'm looking for ways to solve or alleviate my C#/ASP.NET pain.

Boo seems to be a good language. It lacks good Visual Studio support though. This means I lose productivity to gain a cool language.

IronPython has a sweet spot in scripts and possibly web pages. I like the quick turnaround of editing a script and seeing the results without the long compile time.

On the framework/library front there is ProMesh.NET and MVC framework that replaces WebForms. It's pretty good but it still has some bugs. There is also MonoRail but I haven't gotten the courage and the time to test it out. It looks massive and I don't really get Inversion of Control and Dependency Injection yet. However, they sound odd and a bit scary. Do I really need them just to have a decent web framework? I don't need these in PHP.

A solid win on the ORM front is CoolStorage.NET. This thing blows the doors off of anything else I've used bar none. It is the optimal combination of light weight yet powerful features. I think CoolStorage wins by being a C# first project. It is not a clone of a Java project. CoolStorage takes advangtage of attributes and generics to produce a terribly productive product.

So with one win and so many that qualify as so close yet so far, what is a practical programmer supposed to do? The only thing I can do is spend hours testing out new languages and frameworks to see if there is anything out there. At least at the end of the day, if I don't find anything, I know that C# is king and I'm not left wondering.

So I must continue my crusade for the best even though most days its a big pain. I've recently found F# and it looks very nice. Visual Studio support, a real REPL and syntax and conciseness like a scripting language yet with a typing system more powerful than the one in C#.

So yes, these little discoveries are worth all the pain of downloading, installing, and compiling countless new programs. I can put my mind at ease and keep up on the latest developments. In the end there is something to be said for intellectual stimulation and if there is practical use then all the better.

Thursday, October 11, 2007 8:49:30 PM (Central Standard Time, UTC-06:00)  #    Comments [0]