The Artima Developer Community
Sponsored Link

Agile Buzz Forum
So much work

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
So much work Posted: Jul 23, 2004 10:11 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: So much work
Feed Title: Cincom Smalltalk Blog - Smalltalk with Rants
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rssBlogView.xml
Feed Description: James Robertson comments on Cincom Smalltalk, the Smalltalk development community, and IT trends and issues in general.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Cincom Smalltalk Blog - Smalltalk with Rants

Advertisement

This is interesting - a .NET (C#) developer looking at what it would take to add an attribute to an object at runtime:

I wanted to be able to add properties on the fly.%A0 I've changed the idea a bit to look them up on the fly versus adding them.%A0 Using psuedo-code:

// expandable object
MyObject o = new MyObject();

// add the property
o.AddProperty("FirstName", "Justin");

I'm not using these properties in code anywhere.%A0 I'm actually feeding the object to a template system (the C# port of StringTemplate%A0in this case).%A0 Now StringTemplate supports reading properties in the templates like so...

$p.FirstName$

But unfortunately the%A0MyObject%A0type%A0doesn't have a FirstName property.%A0 And StringTemplate uses the Type to do reflection.%A0 Anyway, during my research of IExpando (much like IDispatchEx), I noticed the interface IReflect.%A0 Looking at the docs for it, it contains all the most common methods that people use on Type when performing reflection (GetProperty, GetMethod, etc.).%A0 So if I change StringTemplate to use IReflect vs. the Type class, then I could implement IReflect myself.%A0 Of course, there are problems with this; mainly the fact that PropertyInfo is an abstract class (MemberInfo, the parent class, is also abstract).%A0 So I would have to write implementations of those.

Hm...this seems like more effort than its worth.%A0 Maybe I should just do something like this...

$p.Attributes.FirstName

Attributes would be an IDictionary.%A0 Then I can extend StringTemplate to look at the object.%A0 If it is IDictionary, then use the property name as the key.%A0 The former definitely has more of a "coolness" factor, but the latter would take like 15 minutes.

Heh. As opposed to the following in Smalltalk:

myObject class addInstVarName: 'firstName'. This is one of those telling differences between Smalltalk and languages like Java and C# - it's not that you can't accomplish the same things - it's that you don't bother because of all the work involved. Smalltalk makes the simple things simple, and the hard things possible. Languages like C# and Java make the simple things possible, and the hard things painful...

Read: So much work

Topic: An interesting summary Previous Topic   Next Topic Topic: CI Demo Part 5 - Something to play with

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use