Published 2005-01-05 23:53:32

First Impressions matter, and today, I started with a blank piece of paper, and tried to port a very simple piece of code from PHP to aspx.

While you cant judge a book by it's cover, from today's experience, even reading the first few pages, was enough to make me wonder what all the fuss is with C# and ASPX, it appeared to be a poor joke in comparison to PHP.

I've hacked at C# projects before, having looked very heavily at mcs, and phpLex (a modification of csLex to generate php code). But I'd never really had any need to look at aspx. Today was a little different, a prototype I had thrown together for a project began being rebuilt in C# (dont ask why...)

The first part of the project was to get aspx + mono up and going on the debian box I was using. In general this was a matter of firing up synaptic, searching for asp.net and selecting install, and apply. There was a small issue that the default debian packages do not create a /var/www/.{cant remember the name} directory, and give it write permissions. I eventually spotted an error by starting xsp.exe manually with the verbose flag. (It would be better if xsp.exe install on debian defaulted to logging verbosely to /var/log/xsp.log)

Some of the impressions I got where from things that mono could improve on, others were a little more fundimental in terms of what at present appears to be questionable philosphy in C#, and maybe a lack of experience with aspx.

Having solved the missing directory issue, I went on to try out all the demo's that came with it, alot of these demostrate the web controls, but in general are good enough for a quick feel for the language.

I was a little perturbed by the examples of web controls, the first thing that came to mind was the template files which include <asp:input name="...."> tags would never render on a browser. It would be near impossible to send a file over to a designer and let them focus on the layout. I did like the way that the controls where available as objects (almost like DOM) to the page controller class, but there was a sense that the the base html template had to be altered far too much to enable this interaction with aspx. Ontop of this, although I'm sure it possible to avoid, I got the sense that you where running a HTML page, rather than an application that happened to render HTML. (most PHP I've done in the last year treats the HTML as a skin available to the application, and is nowhere near the page starting/running process). The example also showed only crude examples of including other files, so I'm left pondering if something as simple as a conditional include is even feasible.

But as I got my head around the task at hand, I began to see the other unusual decissions that appear to hamper productivity while developing in the language.

Class's for everything, looks like an ideal for OOP purists, but in reality, it turns simple tasks into a challenge of huge proportions, locating methods of unknown objects. The first task I set myself was sending a P3P header. Which I rather detoured into testing out sending a location header. A little googling / digging on the MSDN pages, and I discovered Response.sendHeaders(key,value). I tested this out on the page with the key=location, and tried to redirect to google.. - nothing happened.. (the browser go the header, but never redirected to anything).. A little further hunting revealed a Response.redirect() method. There was just something smelly about the idea that what should be simple, was made complex by an attempt to make it simple.

The next issue was dealing with cookies, It goes without saying that you need to know two things in PHP to deal with cookies - $_COOKIE (reading) and setcookie() (writing), in C#/aspx I had to deal with creating 2 objects to retrieve a potential cookie, I had to check it was not null, rather than just see if it was false (no native casting of null => false - eg. if (!mycookie) { .... }). and having begain to understand that I needed to use Request.cookies, I made a simple mistake of trying to use Request.cookies to save my new cookie. Again, the complexity of having Response and Request (which when skimming documentation, the difference is easily overlooked), appeared to be another case of trying to make something too simple, and yet adding complexity.

The one that really finished of the effort was looking at md5() - a nice PHP function that returns a string md5 representation of another string. While C# obviously has this, the amount of work required to do what should be a simple task appeared painful at best. Two different classes where needed , one to convert the string to a format that the md5() understood, the md5 one,  then a foreach loop to read the bytes returned and convert them back to a nice string.

Along the way I also noticed a few other counter intuative behaviours, (along with one or two slightly cuter features).
  • Page exceptions without clear backtracing, and code reveal. (I think) when you try to assign values to asp form elements, that are not strings - I only got a exception, with little explaination..
  • Full Page Code reveals for some exceptions, with highlighting of the offending code. (something PHP turned off by default about 2 years ago due to security concerns). - Although it help alot to have it, I'd consider it a bigger problem in the wider picture.
  • Vague and often meaningless error messages. I decided to write a small function/method to do the md5 stuff, and defined the method
    public String qmd5(String in) {.....}
    I kept getting compile errors on the constructor so assumed it was something to do with String using the wrong case. - I eventually guessed that in might be a reserved word or something, and changed it to inStr and solved it..
The sense I walked away with today was that given this small taster, if scaled up to a larger application would mean that I would end up typing numerous variable types, and be using long object.method names for simple tasks continually, (or constantly writing simple methods to do obvious tasks. ). Constantly be fixing exceptions on typos, and trying to second guess the compiler. Probably taking up 3-4 times as much code, and not gaining any clarity of purpose in the code, compared to a project done in PHP..

Mentioned By:
google.com : april (146 referals)
google.com : InStr C# (96 referals)
google.com : c# instr (91 referals)
google.com : january (66 referals)
google.com : php vs c# (56 referals)
google.com : InStr in c# (52 referals)
google.com : december (47 referals)
google.com : c# vs php (46 referals)
google.com : aspx c# (38 referals)
google.com : MONO VS PHP (31 referals)
google.com : mono aspx (27 referals)
google.com : convert php to aspx (25 referals)
google.com : c# mono (20 referals)
google.com : convert php to c# (20 referals)
google.com : aspx mono (18 referals)
google.com : instr function in C# (17 referals)
google.com : aspx vs php (15 referals)
www.artima.com : PHP Buzz Forum - aspx, C#, mono and First Impressions (14 referals)
frassle.net : aspx, C#, mono and First Impressions - frassle (14 referals)
google.com : "php vs c#" (12 referals)

Comments

yes but ... yes
I agree with most of what you said, PHP is no doubt the KISS language, and that's why we have chosen it.

But you have to consider the fact that you tested with Mono under Debian and therefore didn't use VS.NET
VS.NET greatly "enhances" the experience of programming for .NET
The syntax/typos problems you had for example would disappear within minutes by using VS.NET.

And there are a few neat things you didn't insist enough on I reckon. Being able to program components and lay them out by drag 'n drop can be a big time-saver and for the moment, ASP.NET + VS.NET is the ideal solution for this kind of things.
Also the class based design of .NET makes it way more complex than PHP but in certain situations more powerful too.

But generally I agree with you.
A language/platform should not be dependant on an IDE to reach a satisfying level of usability and productivity.
Now that PHP5 is here and very interesting projects are being developed around it (prado for example, http://www.xisc.com) I feel less and less the need to even look at ASP.NET ...
#0 - Cyril Doussin ( Link) on 2005-01-06 06:42:00 Delete Comment
comments
I think when you started using php oriented analogies in ASP.NET you have to be careful. The concepts in ASP.NET and the .NET framework are quite different to that of PHP.

Of particular importantance is the concise and comprehensive documentation available for .net. I believe you should start with the documenation (including the tutorials and MSDN), rather than coming from a PHP perspective to examine the various apsects.

Lastly, although you can build applications without the Visual Studio. Assuming you know the basics of the framework, why would you not want to?

P.S. I have tried mono asp.net on debian. The main difficulty was the lack of quality database adapters on linux (for the ones that I found).
#1 - Wei ( Link) on 2005-01-06 08:34:45 Delete Comment
MD5 - PHP vs C#
I've actually had problems trying to generate a MD5 hash using C# to coincide with a hash created using PHP.

I've been using the UnicodeEncoder and the UTF8Encoder to convert my string to a byte array. This is the way I usually do it. But I was getting an incorrect hash. Or should I say, my hash wasn't matching the one generated with PHP.

In order to get the 2 hashes to be the same thing, I had to use the ASCIIEncoder object in C#.

I'm no PHP expert, and I don't know for sure how the MD5 function in PHP works. But, if it only does hashing of an ASCII encoded string of bytes, and doesn't allow for a different encoding, I think it's time to submit a bug report...

PS. Ubuntu + Mono + MonoDevelop + [some other stuff] = my desktop system.

I deploy asp.net applications to Win2k and Win2k3 servers.
#2 - Marc DM ( Link) on 2005-02-06 09:19:09 Delete Comment
ASP.Net versus PHP
Couple of comments about things you said:

> It would be near impossible to send a file over to a designer and let them focus on the layout.

If you are using the suite of Microsoft development tools then this is quite simple. Also if you split your code from the UI of the page this also is quite simple for the html developer. I won't get into the various methods, but if you compile the code into a DLL file (which has various drawbacks) then the designer would never even see the code, and have no way to "break it" - much less have to worry about finding the html in the midst of the code (well, not html but asp:label, etc.).

PHP (which, no offense intended, is basically a copy of classic asp - I don't mean a copy in a bad way, but it's basically the same concept / style of writing though). If you compared from PHP -> classic ASP you'd have a fairly easy transition. For web apps PHP has some features classic ASP missed, especially things that got enhanced over the years while Microsoft gave up on classic ASP in favor of asp.net - However the transition would be a fairly simple one between these two systems.

Realize ASP (and ASP.Net) is just a wrapper for a language, where PHP is a language. So ASP, and ASP.Net, are both designed for various programming languages to be included, C#, VB.Net, Python, etc.

> Full Page Code reveals for some exceptions, with highlighting of the offending code. (something PHP turned off by default about 2 years ago due to security concerns). - Although it help alot to have it, I'd consider it a bigger problem in the wider picture.

This is configured in web.config - Sice you did things manually you skipped some steps in development resulting in this being on. In your web.config see the <customErrors> defintion.

Overall to your post:

ASP.Net has a learning curve. It has many features, but the entire concept is NOT to think like a PHP developer (or classic ASP developer) - It's instead more geared towards those developers that think like a desktop application in VB - If you came from that mindset PHP would be extremely confusing, as would classic ASP - And ASP.Net would make far more sense.

Steve Radich - http://www.aspdeveloper.net - Virtual Server FAQ - ASP.Net Information - FREE
BitShop, Inc. - http://www.bitshop.com - Managed Servers, Colocation, .Net Development (C#,VB,ASP)
#3 - Steve Radich ( Link) on 2005-05-09 19:19:06 Delete Comment
Yeah, okay...
I'm actually a PHP developer myself who has been scoping out Asp.net with Mono...

It should probably be mentioned that most of your observations were due to a lack of understanding, and the overall article has a thick layer of what seems to be preemptive dislike of Asp.net.

I should probably also point out that your doing development in C#.net which, in my opinion, is the lowest-level and most complex language in the .net family.

On the other hand, I think C# is the coolest thing since toasters, but I'm an old-school C programmer, too.

Which raises another thought: do you even know C? I mean, were you under the impression that writing a C# program was in some fashion the same as writing a PHP *script*? It isn't a scripting language, and it never was, nor will it ever be. This is, fundamentally, why it took you so many painstaking steps to hashing an MD5.

Now then; please, attempt to hash this MD5 with C, by itself, and count the lines of code.

On the other hand, if you had to (for example) hash an MD5 manually within your PHP script, if you were to compare performance with a similar C# native implementation I'm sure you would see the advantage of compiled code over ad-hoc accelerated JIT scripts.

I suppose my point is rather simple; I don't write web applications in C, and I don't write webservers in PHP, I use the correct tools for the job! If you had an intensive PHP script which, for some reason, had extremely poor performance under load, would you:

a) buy more servers and cluster
b) rewrite the program in a different scripting language
or
c) find the resource intensive part(s) and link native libraries in to improve performance

probably c), but unfortunately it isn't very easily done with PHP, and 9/10 companies simply do a).
#4 - Deeo Daniels ( Link) on 2007-02-09 22:49:15 Delete Comment
yeah it's a hard choice
I'm from the php camp, but see the grass greener in the asp.net world.

since php is just a language and not a framework i can easily pick between iis, apache; postgresql or sql server

In asp.net you don't have that luxury. [mono will always play catch up; look at ctp products: linq, ajax extentions, css adapters ]
therefore you have to stick with iis, and sql server.

if you don't stick with the bundle it is painstaking work to create all the providers, and the ide doesn't play nice when creating datasources of other db's.


Your also required to become intimate with the framework which you have no way of making changes to. Example I created a custom control to solve the problem of asp.net websites littering javascript throughout the page instead of placing it in the header. The control grabs the inner content saves it to a session and when my request.filter is called it was to place the content in between the head tags of the page using regex.split .. well after creating this control.. I couldn't do that as my session is destroyed before request.filter is called therefore exceptions are thrown for attempting to access the session object.





here is another one. you can't have singletons in an asp.net application. Yes its true because the object is placed in app domain not in the context of the user so multiple requests will read and write to the same object - not what i expected. A work around was to save my temporary object to session... but again something possible in php [since the whole request runs on 1 thread.... but this also contains limitations; asp.net i can call a webservice asynchronously while my other crap can keep being processed].


I like that c# already has the encoding all worked out.


Although i hate how some things HAVE to be done when working with asp.net .. the benefits are I'm meeting my deadlines now.
#5 - Leblanc Meneses ( Link) on 2007-04-07 16:32:40 Delete Comment

Add Your Comment

Follow us on