Archive for the ‘Learning notes’ Category

To “refresh” a SqlDataSource.

Sunday, July 27th, 2008

I am trying to “refresh” a SqlDataSource in a postback action.  The basic idea is, user change some setting (which passed as paramters to the SqlDataSource) and need to “refresh” the query result. I was though to call some method in SqlDataSource but eventually I found the simplest way (maybe not that efficient) is call the object who have databinding with SqlDataSource’s DataBin() again.

e.g.

protected void Button1_Click(object sender, EventArgs e)
{
RadChart1.DataBind();
}

asp:ControlParameter vs asp:FormParameter

Sunday, July 27th, 2008

I got stucked on ASP.Net’s SqlDataSource’s parameters for quite a long time.  The problem is I am always trying to use aspFormParamter in a postback, there are quite a few samples in the Internet, but most of them are simple aspx page without masterpage. In my project I used masterpage, it looks like for some reason it doesn’t work well.

Fortunately, after I changed to asp:ControlParameter, it works great.

output a line in a batch *without* crlf

Saturday, July 5th, 2008

Learned from here: Progressive Dots, this is a MSFTer who developing LiveMesh.

set /p CRLF=.<NUL

try this in command window, you will get a ”." output.  "set /p" is used for get a input with a specified prompt, "<NUL" make it return immediately, so "set /p CRLP=.<NUL" generate a dot without carriage return.

It’s a good trick, but as always, I hate .BAT files…

Write code with no getters???

Tuesday, June 17th, 2008

One of my friends shared a blog post to me, at first it looks like quite a good practice, however after I read and think over I feel I am quite disagree with this guy. It’s a quite interesting debate, I am wondering if you guys like it or have your opinions.

In this blog (http://michaelfeathers.typepad.com/michael_feathers_blog/2008/06/the-flawed-theo.html ), someone tell a story that write code without setter will have great benefit for TDD:

“John Nolan, gave his developers a challenge: write OO code with no getters. Whenever possible, tell another object to do something rather than ask. In the process of doing this, they noticed that their code became supple and easy to change. They also noticed that the fake objects that they were writing were highly repetitive, so they came up with the idea of a mocking framework that would allow them to set expectations on objects - mock objects.”

Someone(http://peripateticaxiom.blogspot.com/2008/06/tdd-mocks-and-design.html ) extended his idea and provided a code sample:

“Suppose that we want to print a value that some object can provide. Rather than writing something like statement.append(account.getTransactions()) instead we would write something more like account.appendTransactionTo(statement) We can test this easily by passing in a mocked statement that expects to have a call like append(transaction) made. Code written this way does turn out to be more flexible, easier to maintain and also, I submit, easier to read and understand. (Partly because) This style lends itself well to the use of Intention Revealing Names.”

Those idea looks great at the first sight, but at least for me I complete can’t agree with the second guy, I feel what he *suggested* is what I will *avoid*. Maybe he just gave a bad sample, however from his blog’s long debate it looks like he is quite confident with his idea.

Reference reading:

Getter/Setter debate: http://moffdub.wordpress.com/2008/06/16/the-getter-setter-debate/

Getter Eradicator: http://martinfowler.com/bliki/GetterEradicator.html

Why getter/setter are evil: http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html

Doing it wrong: getters & setters: http://typicalprogrammer.com/?p=23

I would like to hear your opinions….

Dump SQL Server Express’ DB Schema

Wednesday, June 4th, 2008

I am quite feeling lost since SQL Server 2005, SQL Server Express don’t come with the "Enterprise manager" any more… I used to do many stuff under that Enterprise manager for SQL Server 2000 before.

One simple task I need to do is dump my database schema and transfer to another server, I can easily do that before in Enterprise manager, now I don’t even know hot to dump and generate the SQL statement… fortunately I found this tool:

http://www.codeplex.com/sqlhost

Database Publishing Wizard

Download the Current Release (1.1)

Localized versions of 1.1

The Database Publishing Wizard enables the deployment of SQL Server 2005 databases (both schema and data) into a shared hosting environment on either a SQL Server 2000 or 2005 server.
The tool supports two modes of deployment:

  1. It generates a single SQL script file which can be used to recreate a database when the only connectivity to a server is through a web-based control panel with a script execution window.
  2. It connects to a web service provided by your hoster and directly creates objects on a specified hosted database

The Database Publishing Wizard provide both a graphical and a command-line interface. In addition, it can integrate directly into Visual Studio 2005 or Visual Web Developer 2005.

My suggestions on Web2py’s route design

Tuesday, June 3rd, 2008

Learning web2py, it’s an excellent yet young python web framework, I just wrote a few suggestions in the dev group: (route to controllers- Some idea may take from ASP.NET MVC’s design)

I am learning web2py and very new to Python, so I could be wrong or I am not yet understand Massimo Di Pierro’s principles, just some opinions for discuss. 

Looks like the URL rules  /[applicaiton]/[controller]/[function]  is hard coded, I saw the code in main.py (lines near 140) :

            request.application=items[0]
            request.controller=items[1]
            request.function=items[2]

And also I found /static/… is hard coded as well.

Yes, with rewrite.py(route.py), we can rewrite any URL in this format and rewrite any this kind of URL to whatever we want. However there maybe some design which could be more flexible and yet keep CoC in good shape.

Look at the latest Microsoft ASP.NET MVC (now in preview 3, you can read this blog http://weblogs.asp.net/scottgu/archive/2008/05/27/asp-net-mvc-preview-3-release.aspx to get some general idea), it also have a route mapping mechanism, you can write your rule to define which part means "controller" which part means "action", if you read the blog post I give, in the end part it introduced the route.

Something interesting is, that new added route part is NOT a part of ASP.NET MVC framework, it’s actually useful for some other senarios, e.g. new release ASP.NET dynamic data applications(ASP.NET’s answer to scaffold)

My points is, a more flexible routing mechanism could make the architect looks better and more flexible and you won’t need to give up the compatibility and CoC principle.

ASP.NET MVC’s design learned a lot from Ruby On Rails, actually RoR’s route design is also quite flexible (refere to http://manuals.rubyonrails.com/read/chapter/65)

Good comparing of GAE Data Store .vs. Amazon Simple DB .vs. MS SSDS

Monday, June 2nd, 2008

Found a good comparing paper on:

Comparing Google App Engine, Amazon SimpleDB and Microsoft SQL Server Data Services

Very good articles on MVC, MVP and more.

Saturday, May 31st, 2008

Very good articles on MVC, MVP and more.

Interactive Application Architecture Patterns

An Introduction to the Model-View-Controller, Model-View-Presenter, and Presentation-Abstraction-Control Patterns

Presenter First approach in MVP

Wednesday, May 28th, 2008

A colleague of mine recommended me a great paper to read:

 "Presenter First: Organizing Complex GUI Applications for Test-Driven Development", agile, pp. 276-288, AGILE 2006 (AGILE’06), 2006.

I really like the idea in this paper, it’s practical and useful in daily development life.

There are many articles or implementations and even courses talk about MVC or MVP, but most of them only gave very simple examples for them. Yes, it’s really easy to understand or sounds clear for a simple M-V-C piece or simple M-V-P piece, however in real life, a complete application contains many Models, Views, and Controllers/Presenters, this will be much harder than a simple sample.

This paper give a great approach in MVP best practice, I am still learning more and will do some experiment  development, but I already feel I should strongly recommend this paper.

More valuable links and examples, videos here:

http://www.atomicobject.com/pages/Presenter+First

ASP.NET MVC Preview 3 just released

Tuesday, May 27th, 2008

Scott’s introduction: http://www.microsoft.com/downloads/details.aspx?FamilyId=92F2A8F0-9243-4697-8F9A-FCF6BC9F66AB&displaylang=en

download: http://www.microsoft.com/downloads/details.aspx?FamilyId=92F2A8F0-9243-4697-8F9A-FCF6BC9F66AB&displaylang=en

 

It looks much neater than the previous version. Looking forward the official launch.