I just read a blog post by Rocky Lhotka where he discusses where to put the validation logic. This interests me quite a bit because it's one of those caveats I've found around ASP.NET and web development in general.
The problem with validation in a web environment
In web projects you often want validation to take place on the client (to reduce the number of post backs and give a better user experience), but it's not an environment you can trust.
How not to do validation
For obvious reasons, as stated above, you should not exclusively put validation on the client.
One way of solving it
I would agree with Rocky Lhotka that you should put validation in the business layer to begin with, and then duplicate that to the frontend to give the user a better experience. The main point here is that the business layer will be the deciding factor what gets though no matter if the UI validation isn't working as it's intended to.
Preparing for the future
Another important point Rocky touches on is that the UI is more frequently replaced than the business layer code, which gives some value to having the validation there no matter if it's implemented in the UI.
Security
One good rule I've come across is that you should treat everything coming from the user as potentially dangerous, and even better, do the same for anything that comes from the database. With this in mind, putting at least the critical validation in the business layer seems like a good idea.
Patterns and practices?
I'm looking into ways of building robust applications by using the MVP pattern (supervising controller) and TDD. I'll probably write more about that when I've gotten a bit more experience on the subject.
Saturday, April 21, 2007
Thursday, April 5, 2007
Weeks of .NET
This last month have been spent coding in .NET (mostly VB.NET) at my full time practice at Avancit AB. I thought I would share a few things I've come across in the projects I've been working on during that time.
T-SQL
I had a problem where I needed to get all mail addresses of all groups in a company except those in the current group. This was solved by the SP shown below:
BCP versus SqlBulkCopy
Another problem was where we had an application that needed to push tables from a client to a server effectively. The current version at the time used BCP which was run from a batch process and sometimes (but very rarely) failed.
I started to look around and I found that people where replacing BCP with SQLBulkLoad. I suggested we'd try it and we successfully implemented the transfer using it. As the whole process now took place inside the .NET application it was simple to setup a better error handling than was possible with BCP.
Macros
As for productivity, I've started to look into using macros in VS2005. The first macro I installed was one that reversed assignments. I know there are tools that do this, I think ReSharper has this ability, but I don't have it yet so a macro works just as good. You can find this macro at: http://www.codeproject.com/useritems/macroswapassignments.asp
DNR
Anyone still not listening to DotNetRocks are missing some great stuff. As I'm on a train or a bus for 3 hours a day I've listened to quite a few episodes in the last few weeks (1 to 40). Even the early episodes are great, they give a good insight into why things are the way they are and what is new in .NET 2.0 (as I started with 2.0, I don't have much of a reference as to the differences compared to 1.1).
TDD
Next week we're starting a project that will use TDD (Test Driven Development) for the first time within Avancit. It will be lots of fun and I'll probably write how that goes here later.
T-SQL
I had a problem where I needed to get all mail addresses of all groups in a company except those in the current group. This was solved by the SP shown below:
ALTER PROCEDURE [dbo].[sp_GetMailAddressesByCompany]
(
@intCompID INT,
@excludeGroupID INT
)
AS
BEGIN
— Get all addresses in company that are NOT in the excluded group
SELECT addr.* FROM tblMailAddresses addr
INNER JOIN tblMailGroupsToAddresses con
ON con.intMailAddressID = addr.intMailAddressID
WHERE addr.intCompID = @intCompID
AND addr.intMailAddressID NOT IN
(
— Get all addresses in the excluded group
SELECT addr.intMailAddressID FROM tblMailAddresses addr
JOIN tblMailGroupsToAddresses con
ON con.intMailAddressID = addr.intMailAddressID
WHERE con.intMailGroupID = @excludeGroupID
)
END
BCP versus SqlBulkCopy
Another problem was where we had an application that needed to push tables from a client to a server effectively. The current version at the time used BCP which was run from a batch process and sometimes (but very rarely) failed.
I started to look around and I found that people where replacing BCP with SQLBulkLoad. I suggested we'd try it and we successfully implemented the transfer using it. As the whole process now took place inside the .NET application it was simple to setup a better error handling than was possible with BCP.
Macros
As for productivity, I've started to look into using macros in VS2005. The first macro I installed was one that reversed assignments. I know there are tools that do this, I think ReSharper has this ability, but I don't have it yet so a macro works just as good. You can find this macro at: http://www.codeproject.com/useritems/macroswapassignments.asp
DNR
Anyone still not listening to DotNetRocks are missing some great stuff. As I'm on a train or a bus for 3 hours a day I've listened to quite a few episodes in the last few weeks (1 to 40). Even the early episodes are great, they give a good insight into why things are the way they are and what is new in .NET 2.0 (as I started with 2.0, I don't have much of a reference as to the differences compared to 1.1).
TDD
Next week we're starting a project that will use TDD (Test Driven Development) for the first time within Avancit. It will be lots of fun and I'll probably write how that goes here later.
Wednesday, February 28, 2007
As a student...
As a student I've got a problem... there is just so much information out there.
You know when you have a fair bit of knowledge about a topic but there are several big gaps missing? I've encountered this while I worked on a CakePHP site where I often had to search in the documentation as I couldn't get myself to read the entire thing to begin with.
To solve this I started up a new tiddler in my TiddlyWiki where I wrote down the sections in the manual. Then I began skimming though the manual and noted every potentially useful bit of information. There is nothing incredibly new about this study technique, but it works for me. This approach of course requires that you have a project in mind.
What I really would like is some way to attach little notes to places in texts and podcasts, and have them indexed, labeled and searchable. Maybe there is such a thing, a Firefox plugin perhaps?
On a side note I've been working on a few projects, including a CakePHP site and a couple of ASP.NET/C#/VB.NET sites. Also been using my TiddlyWiki a lot, it has even replaced the need for FreeMind to some degree as it is searchable, indexable, has labels and can take really long and formatted texts :)
You know when you have a fair bit of knowledge about a topic but there are several big gaps missing? I've encountered this while I worked on a CakePHP site where I often had to search in the documentation as I couldn't get myself to read the entire thing to begin with.
To solve this I started up a new tiddler in my TiddlyWiki where I wrote down the sections in the manual. Then I began skimming though the manual and noted every potentially useful bit of information. There is nothing incredibly new about this study technique, but it works for me. This approach of course requires that you have a project in mind.
What I really would like is some way to attach little notes to places in texts and podcasts, and have them indexed, labeled and searchable. Maybe there is such a thing, a Firefox plugin perhaps?
On a side note I've been working on a few projects, including a CakePHP site and a couple of ASP.NET/C#/VB.NET sites. Also been using my TiddlyWiki a lot, it has even replaced the need for FreeMind to some degree as it is searchable, indexable, has labels and can take really long and formatted texts :)
Saturday, January 13, 2007
Keeping track
TiddlyWiki - Wiki in a single .html file that stores info into itself and runs on basically anything. It uses a very nice Web2.0'ish interface. I replaced my remaining text files with a TiddlyWiki today.
Worth mentioning twice, Freemind - Great mind-mapping software. I use it for keeping track of projects, classes, assignments, todos...
On the web
As for web resources, I'd say gmail got email just right. Used it for years and never felt like switching to anything else. I also use the google calendar, reader and of course blogger.
As for self-improvement I've been trying Joe's goals for a little while.
Worth mentioning twice, Freemind - Great mind-mapping software. I use it for keeping track of projects, classes, assignments, todos...
On the web
As for web resources, I'd say gmail got email just right. Used it for years and never felt like switching to anything else. I also use the google calendar, reader and of course blogger.
As for self-improvement I've been trying Joe's goals for a little while.
Monday, January 8, 2007
Books...
Books... seems there is no end to the books you absolutely need to read when you're attempting to be a decent developer. In my random browsing trough the web I stumbled upon "Five more books for developers" which is not a list of computer books as you might expect, instead it's a list of books that a developer might want to read anyway. I really like the neat twist at the end of the blog post. I'd recommend any sci-fi addict to read Peter F Hamilton's works (especially the Commonwealth Saga (2002-2005)).
Monday, December 25, 2006
Eclipse with PHP and Java
I have been using Eclipse for some time now and it's the first IDE that I can compare to Visual Studio 2005. In some respects I'd say it's better than VS, but then I use them for different languages. I like the fact that Eclipse is multi-platform and free (as in open source).
Pluggabe!
One of the best things about Eclipse is that it is easily pluggable and has as a result lots of great plug-ins. I've been using the EasyEclipse Expert Java distribution with some of the EasyEclipse plug-ins, one of which is PHP Eclipse.
Slow?
I've heard some people speak of not using Eclipse because it's Java and "Slow". Now I don't have a fast computer (laptops are expensive things), but I'd have to say Eclipse is very responsive, way more so than VS.
Java and Eclipse
I found one site that is great for beginners of both Eclipse and Java. Dave Powell at Elon University has created a great video tutorial on everything from setting up Eclipse, debugging and GUI programming to unit testing in Java using Eclipse.
Experience with CakePHP and Eclipse
CakePHP is a rapid application development toolkit for PHP centered around the Model-View-Controller pattern. I've found it by way of searching for a PHP alternative to Ruby-On-Rails (as rails hosting is still harder to come by).
Maybe I just don't know how, but I could not seem to make Eclipse use the correct coloring or syntax-helpers with the default .thtml view file suffix. I've solved this for now by using .phtml and in the controller set $this->ext = '.phtml';. After that Eclipse has been very comfortable to work with.
Im using EasyPHP as my LAMP server.
Pluggabe!
One of the best things about Eclipse is that it is easily pluggable and has as a result lots of great plug-ins. I've been using the EasyEclipse Expert Java distribution with some of the EasyEclipse plug-ins, one of which is PHP Eclipse.
Slow?
I've heard some people speak of not using Eclipse because it's Java and "Slow". Now I don't have a fast computer (laptops are expensive things), but I'd have to say Eclipse is very responsive, way more so than VS.
Java and Eclipse
I found one site that is great for beginners of both Eclipse and Java. Dave Powell at Elon University has created a great video tutorial on everything from setting up Eclipse, debugging and GUI programming to unit testing in Java using Eclipse.
Experience with CakePHP and Eclipse
CakePHP is a rapid application development toolkit for PHP centered around the Model-View-Controller pattern. I've found it by way of searching for a PHP alternative to Ruby-On-Rails (as rails hosting is still harder to come by).
Maybe I just don't know how, but I could not seem to make Eclipse use the correct coloring or syntax-helpers with the default .thtml view file suffix. I've solved this for now by using .phtml and in the controller set $this->ext = '.phtml';. After that Eclipse has been very comfortable to work with.
Im using EasyPHP as my LAMP server.
Saturday, December 9, 2006
.NET game-related frameworks
Last Thursday I was at the first "Game Developers Evening" at KTH/Stockholm listening to a speech about XNA by Johan Lindfors.
This will be the first of a series of GDE's, hosted by various game development companies during the next year (have not found the schedule).
I will sum up some of the points of the XNA speech below.
One benefit of XNA could be said to be that you can develop games for both the PC (Windows) and the XBOX360. You have to have different projects for the XBOX360 and PC game but they claim that you can reuse 95% of your code.
Another benefit could be that it has a component structure that you can use to share game components, like an in-game browser or a special camera orientation.
As for using XNA to build games for the XBox360 you have to pay a subscription fee of $49 or $99 (4 months or a year I think) to get access to the runtime used. In the first release you would not have any way of distributing your games to others except by source to others that subscribe as developers on Live. Also you can't use networking in your game and subsequently the only option for more than one player is a split screen game.
At this point XNA uses DirectX 9, I'm not shure if this is supposed to change with a later release.
I think I will take this opportunity to mention about other .NET game related frameworks, namely BooGame and Axiom.
BooGame is a 2D-Game framework that is very similar to XNA in how you build the game, in other words, inherit from a base class, let BooGame run the game loop and have events or overrides tell you when to update or draw. The clear benefit of using BooGame is that you get a multi platform application. Also it never hurts to support an open source initiative. It uses OpenGL to render the 2D game which makes it very fast. I have not tried to use it with emulated OpenGL, but I guess that would work too.
I use BooGame for my NetPlanes game.
As for Axiom it's a 3D engine (not a game-engine like BooGame). It's a port of Ogre, a very good C++ 3D engine. There are a couple of wrappers for Ogre to use it with .NET programs. I have not personally decided what the best method is, Axiom isn't as mature as Ogre but the wrappers have some problems too.
My contribution to Axiom thus far is porting the first basic tutorial and writing a base code (inspired by that of Ogre) to use (inherit from) in examples.
This will be the first of a series of GDE's, hosted by various game development companies during the next year (have not found the schedule).
I will sum up some of the points of the XNA speech below.
One benefit of XNA could be said to be that you can develop games for both the PC (Windows) and the XBOX360. You have to have different projects for the XBOX360 and PC game but they claim that you can reuse 95% of your code.
Another benefit could be that it has a component structure that you can use to share game components, like an in-game browser or a special camera orientation.
As for using XNA to build games for the XBox360 you have to pay a subscription fee of $49 or $99 (4 months or a year I think) to get access to the runtime used. In the first release you would not have any way of distributing your games to others except by source to others that subscribe as developers on Live. Also you can't use networking in your game and subsequently the only option for more than one player is a split screen game.
At this point XNA uses DirectX 9, I'm not shure if this is supposed to change with a later release.
I think I will take this opportunity to mention about other .NET game related frameworks, namely BooGame and Axiom.
BooGame is a 2D-Game framework that is very similar to XNA in how you build the game, in other words, inherit from a base class, let BooGame run the game loop and have events or overrides tell you when to update or draw. The clear benefit of using BooGame is that you get a multi platform application. Also it never hurts to support an open source initiative. It uses OpenGL to render the 2D game which makes it very fast. I have not tried to use it with emulated OpenGL, but I guess that would work too.
I use BooGame for my NetPlanes game.
As for Axiom it's a 3D engine (not a game-engine like BooGame). It's a port of Ogre, a very good C++ 3D engine. There are a couple of wrappers for Ogre to use it with .NET programs. I have not personally decided what the best method is, Axiom isn't as mature as Ogre but the wrappers have some problems too.
My contribution to Axiom thus far is porting the first basic tutorial and writing a base code (inspired by that of Ogre) to use (inherit from) in examples.
Subscribe to:
Posts (Atom)