Scott Guthrie just posted the first overview of the ASP.NET MVC
Framework Microsoft is going to be shipping with VS2008:
http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx
Looks amazingly like Rails... ;)
--
Cory Foy
http://www.cornetdesign.com
> a method on a controller is an "action" is an improvement over
> the Rails implementation wherein any public method on the
> controller can be executed from a browser with the proper URL.
Why is that an improvement? Rails relies quite a bit on convention
over configuration. Why add yet more line noise in the form of .NET
attributes to figure out something that has already been stated: a
public method on a controller can be executed publicly.
> The ability to map the URL parameters to action method parameters
> beats using Rails' params dictionary.
Looks good in the demos. You might still use the params collection
when you've got too many parameter arguments than would should be
sensible for a method signature.
> I prefer the MS MVC's approach of explicitly passing
> data to the view instead of having all instance variables
> on the controller be available to the view (as it is in
> Rails). I prefer to have my intent be the result of explicit
> action, rather than side-effect.
What's not explicit about setting an instance variable? The only
instance variables set on a Rails controller are data sent to the
view. The semantics of a controller in Rails suggests that this is
the explicit mechanism for passing data.
On Nov 25, 2007, at 10:17 AM, m.sean.kelly wrote:
> a method on a controller is an "action" is an improvement over
> the Rails implementation wherein any public method on the
> controller can be executed from a browser with the proper URL.
Why is that an improvement? Rails relies quite a bit on convention
over configuration. Why add yet more line noise in the form of .NET
attributes to figure out something that has already been stated: a
public method on a controller can be executed publicly.
> The ability to map the URL parameters to action method parameters
> beats using Rails' params dictionary.
Looks good in the demos. You might still use the params collection
when you've got too many parameter arguments than would should be
sensible for a method signature.
> This can be seen as a improvement because of the security
> concerns. I don't like it, but this is a valid argument.
I'm not clear on the issue. How does the vulnerability relate to
public methods vs. methods with attributes?
> Or, you can use [DataBind] and have a method parameter.
I'm not familiar enough with ASP MVC. What do you mean by 'method
parameter'?
On Nov 25, 2007, at 11:06 AM, Ayende Rahien wrote:
> This can be seen as a improvement because of the security
> concerns. I don't like it, but this is a valid argument.
I'm not clear on the issue. How does the vulnerability relate to
public methods vs. methods with attributes?
> Or, you can use [DataBind] and have a method parameter.
I'm not familiar enough with ASP MVC. What do you mean by 'method
parameter'?
> It is fairly typical MS mindset, trying to make sure
> that you meant what you wanted.
Yeah, that sucks. Too bad though. They could have shipped the tools
with a practice guidance effort that would see to it that doing stupid
things with controllers would be a matter of choice rather than
ignorance.
> public void NewUser([DataBind] User user)
I didn't realize that was possible in ASP MVC.
Since switching from MonoRail, I've become partial to the Rails way
using the params collection:
def new
user = params[:user]
end
The underlying mechanisms are quite different though.
> public void NewUser([DataBind] User user)
I didn't realize that was possible in ASP MVC.
Since switching from MonoRail, I've become partial to the Rails way
using the params collection:
def new
user = params[:user]
end
The underlying mechanisms are quite different though.
> What is user in this case? A string?
It's a Ruby Hash: http://www.ruby-doc.org/core/classes/Hash.html
A hash behaves like a dictionary. A Rails model object (ActiveRecord)
can be initialized by passing a hash to its constructor.
There are no real concrete fields on a model object. There are
dynamic accessors that look into the dictionary for the key/value that
corresponds with the accessor.
Internally, the value for user.name is stored in attributes[:name],
user.password is stored in attributes[:password].
Hash is like the universal mechanism in Rails and Ruby. Anytime you
see something like :name => 'Bob' it's a Hash. You don't need to do
much more to create one than something like my_hash = { :name =>
'Bob' }, or my_hash = :name => 'Bob', although you don't often see
that kind of thing except in test code (or framework code).
It's more likely that you'll see user = User.new :name =>
'Bob', :password => 'foo'.
And in the case of passing model data from the view to a controller
action:
def create
user = User.new params[:user]
...
end
> It's conceivable that I may want to have a public method
> on a controller that I don't want to be accessible from a browser.
A controller class with a public instance method that isn't an action
is a design smell.
Putting attributes on actions is like putting a band aid on a design
problem rather than curing it.
> I can see developer preferences on either side. Myself, I like having
> the action method explicitly state via method parameters, "This is
> what I expect to be passed to this method."
As long as your perspective of action invocation equates to method
invocation...
Even though a method, function, whatever is the construct that handles
the request, you could make a case for using a params collection as
more closely representing and signifying HTTP. At least, that's part
of my appreciation of the way that Rails influences the semantics of a
controller action.
Strongly-typed args in MonoRail are cool, but it can get unwieldy for
forms with a good number of fields. A method signature with 10+
arguments is a design smell for me. The args could be replaced with a
DTO, but a parameters collection on the request is already a DTO.
I'm not sure I'd create a strongly-typed parameter object just to
replace a hashmap.
Anyone know if ASP MVC exposes the equivalent of a Rails' params array?
> It is simply that this:
> :foo => :bar
> reads much better than
> "foo" => "bar"
Well that, and symbols are singletons.
This hash: "foo" => "bar, "foo" => "yo"
allocates memory for both instances of the "foo" string.
This hash: :foo => "bar", :foo => "yo"
allocates :foo once. And any subsequent uses of :foo will refer to
the same :foo space in memory.
Symbols are truly treated by the compiler as something other than a
string. They're part of the symbolic language of a model or API.
Symbols are something like a field definition on a .NET class - the
field is defined once on that class, no matter how many instance of
that class exist, and no matter what different data is held by that
field in each individual instance of the class. The definition of the
field is a single definition.
It's not a perfect analogy, but .NET doesn't have an ideal
representation of a symbol.
A symbol is a representational unit that doesn't have to belong to the
definition of any class or module. In can just live in the Ruby
object space, representing different things in different contexts.
Linguistically, they're something along the lines of a morpheme.
Because symbols are often thought of as linguistic units in Ruby
rather than strings, they play into the mindset of language-oriented
programming, and thus are in play in the Ruby DSL mindset.
On Nov 26, 2007, at 7:07 PM, Ayende Rahien wrote:
> It is simply that this:
> :foo => :bar
> reads much better than
> "foo" => "bar"
Well that, and symbols are singletons.
This hash: "foo" => "bar, "foo" => "yo"
allocates memory for both instances of the "foo" string.
This hash: :foo => "bar", :foo => "yo"
allocates :foo once. And any subsequent uses of :foo will refer to
the same :foo space in memory.
Symbols are truly treated by the compiler as something other than a
string. They're part of the symbolic language of a model or API.
Symbols are something like a field definition on a .NET class - the
field is defined once on that class,
I find value in being explicit.
http://martinfowler.com/ieeeSoftware/explicit.pdf
http://codebetter.com/blogs/jeremy.miller/archive/2005/08/24/131096.aspx
I MUCH prefer the approach in letting my class definition attributes
and/or HBM be the authority for the domain rather than the database
itself. I love that I can just ask NHibernate to generate the database
schema for me. I can now run my unit tests in sqlite, but my
dev/qa/production on PostgreSQL. I can change databases with very
little work.
Frankly, I'd love to see this extended with a declarative approach for
suggesting indexes and allowing CreateSchema or CreateIndexes.
I can't complain too much about the Rail's ActiveRecord approach. But
I don't like it. I'd much rather be able to look at my class
definition and know what is available than have to inspect a database.
--
Jay
> I can't complain too much about the Rail's ActiveRecord approach. But
> I don't like it. I'd much rather be able to look at my class
> definition and know what is available than have to inspect a
database.
In Rails, you don't have to look at the database to know what's
available, you look at the migrations. Or, you can look at the
schema.rb that is generated when migrations are executed.
On Nov 28, 2007, at 9:13 AM, Michael Kelly wrote:
> But I wonder if Jay isn't also making the point that he'd prefer
> to work at the level of the ActiveRecord (or "entity") class, and
> let the the database take care of itself.
I don't see the distinction being made.
I use ActiveRecord in Rails, and I work at the level of the entity -
or "model" in Rails parlance.
I guess I don't understand what is meant by "let the database take
care of itself."
Are you talking about a need for more sophisticated object to
relational mapping over and above what the ActiveRecord pattern
typically addresses?