February 2004 - Posts

DevWeek is done
27 February 04 06:45 PM | despos | 1 comment(s)

Just finished with the DevWeek conference in London, UK. Excellent. Really excellent.

Good people, great city. You should make it next year. I do recommend it.

Always macros (but in VS.NET)
27 February 04 06:39 PM | despos | with no comments

I'm a fan of wizards since Visual Studio 97. I hate wizards that expect to teach you how to accomplish tasks. And even more,  I hate wizards that present themselves as the only way to accomplish a task. But I do love wizards that let you write more code faster. Or that give you a piece of code as you would have written it.

I'm not trying to say that wizards are a replacement for CASE tools or for code generators or so. I just look at them as a tool. Period. And I love macros too. Especially, VS.NET macros.

For quite some time (yes, since 1997) I minded writing new macros and wizards for VS. Here at London's DevWeek, I attended a presentation that thrilled me at that. The presenter was Francesco Balena--a good pal of mine. I think I'll spend some time to build my own collection of VS.NET macros just to speed up work.

And you? Do you have special macros to share or recommend?

Macro in ASP.NET (part 2)
22 February 04 12:32 AM | despos | 3 comment(s)

Thanks for sharing your thoughts!

I've been thinking to ASP.NET macros for quite some time lately, but I'm not sure they are really a good idea. Read, something you might want to add to the official wish list for the next version of ASP.NET.

Maybe they are. Maybe not. However, I want to clarify a couple of points raised by some comments.

What I call an ASP.NET macro is the capability of expanding some compact code to HTML literal markup before the ASPX source page is compiled to the assembly. It goes without saying that this can be coded with a custom or a user control. I just don't want to use server controls. By design.

There's nothing a macro (according to the definition above) can do that a server control cannot do either. The rub lies in the fact that controls have a certain impact on performance and should be avoided when the functionality they provide isn't strictly necessary. 

Basically, I'm looking for the save programming style pushed by controls without the overhead of controls. I'd like to use a compact and declarative syntax to reference significant pieces of (literal) HTML. A way to save development time. Andrew hinted at ideas he has to improve design-time tools. This is certainly one way to give me the functionality that I devise in what I call ASP.NET macros.

I haven't found yet significant scenarios where this would really be useful. But in some way I feel this is something I need to think more about.  

Macro in ASP.NET
20 February 04 06:36 PM | despos | 11 comment(s)

Quick (and non-scientific) poll. How do you feel about sort of ASP.NET macros? What's that?

My definition of ASP.NET macro is some markup text that is detected and expanded before the whole ASPX source is passed to the runtime for compilation. For example:

<dino:header title="Hello">

expanded to pure HTML (of course...)

<TABLE width="100%">
<TR> <TD>Hello</TD> </TR>
</TABLE>

Is it a far-fetched idea? Uhm, not sure. I've just seen a couple of posts to the public ASP.NET newsgroup. I'm not alone...

Come to Italy
20 February 04 06:19 PM | despos | 14 comment(s)

There are many reasons to come to Italy. In no particular order,

  • Monuments
  • Museums
  • Food
  • Weather
  • Beaches
  • More...

However, that's stuff for tourists. If you're looking for a new country, now you have an excellent reason to move to Italy. It has to do with taxes and elections... Read on.

Elections? This reminds me the first joke I ever told in English.

An American and a Chinese meet up and talk. The American asks "How often do you have elections?". The other answers: "Oh, almost evely day..."

Elections--the "motionless engine" of everything. (copyright Aristotle).

(G)rave Amazon reviews
16 February 04 10:45 AM | despos | 10 comment(s)

An Italian newspaper reported it yesterday quoting this Amy Harmon's article from the New York Times. A quick search on Google proves that the rumor started spreading out way back. What's the point? Amazon book reviews are (sometimes? often? never? always?) a farce.

The article reports that a bug in the Amazon software (the Canadian site) revealed the identity of thousands of anonymous reviewers. In at least one documented case, the author of the book also wrote a five-star review.

"That anybody is allowed to come in and anonymously trash a book to me is absurd" 

This is the comment of John Rechy, one of the authors of such "homemade" reviews. There's more, though. There are significant clues leading to the conclusion that a sort of war is in course between competitors. Unknown reviewers--the NYT article reports--often appear behind the signature "a reader from New York".

Hey, wait a moment.

Have you ever read through the reviews of my Programming ASP.NET book? At this time, Amazon awards it with 4.25 out of 5. There are several fully documented five-star reviews with arguments. There are quite a few with less stars, but equally with arguments. Finally, there are a few with one star or two but NO arguments. And who's the author of (at least) one of them? Just "A reader from NY" :-))))

Quoting from that one:

I purchased this book because it is from MS Press. But this book really disappointed me. There is no logical flow . There is a lot of text in this book but it is very hard to keep your interest in this book. Sometimes I felt that even English wasn't good. I tried to read this book at different times of the day ,morning ,evening,before dinner, after dinner, on weekends ,during weekdays but nothing changed.I want to 'donate' this book to someone. My personal advice is 'don't buy this book unless you have read a few chapters at the book-shop'. In fact Jeff Prosise's book on .NET has better material on ASP.NEt than this book.

Respectable point of view--definitely not a review.

Probably, the problem (if we still want to call it this way) is in the free text that is allowed. A review must give certain structured info to the potential reader. It should be a sort of guided wizard, not just comments. It is too easy to "trash a book" w/o plausible reasons.

OK. Am I the author of one of those rave reviews for my book? No. However, I often answer the next question "Was this review helpful to you?". Of course, unargumented comments are not much helpful. To anybody. 

Attribute-based Programmers
12 February 04 07:36 PM | despos | 5 comment(s)

Just for fun... Here's a couple of nice quotes from e-conversations and comments.

  • The more I use attributes, the more I like attributes. I'm really becoming a "programmer with attributes"
  • There is more, about you and your professionalism, that can not be "decompiled"

The first quote is adapted from Italian and in the original form it enjoys the double sense we assign to the word "attributes" (the plural form). You americans and mother tongues, do "attributes" mean to you what it (sometimes) means to us? 

Reading Flyboys, a James Bradley's book about the story of some US pilots during WW2, I've learned a lot about the so-called Spirit of Warrior that animated all Japanese troups during the war. They (were led to) believe that thanks to their spirit they could only win any war. In the book, James reports the comment of an unknown American pilot:

We had the same spirit, but we called it balls.

Well, we (also) call it attributes. (When we want to be polite and be "sort of" elegant in our conversation...)

In light of this, I officially propose to rename "real programmers" to "attribute-based programmers." It reflects better the new spirit of .NET programmers, isn't it? Attribute-based programmers are seasoned and professional developers and consultant, completely obfuscated and, as such, impossible to decompile for fellows and wives <g>

Themes in ASP.NET 1.1
12 February 04 06:34 PM | despos | 1 comment(s)

As hinted at in this post, I'm trying to implement themes in ASP.NET 1.x applications. So far I've used an XML file (sort of DataSet) with prop/value pairs for each skinned control. These settings are then translated to code and added to the project. The same process can be accomplished using dynamic compilation like that of ASP.NET pages.

To the extent I can judge having looked at the ASP.NET 2.0 implementation with a couple of decompilers, this implementation is really close to that you find in ASP.NET 2.0.

The only problem left is--what's the best format for a theme file?

ASP.NET 2.0 uses a sort of markup. Basically, you can shape your control in VS.NET and then cut-and-paste the ASPX markup in the theme file. The problem is, how can I extract the settings out of this markup? Again, ASP.NET 2.0 seems to use the template parser--a class marked as internal and not usable outside system.web.

The idea of writing a parser doesn't really excite me. I'm not like my good friend Francesco Balena who really enjoys parsers of any type...

There's a method in the Page class that sounds promising. It is ParseControl. It takes a markup string and creates the corresponding control! My idea is

  • Read blocks of markup out of the theme file
  • For each block, create the corresponding control (a temporary control)
  • Parse the markup and extract all the properties explicitly set (the properties that make up the skin)
  • Read the value of these properties from the temporary control and use these values to override the corresponding property on the original control

I didn't know an effective way to accomplish the last point. Using reflection seems to be obvious but exactly how?

Chris Anderson contributed this code--which is just what I was looking for.

object o = this;
PropertyDescriptor bg = TypeDescriptor.GetProperties(o)["BackColor"];
TypeConverter c = bg.Converter;
object v = c.ConvertFromString("Red");
bg.SetValue(o, v);

 

Really cool. I was too lazy to look carefully into PropertyDescriptor!

Got obfuscated?
11 February 04 03:47 PM | despos | 7 comment(s)

A frequent question I get at public shows (mostly in Italy) regards code obfuscation. I've never used commercial tools to decompile and obfuscate. I simply use Anakrino to dig out intricacies of system assemblies. I formed the idea that decompilation is not enough to steal tricks and ideas and let alone to build competitive apps. Am I wrong?

Do you have experience with Anakrino and other commercial decompilers? Are they different? Which one would you recommend?

Are you worried about decompilation?

Reflecting on reflection
11 February 04 03:41 PM | despos | 8 comment(s)

I have a sort of love-hate relationship with .NET reflection. Being a form of indirect programming, reflection is not as fast as early-bound code. However, that is a secondary point to me. Avoiding any performance-related gripes, my points about reflection are the following:

  • I love the flexibility that reflection provides
  • I hate the messy code it forces you to write

Reflection-based code is hard to read and maintain. So far I've been able to make use of reflection only to build infrastructural code--not directly application code. Love to see your thoughts about reflection and scenarios in which you're using it and comments you want to share.

Why reflection today? I'm working on a possible implementation of themes in ASP.NET 1.1.

I have a text file representing the skin to apply to all controls of a certain type. The text file lists a group of property/value pairs. For example,

<button>
<property>BackColor</property>
<value>Color.Gainsboro</value>
</button>

where BackColor is the property name and Color.Gainsboro is the corresponding value. Now imagine that you have some runtime code that loops through the controls of a page and applies to each control the skin settings. You can use reflection to set the BackColor property of a Button to a certain color. Sure, it is possible but you need to:

  1. Retrieve the PropertyInfo object for the property
  2. Set the value making sure that you pass in an expression of the proper type.

The second point is the harder I think.

So I discarded reflection and opted for code generation much like you do in a .NET project when you reference a Web service. You import the WSDL and the project generates the proxy file for you. That's what I did and it works. The drawback is that I currently lack tools integrated in VS.NET to automate the process.

There's a better option though and it is just what ASP.NET 2.0 does. In that case, with a significant help from the new compilation model. The idea is generating the code for the theme object at runtime. You look at files in theme directory, parse them in a VB/C# source and compile on the fly. Next, you load the assembly in the app.

It is not for the faint-hearted but it gets the better of both world--early-binding and flexibility.

Haven't started coding yet...

  

 

More Posts Next page »