Showing posts with label Visual Foxpro. Show all posts
Showing posts with label Visual Foxpro. Show all posts

Thursday, December 23, 2010

The Cheerleaders Strike Again - The Good Part Source Code Doesn't Lie!

Believe it or not I don't just rant on here, it takes several hours, in most cases to put a post together and write the sample code. Then I do my research on the internet starting with several sites (some people I'm sure wish I didn't visit their sites :)..) and forums to ensure my posts, while blunt and opinionated, are based on fact and my bases are covered so too speak. Which is FAR more then I can say for some cheerleaders.

This blog post started off on a comparison of weak and strong typed languages. However I found an article, while rather dated, but nonetheless really pissed me off.

The article, of course, was about strong typed languages, which is fine if you have an opinion that varies from mine. There is no right or wrong answer when it comes to this it is just a preference. But what pissed me off is the author, who I once respected and now could give a shit less about, was a very well known Visual Foxpro speaker and consultant.

I didn't really care for the fact he refused to sign the VFP petition, as we all were aware of the harsh reality it probably wouldn't carry much weight at Microsoft to the powers that be, but still IMHO it was simply a show of support for the Visual FoxPro community.



Anyway it is safe to assume the author made a very nice living off Visual Foxpro besides being his claim into the programing world, to the best of my knowledge. But now he is a freaking Microsoft Muppet, I had to create a new level higher then Cheerleader for shit like this where Microsoft, I assume, can just pull his strings. If Microsoft isn't influencing this writing then what the "f" is wrong with him?!

Look I am not a fan of Scott "THE DOT" GU and tend to disagree with Soma, I actually hold Soma in a bit higher regard then "THE DOT" due to the fact Soma will at least post comments on his blog that are critical of Visual Studio and let the community debate it out if necessary. But at least "THE DOT" and Soma only spin Visual Studio they don't blatantly invent bogus crap about legacy technology that worked!

This Muppet is not only spinning Visual Studio he is discussing highly questionable negative aspects of a tool that he was advocating using not long ago. His post have the potential to adversely affect VFP'S developers, if a client was considering building a VFP application and stumbled across his ramblings. These are the same developers that bought this muppet's tools and books. WTF is going on in the head of some people!

In his blog post he basically ripped on Visual Foxpro for being a weak typed language with general statements and total disregard for the truth while ignoring obvious problems in Visual Studio.

Of course I needed to set the record straight!

Let's pull out some excepts out of his post and see how right or full of shit he is!

After All Source Code Doesn't Lie

To give you some back ground, the premise is he had some old foxpro code that he wanted to refactor and move some proprieties and variables around. Which according to him was a pain in the ass to deal with the repercussions and ripple effect of an essentially minor change.

Ok so let's get into his post ...

In a strongly typed language, make a change to a property name, or remove and the compiler (he is referring to Visual Studio) will tell you where it's missing or mistyped or used incorrectly. It's that simple. The same is true if you're in full on heads down code mode and you write a large chunk of code at one time without immediately testing to keep the flow going. In Fox I have to write my code and test right away to make sure I didn't accidentally mistype or format something improperly. There are bound to be typos etc. again, in Fox the only way I will find any of these sort of problems is to run the code. In .NET the compiler catches all of that and it takes a few clicks to fix it because the compiler tells me a) that there is a problem, b) where it is and c) takes me there so I can change it. Compare that to VFP: Run the application to the code you changed, bomb, look at the code, make the change and re-run. And you better hope you excercise all the code paths.


I want to stop this right here. Factually what he said is related to properties and is inaccurate at best. In Visual Foxpro, if you removed a property or have a typo the Visual FoxPro compiler will "DEFINITELY" throw an exception.

Here is a small sample code to prove this point.








Sure looks to me like the FoxPro compiler is taking me exactly where the problem is at and yes VCX'S work the same way. WTF he is talking about!

Anyway let's proceed.



In a strongly typed language I can worry about logic errors and forget about syntax and typos - the compiler does that for me. Maybe I'm a sloppy coder, but I find that experience of writing code, having to run it and fail only to find that I left out a letter in a variable name very frustrating especially if that code is buried in the UI that often can be tested only within the application. Compare the time to fix this sort of a bug. ST: Compile see the error, click on the error, fix the code, recompile. Total time: Maybe 30 seconds. Fox: Start the application, click to the place you have to go, fail, pop up the editor, fix the code, shut down the application, clear memory etc. restart the app and try again. Time: 2-3 minutes at least. In my work (especially the last couple of days) that's a typical scenario...



This is another exaggeration of the truth. First off what programmer in their right mind doesn't worry about syntax when writing a piece of code. What the hell is he writing pseudo code and yes that is such a bastardized statement to even imply Visual FoxPro doesn't catch syntax errors. It is not even worth my time to put a print screen together of that case.

His other point, I think what he is referring to is variable name typos and scoping...

For example.

private pcTypo
pcTypo = ""
pcType = "some error"

pcType is a statement that will get through the compiler in VFP, no doubt about it and it will error in C#/Visual Studio.

But here is the kicker, he specifically mentioned UI in his comments. If you have ever used Visual Studio 2008 webforms or mvc, that thing is like swiss cheese, intellisense and even the compiler misses errors when it comes to javascript, html or jquery. That is "code and try" testing or in MVC you can use TDD. If he is right it takes 2 minutes to find a problem in FoxPro, which under most cases is not accurate, how long does it take to write a test script or debug a webform and mvc UI. Why in the hell isn't he blogging about that issue since this is such a big fing deal! And don't even tell me HTML is not compiled so Visual Studio doesn't have to catch anything, BULLSHIT! there could be a well implemented editor with error handling. This is one f'd up double standard being applied here.


I've worked this way for many years in FoxPro and I've never really thought much about it, but after having spent a significant amount of time in .NET, now when I go back to VFP code I sorely miss strong typing and the true Intellisense that VS.NET offers in the editor.


Sure he never thought about it much because the compiler and intellisense worked in Visual FoxPro for 99% of the cases. The typos in variables names happened so rare it was only an after thought. Most VFP programmers used Hungarian notion and knew the variable scope and type just by looking at the name without wasting time with all this strong typing crap. Apparently now he felt the urge to rant about FoxPro for no apparent reason other then a lame attempt to prove Visual Studio is more productive then VFP which it totally IS NOT!.

Ironically when he goes back to Visual Studio and leaves Visual FoxPro doesn't he miss not having to write plumbing code or having a class browser that functions or how about the command window to quickly and easily execute a command/function/query a table etc ... or being able to use the EVAL() statement instead of writing massive amount of reflection code. Give me a break!

Then he stated "true" intellisense: I Googled Visual Studio Intellisense Bugs, it produced 76,000 results. Move over there is limited intellisense in the UI layer of Visual Studio for web development and the Visual Studio intellisense, even in 2010 for C# has issues.

Look at this simple code...



iBroken is returning an error, fair enough, but the problem is gGuid is not where is the consistency?

Here is a UI snippet in Visual Studio 2010.



This snippet is an FING mess and not a single error being returned by Visual Studio 2010 intellisense. Leave me a comment if you can't see the problems and I will point them out.


I haven’t seen such an editor and I doubt that there will be one. It’s damn tough to parse untyped code and get meaningful metadata from just the source code alone especially if that source code doesn’t tell you type information. Without strong typing, how does the editor know what’s an object, what’s a property and whether it subobjects? How could it? It can take you some of the way as the Visual FoxPro editor does, but it will always stop short of providing a complete implementation.

The second problem with editor implementations is that it relies on an editor. The editor doesn’t compile the code. If you don’t use the fancy schmanzy editor that does this supposed syntax parsing then you’re back to having no type safety checking at all.


Sure he brings up FoxPro again, but where is even a simple case Visual FoxPro doesn't work? I honestly tried to break VFP and with the exception of some strange com stuff I couldn't. Again referring to my snippet above, there is the code editor in Visual Studio that didn't catch even obvious problems!

Let me skip to the end of his post to wrap this up.



In VS.NET 2.0 the new databinding features can bind directly to objects and the designers let you look at the objects and pick what to bind to by way of the meta data. You can drill into objects and pick properties several levels down etc. Without strong typing this would not be possible!


I am a bit confused as to what designers he is referring to in Visual Studio that indeed lets you do everything he states they can do?

Hmmm how about a class browser that let's you drill down into properties, methods and events isn't that a designer in FoxPro that Visual Studio lacks?


In FoxPro to do the same for a Fox class, we have to parse source code files ourselves and given the somewhat convoluted formats of the designer files. And even then there's not enough information in there. How do you figure out a return type in a VCX method for example? I’ve done this in Help Builder and the code to do this is a serious mess and what’s worse it doesn’t provide all the information that would be useful.

You may say that that this doesn't affect because you don't use features like this, but it does indirectly. In terms of what tools are provided for you and what functionalities are not available easily in Fox.


This is getting worse the farther we dig into it. Did the author really ask how do we figure out a return type for a method? Is he freaking serious? If you can't figure out a return type then you have more then intellisense problems with your code. Let me help him figure out a return type for a method.

Step 1: Here is how you create a class in the class browser with a return value



Step 2: We write some code that uses the class and WOW even intellisense works and we are able to find the method we created.



Step 3: Now the tricky part to figure out the return type. Lets use a couple lines of code and the command window for this complex task.



I am really glad I could help solve this mystery!

All the years I have been developing applications, return types has NEVER been a huge issue in the code I wrote. I would go into LINQ with the VAR return types or better yet the really screwed up anonymous return types in C#, but those came out after his article was posted and unlike the author I want to be "FAIR" in my analysis.

Functionality not available in FoxPro, damn why doesn't he mention core functionality not available in Visual Studio. Like a data centric language or a web form designer that freaking works or property sheets that function correctly. Shouldn't we be a bit more concerned about core features that are missing!


For example, lack of proper meta data is one reason there aren't any decent Web Service tools for VFP (and COM) because neither can generate type information on the fly just by looking at the objects. This is why it's so damn difficult to Interop with a Web service that exposes objects or even worse create one that publishes objects.


Meta Data in Visual Studio, this one I struggle with a bit, it is almost as bad as calling .NET a framework. When I think of meta-data, I can see how the compiler can extract type information and use it in C# fair enough. But in my mind a robust Meta-Data implementation is more along the lines of Visual FoxPro's VCX and SCX tables, where we have actual data that we can manipulate and extend prior to build time for some automation or designer functionality not only for intellisense. Yeah I know there is a layer we can hook into with Visual Studio to pull off some of the same things, but that is a bloated convoluted mess to work with making it not even worth the effort. Further like everything Microsoft does in Visual Studio that is a moving target as well. I believe they just released yet another RC or CTP called the MEF framework.


And you can get that same FULL information about an object instance, or type at RUNTIME. VFP sort of lets you do some of this, but it's very half hearted. The proof of this half-hearted design is Fox Intellisense which doesn't work properly most of the time because VFP doesn't have enough information to give you full information about a type.


Visual FoxPro is half hearted and doesn't work properly again but yet again not a single example of where this is occurring and Visual Studio is freaking perfect right! These Cheerleaders/Muppets will do or say anything won't they!


In closing:

This f'ing Visual Studio Muppet's post took bullshit to an entire new level. In his post he is praising more work caused by strong typing and Visual Studio while wrting about VFP'S half hearted implementation. WTF!!! On behalf of the Visual FoxPro Community, we want to thank you for dissing the tool that some developers are still making a living with!

Further what is wrong with making the compiler a bit more intelligent so we don't have to hand code the types as much or how about an opt-out option for strong data typing in C#. You are thinking, Mark that is not possible. Sure it is, VB.NET has an opt-out feature and let's consider the following example.

LOCAL pcTemp
pcTemp = ""
pcTemp1 = ""

We have a scope of local so the compiler can easily pickup on the fact it is a variable, further the first value assigned to the variable is set to a string so the compiler can also derive a type of string. pcTemp1 is not scoped so the compile could pick up on the fact there is an unscoped variable in the code. Does this have some holes, maybe, I gave it 30 seconds of thought. But the point is, there are ways to get around issues and make life a bit easier on programmers. Let the tool handle the majority of cases in an eloquent fashion and let us code out the exceptions NOT force us to code out everything because tool developers are too lazy to think!

Anyway.....

I hope everyone has a happy holiday...

Until Next Time...

.Mark

Monday, December 13, 2010

Separating from Concerns - Stop Using Visual Studio Is One Option


The MVC cheerleaders and Scott "THE DOT" GU make a big deal out of separation of concerns like this is some great break through. This is nothing new or anything to get excited about we have been easily pulling this off in Visual FoxPro for years through N-TIER and so has rails through MVC.

Now some of you maybe thinking VFP wasn't a web-tool, actually it can be used for web development which is out side the scope of this blog post but I used the same VFP middle tier classes in classic asp applications and in desktop lan applications. But more importantly if you understand design patterns then you would realize, it should NOT matter what the UI is, who cares, if it is a webform, winform, a service or mobile device. It is Microsoft's inability to build a productive tool which is the only reason this is a concern.

If Soma and the boys at Microsoft would have followed an N-TIER thought process and included a "HEAVY DUTY" class browser and focused developers on building a code repository that could be used across any UI seamlessly with VS containing an open source code generation layer that handled all the plumbing code NOW that would have been a "GREAT" tool.

The part that frustrates me, yes even more than standing next to an Indian at a public defecation pool with a bad case of diarrhea, is how close FOXRPO was to accomplishing this feat. If they would have added a form base class of type webform it would have worked. I actually often thought of doing just that and have it churn out the HTML and CSS based on classes. Damn I should have Soma's job lol.

Instead Soma and Microsoft got off on this tangent of composite UI controls and never ending layers of bloat, combined with bastardized paradigms that require a vast amount of "more" work then legacy Visual FoxPro did to "separate concerns" which is highly concerning.

I believe MVC separation of concerns is based more upon a flaw/lack of understanding with regards to Webforms, competing with ruby and implementing a "new" but copied design pattern then really "FIXING" the design pattern problem which is deeply rooted in Visual Studio and .BLOAT.

I will get off my soapbox and further explore Visual Studio's MVC separation of concerns.

N-TIER patterns are one way developers could "truly" separate concerns, here is a quick refresher on how this works.

The UI Layer - Handles user input and sends and retrieves data to the business layer.
The Business Rules Layer - Validates information, performs processing and connects to the data access layer to send and retrieve information.
The Data Access Layer - Is responsible for connecting to the data source. In some cases this is a base class for the business rule class or can be a separate layer in the event we need the ability to use different back-end databases such as My Sql, FoxPro, Sql Server, Oracle etc...
The Database - This is merely My Sql, SQL Server, Oracle, Access, FoxPro etc...

N-TIER is linear: UI hits the middle tier and the middle tier hits the data tier.

With MVC the tiers are triangular, views hits the controller and model and the controller hits the model. Even thou it is a triangular pattern that still doesn't mean we should not be concerned with code reuse.




In Visual FoxPro given it had a "functioning class browser" it was very easy to assemble these layers and setup a class "tree" hierarchy. Developers only had to concern themselves with application code and there was a "true" separation of concerns. Fox developers weren't not concerned with writing plumbing code or dealing with framework syntax that is more bizarre then crossing an intersection at rush hour in India.

With Visual Studio the class browser is mainly a nice looking UI plumbing code template generator that functionally does absolutely nothing mentionable. The VS class browser is unable to visually subclass UI controls amongst other things, in short, it is just about as fast to build your Visual Studio classes by hand in notepad.

If you want a more in depth comparison here is a link regarding the UI layer and class browser with code samples. When I went back and reread that post it is amazing how consistent I am which is more then I can say for some cheerleaders.

Now that we have a basic understanding of how concerns can be separated and the difference between VFP'S class browser and Visual Studio's want-a-bee class browser implementation lets explore what happens in an MVC application.

In the UI Layer of MVC we end up with some nice HTML, if we are good little coders. Next we have to inject the data access, business rules and validation to make the html do something productive, unless of course we are Scott "THE DOT" Glue then making it do anything that may reveal the truth of how messy VS MVC is, well, lets just say is out side the scope of his specs.

In most "GOOD" applications when the user tabs out of a field we should give some feedback to let the user know if their input is not valid. This is where separation of concerns falls apart with Microsoft's MVC implementation. In MVC field level validation is pulled off by using Javascript, Jquery and alligator script syntax etc... bloating the hell out of our NICE html or we could use the the range attribute property of EF (which I discussed in a prior post). If you are sharp, you should immediately see we have already lost our separation of concerns and the code is "NO LONGER" dry.





Despite what the MVC'ERS are bragging about here is what is "really" happening in the controller code with most applications I looked at in the field and sample code written by cheerleaders. The controller becomes this massive bloat of spaghetti code combining data access, linq, business rules, authentication and data sets with varying degrees of duplicated code in the UI. Worse yet the code is further duplicated from controller to controller and also into the web services because developers are NOT using "true" OOP design patterns.

I found a brief video that helps explain this point a bit more, enjoy. :)



There are several reasons why I believe this happens:

Microsoft ignored the model layer in their paradigm making it difficult to work with and now they seem to be forcing EF as the model layer, good luck with that one. Some developers haven't worked in C++ or VFP therefore don't have a firm grasp of OOP programming concepts or design patterns and fail to setup a good class structure if they use any class libraries at all. They merely are following some false hope and Microsoft marketing efforts to make them believe because a controller layer is involved in their application they are following OOP design principles and therefore their concerns are separated.

Anyway lets look at some code shall we, that may help...



This was pulled right off the blog of a Visual Studio cheerleader to validate a login in MVC.

Here is a very real world scenario.

A programmer is working on a site and "googles", log in validation + MVC, they find this sample with some documentation and implements it. The blogger is an Indian MVP from Microsoft so he has to know what he is talking about right? - come on do you really think this doesn't happen? My good friend Soma was blogging about script junkie, trust me this shit happens all the time!

A few minutes later, cool, the site is working, users are getting in and some users are denied access. The developer is happier than a two-dicked billy goat and thinking wow those cheerleaders f'ing rock man!

A month later they receive a request to add in a web-service to this web app that requires a username and password before it can return some data. So the programmer cracks open VS/.BLOAT then armed with C# and a KB article works some magic and the web-service is working.

I think you can see where this is going, we have validation crap in the controller, the html and a web-service.

And folks I will say it again this unfortunately is "REAL WORLD" stuff. This is how quickly an application turns into bloat because a "true" design pattern was not implemented from the get-go.

Don't worry I get it, you been brainwashed into thinking webforms controls are bad due to viewstate and extra lines of code VS injects into the html along with losing control over the id's then there is also the postback issue etc... but isn't the real solution to fix webforms/VS? Isn't using the code behind to bind up a list view and act as a bridge between the middle tier and UI a "workable solution" to a bad situation when it comes to separating concerns? If the web-forms code behind is merely calling classes in a middle tier how is that not separating concerns?

Some closing thoughts.

Look there is nothing wrong with MVC as a pattern, the issue is Microsoft's tools are lagging behind the technology (debugging, intellisense, class browser etc) and what Microsoft's final MVC implementation will be like is anyones guess, if it even makes it to maturity. Companies have spent an enormous amount of time and money jumping on the MVC bandwagon early and now stuck supporting some really ugly code.

Many cheerleaders are hyping this technology simply because it is new and "cool" and that type of bullshit doesn't do anyone much good. Pick technologies because it serves a purpose to your development efforts not because it is cool or because "DOT GLUE" or some freaking cheerleader says so. Using MVC doesn't mean separation of concerns, you still need a well planned out class structure or you will just end up with spaghetti code in a new framework.

Webforms is a mature product that will be around for a while don't dismiss it on a whim, it could end up saving you a significant amount of development time.

That is enough for today.

Happy Coding!
.Mark

Thursday, December 9, 2010

The Death Of Foxpro and the Birth Of the Entity Framework - another CTP anyway

There was an estimated 500,000 FoxPro developers at FoxPro’s peak around 1995, and millions of computers with FoxPro apps running (either DOS or Windows based) according to Ken Levy’s Blog. Still Microsoft in their ultimate wisdom- or lack thereof- killed VFP to force developers into the .Bloat/Visual Studio environment.

Today Scott “The Dot Glue” is hyping AND spinning EF CTP 5 on his blog. Instead of my personal rants about how bad EF is, let’s take DOT Glue’s own example code and rip it to shreds with” code first” and see the future and the past to determine if we are really better off by comparing the EF to VFP.

After all “Source Code Doesn’t Lie”…

The Entity Framework CTP 5

Step 1 Model Class and DB Context classes.

Actually we have to build up the tables first, just a minor detail...

So let’s see what these model classes look like...

Public class Product
{
Public int productid { get; set }
Public int categoryid { get; set }
Public string productname { get; set }
// WTF is up with the ? talk about an after thought…
Public Decimal? UnitPrice { get; set }
Public Bool Discontinued { get; set }
public virtual category category { get; set }
}

Now we have to jerk with the category table class

Public class category
{
Public int categoryid { get; set }
Public string categoryname { get; set }
Public string description { get; set }
public virtual ICollection Products { get; set }
}

Public virtual is one of the bullshit commands that Microsoft loves since it struggles to do anything that is straightforward in Visual Studio. Basically we have two tables or collections, products and categories and there is a relationship between the two that is lazy loaded so EF needs a property for some screwy reason.

Now we need to create a data context – No I am not shitting you

Public class northwind : dbcontext
{
public dbset Product {get;set;}
public dbset Category {get;set;}
}

Side note: You need less then and greater than signs around the table names. The blogger editor stripped them out.

Thanks goodness THE GLUE doesn’t use any real world examples I would spend hours hand coding the classes.

Step 2 Configure the connection string

No big surprise a connection string in the app.config, if vfp was accessing a sql database we issue a sqlconnect no biggie either way.


connectionString="data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|\northwind.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />


Step 3 Pull a collection from EF

DOT GLUE used linq in this example

Personally I hate the linq syntax it is sort of like reinventing the wheel and building a CUBE instead of a circle.


NorthWind Northwindw() = new NorthWind();

var p = from p in northwind.products
where p.category.categoryname = “Beverages”
select p;

Step 4 an EF update

NorthWind Northwind() = new NorthWind();
Product.Product = northwind.products.find(1);
Product.UnitPrice = 2.33m;
Product.Discontinued = false;

// this is where the VS Cheerleaders have an orgasm and praise gu!
Northwind.SaveChanges();

NOW Let’s run through this same example in VFP

Yes no class code or data context required.

For humor sake if we wanted a record object it would look something like this.

Select product
Scatter name oProduct blank
Select category
Scatter name oCategory blank

Yes that is correct in Visual FoxPro we use two lines of code no cryptic syntax no virtual relationship command. Even more important if the base tables structure changes no change is required to the code.

Next The Glue built a collection using linq… a cursor will work just fine in vfp.

Select * from products
inner join category on products.categoryid = category.categoryid
where categoryname = “Beverages” into cursor p

That looks familiar Native SQL in VFP sweet! Yes the same syntax can be executed against a sql database using sqlexec. This is important makes sure you read my closing comments with regards to sql commands and ef!

Perform an Update

Select product
= seek(1) // This finds a record

Don’t even complain about what happens if the record is not found THE GLUE didn’t handle that case either. Yes we could add the workarea and index into the seek command and use one line of code instead of two.

Scatter name oProduct
oProduct.UnitPrice = 2.33m;
oProduct.Discontinued = false;

// this is where VFP developers should be laughing at EF as we have been saving records with one line of code since foxpro for dos.
Gather name oProduct

Is it just me or are you having a WTF moment as well.

Folks Microsoft killed Visual FoxPro and now we have the entity framework don’t you love progress Microsoft Visual Studio style!


EF Validation

Next THE GLUE blogs about two property attributes: range and required. My first instinct when I read this was that is pretty cool. Then I sat back any thought about it for a minute and SAID this is bullshit and here is why.

If there is a UI involved the range and required validation should occur in the form! Now you are thinking yeah Mark you missed the case of a web-service and reusability. Fair enough but wouldn’t it be better to catch this in the business layer object of the middle tier and avoid a round trip to the server and connecting to the datasource etc- after all you die hard performance based MVC guys are worried about view state in the HTML being downloaded from the server slowing things down you should crap yourself if you have to load the EF data context when it isn’t needed.

Ironically in the next paragraph THE GLUE discusses Keeping things DRY





The “DRY Principle” stands for “Do Not Repeat Yourself".

Don’t you wish Microsoft came up with this idea with regards to the .NET FRAMEWORK that is all redundancy or how about 6 different Datagrids and list views and isn’t there two different View Engines for MVC. Better yet how about all the different flavors of Vista ... What an Joke!


The GLUE wraps this post up by getting us excited about other improvements

1) EF Code First CTP5 exposes a new set of change tracking information that enables you to access Original, Current & Stored values, and State (e.g. Added, Unchanged, Modified, Deleted). This support is useful in a variety of scenarios.

Well this sounds like VFP GetNextModified and GetFldState to me nothing new there.

2) EF Code First CTP5 now allows raw SQL queries and commands (including SPROCs) to be executed via the SqlQuery and SqlCommand methods exposed off of the DbContext.Database property. The results of these method calls can be materialized into object instances that can be optionally change-tracked by the DbContext. This is useful for a variety of advanced scenarios.

By advanced scenarios does THE GLUE mean cases that Linq to entities can’t handle or does linq to entities perform so poorly under some instances you really should use an SPROC? Regardless this was available years ago in VFP in the native VFP SQL statement and does SQLEXEC sound familiar to VFP developers?

THE GLUE writes in conclusion, EF Code First provides an elegant and powerful way to work with data [OBVIOUSLY HE NEVER USED A DATA CENTRIC LANGUAGE BEFORE LIKE VFP]. I [“THE GLUE”] really like it because it is extremely clean and supports best practices [IS THERE REALLY SUCH A THING AT MICROSOFT AS BEST PRACTICES WHEN TECHNOLOGY AND PARADIGMS ALMOST CHANGE DAILY?], while also enabling solutions to be implemented very, very rapidly [THIS HAS TO BE A TYPO]. The code-only [HE NAILED THAT ONE THERE IS A TON OF CODE IN VISUAL STUDIO APPLICATION DEVELOPMENT AND NOT MUCH RAD] approach of the library means that model layers end up being flexible and easy to customize….. [OH REALLY WE MAKE A CHANGE TO A DATA STRUCTURE AND LETS SEE WE NEED TO RECOMPILE THE EF AND CHANGE ALL THE CLASSES REAL FREAKING EASY]

I think it would behoove THE GLUE to use VFP for a while before writing a blog post as according to my blog post there is nothing new or elegant based on the sample code Scott GU is blogging about when using the Entity Framework. Obviously VFP should be the winner but even if you want to give the THE GLUE the benefit of the doubt, look there is not a thing in this example that is new or different at best this example is on par with VFP technology.

The funny part is the GU is getting praised on his blog for EF when it is doing nothing but causing more work and I am sure a few cheerleaders will flame me for pointing out just how bad the new EF technology really is…. And here I am trying to make their jobs easier by suggesting Microsoft builds (for you anyway - I went open source for all new web projects) development tools that work!

When all is said and done aren’t you glad source code doesn’t lie!

Until Next Time

Happy Coding!

.Mark

By the way in case you are interested here is the link to the no confidence petition for the entity framework started by several MVPS.

http://msmvps.com/blogs/peterritchie/archive/2008/06/25/entity-framework-petition-of-vote-of-non-confidence.aspx

Monday, December 6, 2010

Micrsoft the Next IBM

I checked out Scott "The Dot Glues" blog and he posted websites with great tips to do this or the other thing with Visual Studio and .BLOAT. For lack of something better to do I clicked on a couple links and found pages of steps and tutorials on how to do stuff with Visual Studio.

The first thought I had was, Scott "The DOT GLUE" doesn't get it! If in order to use a software development tool it take approximately 50 links on you blog and pages of tutorials to scratch the surface of steps required to make a tool perform tasks that should be native to the tool set, the software development tool FAILED! Given all the classes and bloat in the API wrapper classes known as the .NET framework that framework should do it all.

The issue is, .NET is NOT a FRAMEWORK, .NET's classes for the most part are merely wrappers over the operating system API much of which is still based on "LEGACY CODE". .NET is a mish-mash over whatever Microsoft has laying around or what some team is using at this moment.

I still can recall when YAG wrote the codebook for VFP. In approximately 200 pages with pictures you could have an application up and running with a pretty good idea of the basics of Foxpro. When was the last time you saw a visual studio book which was 200 pages long that explained this tool. It takes 200 pages just to unwind the freaking app.config and global.asax files.

Even with all that bloat, multiple frameworks and software involved in Visual Studio and blend you know, other then netflix I can not even think of one mainstream website or application for that matter written using Visual Studio and .BLOAT that is considered "cool".

On the operating system front Windows XP is the release when Microsoft finally got their os right, only to destroy it with Vista (gee that sounds familiar they did the same thing with Visual Studio after 6.0 was released). With Windows 7 I don't see any great adaption occuring. Window 3.11 and Windows 2000 were the last OS that had any big fanfare.

In the development tool arena Visual Studio 6.0 was the last good tool set that wasn't a bloated bug ridden mess. With MVC I actually get physically ill when I look at how far Microsoft's MVC implementation has managed to set software development back in terms of productivity. Perhaps only punch cards was more unproductive to use. Those cheerleaders that state we need to "get close to the metal" as justification for MVC are full of themselves and should spend more time deflating their overblown ego so they can drift back to reality instead of blogging. Here is a thought you want to be a real programmer then code in assembler so you can get real close to the freaking metal. Congratulations to Microsoft for splitting their own deveopment community.

On a side note ... Can anyone answer a couple questions, what is so freaking hard about building a webform designer that works? Damn this thing has been out forever and still unstable. I maybe could see a page rendering differently in firefox but IE doesn't even render correctly and Microsoft owns the browser's source code WTF? Further why can't anyone develop a class browser for VS that allows you to visually subclass UI controls? Even VFP could do this! Microsoft and the Cheerleaders love using the term OOP with visual studio but I seriously doubt the cheerleaders even understands what OOP means anymore. Soma or DOT GLUE do me a favor talk to Calvin I am sure he can help you with the class browser and explain to you why classes are important even at the UI level. Yeah I know you can hard code classes but this is supposed to be "VISUAL" studio not notepad with intellisense.

Anyway . . . .

Browsers: Internet explorer sucks balls each version has it's own set of hacks to get a webpages to render consistently across versions. Here is a hint for the IE team. FireFox is open source look at the code to see how to make a page render the same regardless what version of the browser you are using, you guys at Microsoft are great are stealing stuff go with what you know.

Websites: Live is dead. Bing is worthless and MSDN does anyone still use it. Not a single showcase website written by Microsoft. Sure there is Nerd Dinner that is a freaking showcase site and under a million lines of code .... How cool is that?

Office is still a good tool but the office team uses their own libraries and avoids .NET like the plaque.

SQL Server: I do miss using it on a daily basis, that is the one development tool Microsoft is yet to screw up.

Now we have the cloud coming. Which 95% of the average people are clueless what it does and for everyday users it serves no purpose. Again this is a business level technology which I struggle to see how businesses would be willing to turn over their data and files to Microsoft. My prediction, the cloud will have as much longevity as Microsoft BOB with the only exception being a few companies who see it as a way to eliminate some network cost.

I truly believe Microsoft is headed down the road of becoming the next IBM they have totally lost the "coolness" factor! If you dare question this logic here is a brief story.

I went shopping over the weekend to buy my grandson an IPOD for Christmas, my first stop was best buy. I looked down an aisle where Microsoft software was shelved then moved to the computer aisle there was no lines or enthusiasm people just stood blank faced while looking at the pc and the wore out windows paradigm like it was an AS400 mainframe.

I left and went to the mall, I walked into the apple store and it is packed with people, most of them were playing with apple technology or visiting the cool genius bar. People were calling ahead for reservations to talk to a sales person and exchanging ideas, in general they seemed excited about technology.

While waiting to make my purchase I had a vision of what it would be like if Microsoft had a Windows Store. There wouldn't be any employees at Microsoft's genius bar but video chat to Microsoft India where the support people would wear red polo shirts and ask you call them Bobby, Sally, Billy, Dick or Sue. Once you pose your question they would read a KB article to you, painfully detailing each of the 185,232steps required to upload a picture from Windows through the cloud to your facebook page, then assume you are an idiot for missing one of the steps which of course caused the process to fail and you have to start again. Moveover in the background you can watch them argue with each other over which way is the best way to upload your picture since of course there would be 531 ways to perform an upload and none straight forward. The mood in the Microsoft store would closely resemble a DMV office. The monitor above the bar, that displays the waiting list, would show the blue screen of death because a server in the cloud experienced a C0000005 fatal exception due to having the wrong version of the .BLOAT framework installed.

I suppose that is why Microsoft doesn't have stores, Ballmer is smart enough to have the same vision as mine, unfortunately he is not smart enough to fire the entire Visual Studio/ .NET management team then scrap Visual Studio and start over. Unless he is concerned that everything Microsoft does is worse then it's previous release, a lesson learned from vista.

After picking up the IPOD, I hit the wireless shop next. There stood the Windows 7 phone display, I looked at it for a moment but any interest I had in the phone was quickly lost when I thought of Visual Studio then proceeded to the android section where I ended up walking out with a 4g droid phone so I can "play" with mobile software development. Yes folks the ripple of effect of Microsoft Visual Studio even affects their phone sales.

Until Next Time.

Happy Coding and Think Open Source!

.Mark

Thursday, March 5, 2009

Source Code Doesn't Lie #4: UI Framework Layer

The source code challenge creating a UI framework layer

The Winner - Visual FoxPro

Score card through 4 coding challenges:
The Legacy Visual FoxPro 4
The Great Visual Studio 0

--------------------------------------------------------------------------------------

Let’s start with a brief overview of what N-TIER design entails.

An n-tier application is one where the application is split into logic sections. These sections are the user interface tier, the middle tier where the application business rule along with data access programming resides and the data tier (the database). While all the tiers may reside on one or two computers or servers this model allows the application to be “scaled” to improve performance. In other words the user interface may reside on the client’s workstation or in a browser, the middle tier could utilize its own application server and the data tier would have its own server.

There are numerous benefits to this programming model besides scalability, for example the same middle tier and database can be accessed by both a web based interface or a client application interface. This means all the middle tier code and the database is shared instead of writing the code twice. Moreover a framework can be implemented to further reduce programming by creating a baseline of generic programming (classes) which the application is based upon. By employing a framework in conjunction with N-TIER design patterns we are able to create an application that is scalable, easy to maintain and provides a consistent programming model for maintenance along with a consistent user interface.

The most common mistake a programmer (and Microsoft for that matter) makes when trying to implement this design pattern is to place code that really belongs in the middle tier in the user interface tier or to access the database directly from the user interface layer.

Now that we have a basic understanding of the N-TIER model let’s move to implementing the classes that would be required by the user interface layer for a Visual FoxPro application and a winform application. I must be in a good mood tonight as using Winforms will paint Visual Studio in the best light. Microsoft royally screwed this model up in WPF and a comparison with Visual FoxPro would not even be close in terms of code and ease of implementation. On a side note: Yes they failed with Webforms and MVC as well .

Are you ready to develop a framework UI layer at light speed with Visual Studio 2008 and .BLOAT?

The first step is subclass the native development controls into a UI framework class. To keep things simple we will subclass a form, label and textbox class. Let’s start with Visual FoxPro, this step requires zero coding we simply use the class browser. As you see in the screen shot we have a base UI framework layer that is ready to use in our application. This took less then a minute to build.





















Now let’s perform the same task in Visual Studio. First off you can’t subclass UI controls in the class browser therefore we have to hand code each class. In order to save some code in Visual Studio - which I really freaking shouldn't - I will exclude the code necessary to workaround bugs that are related to setting default proprieties in the subclass that get jacked by the property sheet.

Now here is the Visual Studio Code that was NOT required in the legacy Visual FoxPro base framework layer.

//FOLKS: This is the Microsoft money section it forces your client to use the windows
//operating system. Steve and Bill count the dollar signs each time they see a
//USING system in your code.
using System;
using System.Text;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;

namespace UILayer
{

//Since VS doesn't have a class browser that works
//or an ide with code windows we need regions to keep the code manageable
#region forms

//Why in the hell do I have to add an attribute to my class that
//tells the great Visual Studio what icon it needs to display in the toolbox for the class?
//
//The ide freaking knows it is inheriting from a textbox. It should display a default
//textbox icon then allow us to override it as needed.
//
//In VFP a property sheet could have been used and no coding would be necessary

[ToolboxBitmap(typeof(System.Windows.Forms.Form))]

public class SampleForm : Form
{

public SampleForm()
{
}

}
#endregion

//Blah, Blah Blah the same crap not exciting but it is code we should not have to write!
//All that should be required is us setting proprieties and the business logic.
// yes this is plumbing code!

#region textboxes
[ToolboxBitmap(typeof(System.Windows.Forms.TextBox))]
public class SampleTextBox : TextBox
{

public SampleTextBox()
{
}

}
#endregion

#region labels
[ToolboxBitmap(typeof(System.Windows.Forms.Label))]
public class SampleLabel : Label
{

public SampleLabel()
{
}

}
#endregion

}


It is obvious FoxPro requires less work as the more we keep adding to this model the worse things get for Visual Studio. Adding methods, proprieties and inheritance are all done in the class browser visually with the legacy FoxPro and using the Microsoft's Latest Technology Visual Studio 2008 with 70k class of bloat in .NET this it is all done in code.

If this nonsense was not bad enough; let's say for example you decide to use the wizards in Visual Studio instead of using subclasses, guess what happens? (Don't think this wizard code is not used in the field I see it all the time in applications). Anyway back to my point guess what occurs, I will tell you, a WTF MOMENT occurs - that is what. The visual studio wizards embeds data access code into the user interface layer, not only do we lose the value of inheritance and have duplicate code everywhere, the foundation of N-TIER design is broken by code generated by Microsoft!

Even the Visual Studio Cheerleaders will try to spin this extra work as a positive, below is an excerpt from code magazine…

“...Subclassing the base .NET Windows Forms controls is different from VFP because developers must write code to do so. You cannot subclass visually, but the process will provide good exposure to the language and the .NET Framework.”

What the hell are they talking about, they can't think we are that stupid - Let's read it again -

“...Subclassing the base .NET Windows Forms controls is different from VFP [hell yeah it is it is alot more freaking work in Visual Studio] because developers must write code to do so [which in any worthwhile tool we shouldn't have to]. You cannot subclass visually, [no shit thanks for pointing out the obvious, they should have mentioned due to the fact the visual studio class browser sucks] but the process will provide good exposure to the language and the .NET Framework.”

Yes I read it correctly, they wrote "this process will provide good exposure to the language and the .NET framework" - are they freaking joking me?!?!? Here is what I have to say to the code magazine Visual Studio cheerleaders “SCREW THAT”. This is a major bug in Visual Studio call it exactly what the F&$K it is!

I hate to do this I really do, but we have to dig deeper into this idea of "providing good exposure to the language and the .NET framework".

First off I need to ask this, how many freaking times during the application development process do we need to WASTE time getting "good exposure to the language and the .NET framework". WTF - With all the code we have to write in Visual Studio do they think we are going to forget? There is less typing involved in a Mavis Beacon teaches typing dvd. This is a perfect example of what I have been saying all along folks, cheerleaders will do or say anything to hide the truth of Visual Studio.

Secondarily please stop calling .NET a framework. .NET is NOT a framework. For the most part Microsoft took the Windows API layer and wrapped it in classes - that is all the majority of .NET is. Moreover a portion of .NET is based on outdated legacy technology that has been around since early version of windows, yes before Visual FoxPro. There are basic principles of framework design: I will pick 2 general ones everyone can understand, a framework should eliminate code redundancy and a framework should provide a consistent way of coding. How in the world do we have a consistency in .NET when there is class redundancy everywhere, for example we have 6 bad ways of accessing data alone, that is not eliminating redundancy that is BLOAT! If .NET fails the first two general tests required to be considered a framework then it is not a framework!

Getting back to their quote "good exposure to the language and the .NET framework", If we apply their logic for minute to a car, would anyone want to push a freaking car instead of drive one because the car maker failed to design the engine correctly? Your answer would be NO - but a cheerleader would say that is fine because it would provide good exposure to fresh air. Yes, this is as freaking unbelievable as it sounds, and that is the idea they are trying to sell us on.

The bottom line is Visual Studio is so bad and unproductive it can not be defended using rational arguments so cheerleaders invent crap like "exposure to the language". The pathetic part is, believe or not, these people (and I purposely left out their name) are good programmers, why they insult their intelligence time and time again for Microsoft and Visual Studio is mind boggling? Here is a thought, they want to help the Visual Studio community, then in their next issue of code magazine demand Microsoft give us tools so we can get our work done in the most productive way possible, freaking get some balls and point out the bugs. Look, if you don't have the balls to speak the truth for fear of biting the hand that feeds you, just direct your readers to my website and I'll do it.

I will break down what I think transpired, Microsoft was smart when they issued the end of life of Visual Basic and Visual FoxPro in this respect. Before Microsoft killed these solid products Microsoft grabbed the more respected cheerleaders in each community and promised them 75 virgins besides Vista Ultimate to spin Visual Studio. Microsoft was betting that the Visual Basic and FoxPro development community would blindly take the advise of community leaders and just follow along. (Well it wasn't the virgins, actually most got offered jobs in Redmond then disappeared into the woodworks-I should find Griver's letter to the VFP community on the end of life and analyze that to prove my point) . Then with the Visual Studio community, Microsoft didn't want non-microsoft employees leading the development community so they created the Microsoft Evangelist network, these are the A-team cheerleaders that spin visual studio. You know what, sadly for us, this plan worked perfectly. Developers are listening to the cheerleadering squads, which is exactly why we are stuck with this crappy bloated bullshit platform to write applications with. I have said it all along Microsoft may not release the best software (With Vista and Visual Studio I'm being nice) but they are smart when it comes to business.

Ok I will get off my soap box, well there you have it another code challenge and Visual Studio lost again to Visual FoxPro. It is time to move off the class browser, inheritance and User Interface Layer for the time being as the Visual Studio suck factor is obvious. In the next installment of source code doesn't lie I will put LINQ-TO-SQL up against VFP'S native data centric language. Perhaps we can develop at light speed when creating middle tier components that perform basic business processing.

By the way if you haven't checked out the Ms. Fox Pro (Ms. means female not Microsoft) video, do so, it is posted on my blog and also my facebook page.

Until next time, be productive Developing at Bloat Speed!

.Mark

Sunday, March 1, 2009

Weekend Update: Dot Net Chick VS Ms. Fox Pro

I was thinking today, what if Apple bought FoxPro instead of Microsoft? Given there was a FoxPro for Mac version it might have been possible. I'm sure Apple would develop a "simple" way to port my code over to the iPhone without a complete rewrite. My application would also run in any OS instead of being "used as bait" to feed the Microsoft monopoly by locking my clients to Windows through .BLOAT, you know the OS api wrappers Microsoft and the cheerleaders spin as the .NET framework.

More importantly, if Apple would have bought FoxPro just think what great commericals Apple would have made to actually market FoxPro something Microsoft failed to do. Wouldn't it be cool if Apple would have followed a similar Mac vs PC format. Instead of the PC and Mac guy we had the DOT NET chick vs Ms. Fox Pro, like in the video below, I wonder which one you would perfer to take you where you want to go today?

Definately check it out!



Like everything there would be some downsides to Apple owning FoxPro, I would have to find some hobbies to occupy my free time. You know the time that I now waste writing tedious nonsensical Visual Studio "plumbing and glue code" that wasn't required in legacy technology, and working around bugs in LINQ for example when used in the middle tier

Unforunately, I snapped back to reality only to look down at the Visual Studio IDE and thought life can be a real bitch sometime!

In closing, later this week I will be releasing my next installment of Source Code Doesn't Lie: The User Interface Layer. You want to be sure to check it out!

Until then have fun and "Develop at Bloat Speed!"
.Mark

Friday, February 27, 2009

Source Code Doesn't Lie #3 - The Visual Studio Class Browser

The heart of any object oriented application development should be the class browser. While there are numerous benefits to following object oriented design patterns, the two benefits I want to discuss are inheritance and programming code reuseability. Given there are few things in life that suck less then the Class Browser found in Visual Studio (well .BLOAT does come to mind to think of it), it defies logic why the Visual Studio Class Browser has not been corrected.

Before moving to looking at the class browser lets review a simple example of how inheritance works.

Lets say we have a base class called "vehicle", and this base class has certain functionality (methods) such as "Turn on Engine", "Turn Off Engine", "Make Vehicle Go", "Make Vehicle Stop", "Motor" along with some properties that tell us what is happening to the vehicle: "Are headlights On", "Is Motor Oil Full", "Are Seat Belts Fastened" etc....

Next we are going to build a benz and a septic tank truck (class). Instead of building these classes from scratch we can start with the vehicle class and subclass it. By doing so we gain access to all the functionality found in the original vehicle class and we simple build upon it.

By writing code in this manner we know the foundation is stable and tested i.e. the vehicle class. Besides that let's say we come up with a new property like "Is Transmission Fluid Low" instead of adding this to both the benz and septic tank truck we only need to write the code into the vehicle class because the benz and septic tank are inherited from the vehicle class, this new property is there and ready for us to use. Neither the benz or septic tank truck have to worry about everything going on behind the scenes to make "Is Transmission Fluid Low" work.

So it should be clear why this is a great programming model and a huge time saver.

The purpose of the class browser is to allow us to work with these classes in a "productive" manner. Now let's compare the legacy Foxpro's class browser to that of Microsoft newest technology advancement, Visual Studio's Class Browser, to see if perhaps we can Develop at Light Speed using Visual Studio and maybe Microsoft's slogan for Visual Studio is correct.

Below is the legacy FoxPro class browser. It is the standard explorer interface. For the purpose of this sample I added a UI control and subclassed it to prove it could be done and to point out this is something that CAN NOT be done in Microsoft newest tool Visual Studio, yes this is a WTF moment! The reasons why this is important is for developing a UI layer in N-TIER applications. The other thing that is noteworthy in FoxPro's class browser, class inheritance is performed in the class browser NOT in code like in the great Visual Studio 2008.
















Double clicking on a class allows you to drill into the class browser code environment where you can create proprieties, methods and add programming code. With the legacy Visual FoxPro Class Browser you have a "productive" environment to get your work done. You have a property sheet that displays all the proprieties, events and methods for the class. Double click on the method in the property sheet you want to work with and a code window opens that only displays code for that method furthermore there is a "view parent code" button that brings up a window that contains the code in the base class for that method. Of course you have the option to export the class from the class browser to a file and work with the code outside the legacy class browser .




















Now lets examine the Great Visual Studio's Class Browser. It looks flashier then the VFP class browser but that is where the benefit, if that even is one, ends. It is entirely symbolism over substance. More importantly there is not a way to subclass the .BLOAT UI controls using the class browser, remember this is something the legacy FoxPro Class Browser could do.























After the class diagram has been constructed you switch to, what I refer to as, Visual Studio's DOS MODE and you are basically digging through code to do everything that needs to be done with the classes. Unlike the legacy Visual FoxPro's class browser, Visual Studio doesn't provide you with a productive code environment instead we are given a text editor with intellisense to maintain the code.

Below is the code the simple vehicle class structure generated that we have to maintain using Visual Studio 2008 glorified text editor.

using System;
using System.Collections.Generic;
using System.Text;

namespace sample
{

class Vehicle
{

public int IsOilFull
{
get
{
throw new System.NotImplementedException();
}
set
{
}
}

public int AreHeadLightsOn
{
get
{
throw new System.NotImplementedException();
}
set
{
}
}

public int AreSeatBeltsFastened
{
get
{
throw new System.NotImplementedException();
}
set
{
}
}

public void Motor()
{
throw new System.NotImplementedException();
}

public void TurnEngineOn()
{
throw new System.NotImplementedException();
}

public void TurnEngineOff()
{
throw new System.NotImplementedException();
}
}

public class Benz : Vehicle
{
}

public class SepticTruck : Vehicle
{
}

It should be clear the Class Browser in Microsoft's Great Visual Studio 2008 is about as useful to developers as an Indian Saris is to Jenna Jameson.

Now you are thinking Mark that only is your opinion of the Visual Studio Class Browser. But oh not so Markus Egger MVP, VS cheerleader and editor of code magazine wrote the following in his blog.

..."The class browser was the VFP workhorse tool, true. Especially in the early days of .NET I have often wished I had it, especially since OO is and always has been so important to me. I even considered writing one"...

To add insult to injury, with WPF Microsoft is moving away from this productive object oriented subclass programming paradigm for UI controls to the miserable XAML composition implementation. In a future post, I will explain in great and gory detail why Microsoft's decision to implement the WPF/XAML paradigm is misguided and flawed at best. Their decision can only be compared to deciding to spend Christmas in Iraq! As hard as it is believe the WPF tools suck even worse then what we currently have available to us in Visual Studio, I really didn't even think that was possible, but yes friends it is true leave it Microsoft to develop the impossible. Unforunately for developers in this case it is not a good thing!

I'm still trying to find out what Microsoft meant by "Development at Light Speed" in the context of the Great Visual Studio perhaps they are comparing Visual Studio to assembler? Maybe we will have more luck with my next post trying to figure this out...

The score sheet thus far:

Sample Application: Legacy FoxPro beats Visual Studio 2008 and .NET
Class Browser: Legacy FoxPro beats Visual Studio 2008 and .NET

Legacy Visual FoxPro: 2 points
Visual Studio 2008 and .BLOAT: 0 points

Maybe I should have used DOS Foxbase to compare against Visual Studio 2008 to give Visual Studio a chance.

Until next time let's all "develop at bloat speed" with Visual Studio 2008 and the 70k+ classes of the .BLOAT API wrappers.

.Mark

Friday, February 20, 2009

SOURCE CODE DOESN'T LIE PART 2: The sample application code in C#

If you recall in my prior post I wrote a small application using the outdated legacy development tool known as Visual FoxPro and I had to write about 26 lines of code to finish the application and it took about 8 minutes. The legacy Visual FoxPro code and application specifications are in the previous blog entry.

When I was assembling the C# code contained in this post, since neither Sam or anyone else wanted to even quote the application let alone write it, I was thinking of all these witty criticisms to preface the code. However I don't even need to say anything else as I truely believe the volume of code this application required, that Sam referred to as a "toy", speaks for itself.

Update 2/23/2009
I was reading through mini microsofts blog which is one of favorites and I found this quote I wanted to share with you as he defined visual studio, wpf, mvc perfectly!

"Going big and broad and trying to enter and dominate every possible software market is exactly what resulted in Microsoft having reactive and broad, shallow features that are rushed out lacking polish and usually lead to user frustration as the shallow experience putters out. "


Enjoy the show!
.Mark


Dot Bloat proudly present "Developing at Light Speed! "

Act 1: The Screen Shots To Prove The Code Runs!


















Act 2: The Source Code

Application Start Up Code
Code auto generated by Visual Studio to launch the application.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace sample
{
static class Program
{
///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

UI Form Code
The form designer code auto generated by Visual Studio

namespace sample
{
partial class Form1
{
///
/// Required designer variable.
///

private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///

/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(403, 371);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(479, 371);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 1;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
//
// button3
//
this.button3.Location = new System.Drawing.Point(556, 371);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 2;
this.button3.Text = "button3";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// dataGridView1
//
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(1, 27);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(630, 341);
this.dataGridView1.TabIndex = 3;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(128, 3);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(344, 20);
this.textBox1.TabIndex = 4;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 6);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 5;
this.label1.Text = "label1";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(633, 399);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.dataGridView1);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
}
}

The C# Code which was manually written for the form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//Sample data layer and generic file utilities class
using SampleDataLayer;
using SampleFileUtilities;
namespace sample
{

public partial class Form1 : Form
{
//Create a property to hold the dataset
DataSet oDataSet;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

//Note: I put the code to populate the grid in the form load event
//when developing this app and I forgot to move it to the populate
// button on the form. Therefore there is no click event code in the
// populate button and I'm too lazy to worry about it now - I do apologize.....
//
//This section of code could have been done using the property sheet
//Set the label captions
this.label1.Text = "Selected Filename:";

// Put the captions on the command buttons
this.button1.Text = "Get File";
this.button2.Text = "Populate Grid";
this.button3.Text = "Export Grid";
//Put a caption on the form
this.Text = "Visual Studio Sample";
//End playing with simple properties

//Create the data layer
DataLayer oDataLayer = new DataLayer();
//Create a binding source object for the grid
BindingSource oBindingSource = new BindingSource();
//We need to get a dataset so the grid has something to play with
//I stored it in a property just to make passing it around easier for clarity in the sample.
this.oDataSet = oDataLayer.PopulateDataSet("Select * from person.contact", "dsPersons");
//Now we need to bind the dataset to the BindingSource
oBindingSource.DataSource = this.oDataSet;

//Finally we hand the bindingsource datasource off to the datagrid
this.dataGridView1.DataSource = oBindingSource.DataSource;
this.dataGridView1.DataMember = "dsPersons";
}

private void button1_Click(object sender, EventArgs e)
{

// Create the save file dialog object
SaveFileDialog dlg = new SaveFileDialog();

//Populate the pull down list in the save file dialogue
dlg.Filter = "Excel Files (*.xls)*.xls";

// Show the box and ensure the ok button has been pressed
if (dlg.ShowDialog() == DialogResult.OK)
{

// Update the form with the name of file the user entered
this.textBox1.Text = dlg.FileName;

}
}

private void button3_Click(object sender, EventArgs e)
{

//Get a reference to the fileutilites namespace
FileUtilities oFile = new FileUtilities();

// Send the data to excel
oFile.ExportToExcel(this.oDataSet, this.textBox1.Text.ToString().Trim());

}
}
}

Yes keep scrolling down there is more code yet to come!

Data Access Class Code

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace SampleDataLayer
{

public class DataLayer
{

public DataLayer()
{
}

// For fairness in the comparision I used basically a simple read only data set.
// To send up to the form to bind to the grid.

public DataSet PopulateDataSet(String cSelectCommand, string cDataSetName)
{
//Create a data set that we can populate
DataSet ds = new DataSet();

//Establish the connection to SQL Server
//For the sake of this sample the connection string is hard coded
//in production applications the SQLConnectionStringBuilder would be used.
//The connection string was removed for security reasons
SqlConnection oSqlConnection = new SqlConnection("MyConnectionString");

//Create the sql command object
SqlCommand oSqlCommand = new SqlCommand();

//Tell the sql object what type of statement we are going to work with
oSqlCommand.CommandType = CommandType.Text;

//Pass the sql statement to the sql command object
//In a production application should set other properities such as the timeout etc.
oSqlCommand.CommandText = cSelectCommand;

//Bind the connection object to the sql command
oSqlCommand.Connection = oSqlConnection;

//Create a data adapter
SqlDataAdapter da = new SqlDataAdapter(oSqlCommand);

//Try Catch Throw structure should be used to handle errors
//But I didn't want to be accused of code bloating - Lighten up it was a joke

//Open the sql connection
oSqlConnection.Open();

//Fill the dataset
da.Fill(ds, cDataSetName);

//Close the sql connection
oSqlConnection.Close();

//Return the data set
return ds;
}
}
}

You are in the home stretch 150+ lines of code left! And remember it took VFP 26 lines of code....


Utility File Class Code

Note: The less than and greater than signs and slashes in this section of code was messing up the formatting of the blog. Those characters have been replaced with the word slash, lt and gt.
This code, with the exception of the patching I had to put in to extend the datatype support, was originally published on codeplex.

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace SampleFileUtilities
{
public class FileUtilities
{
public FileUtilities()
{
}

// Allows the dataset to be exported to excel
//
// Codeplex introduction
// This function takes in a DataSet and file name and writes the DataSet to an Excel worksheet.
//The code is pretty straightforward. Great thing about this function is that, it's technically an
//XML file that is saved as an XLS file. So it can be used as either file format. No more leading zero
//truncation on numbers that look like strings. Example, if you made a tab delimited file and put a field
//such as "00036" (a field that looks like a number but should be regarded as a string), MS Excel would truncate the leading zeros...
//This problem is solved with this method.
//
//I really enjoy the problem solved with this method - In VFP a single line of code SOLVES this problem

public void ExportToExcel(DataSet source, string fileName)
{
System.IO.StreamWriter excelDoc;

excelDoc = new System.IO.StreamWriter(fileName);
const string startExcelXML = "LTxml versionGT SLASH r SLASH nLTWorkbook " +
"xmlns= SLASH "urn:schemas-microsoft-com:office:spreadsheet SLASH " SLASH r SLASH n" +
" xmlns:o= SLASH "urn:schemas-microsoft-com:office:office SLASH " SLASH r SLASH n " +
"xmlns:x= SLASH "urn:schemas- microsoft-com:office:" +
"excel SLASH " SLASH r SLASH n xmlns:ss= SLASH "urn:schemas-microsoft-com:" +
"office:spreadsheet SLASH "GT SLASH r SLASH n LTStylesGT SLASH r SLASH n " +
"LTStyle ss:ID= SLASH "Default SLASH " ss:Name= SLASH "Normal SLASH "GT SLASH r SLASH n " +
"LTAlignment ss:Vertical= SLASH "Bottom SLASH "/GT SLASH r SLASH n LTBorders/GT" +
" SLASH r SLASH n LTFont/GT SLASH r SLASH n LTInterior/GT SLASH r SLASH n LTNumberFormat/GT" +
" SLASH r SLASH n LTProtection/GT SLASH r SLASH n LT/StyleGT SLASH r SLASH n " +
"LTStyle ss:ID= SLASH "BoldColumn SLASH "GT SLASH r SLASH n LTFont " +
"x:Family= SLASH "Swiss SLASH " ss:Bold= SLASH "1 SLASH "/GT SLASH r SLASH n LT/StyleGT SLASH r SLASH n " +
"LTStyle ss:ID= SLASH "StringLiteral SLASH "GT SLASH r SLASH n LTNumberFormat" +
" ss:Format= SLASH "@ SLASH "/GT SLASH r SLASH n LT/StyleGT SLASH r SLASH n LTStyle " +
"ss:ID= SLASH "Decimal SLASH "GT SLASH r SLASH n LTNumberFormat " +
"ss:Format= SLASH "0.0000 SLASH "/GT SLASH r SLASH n LT/StyleGT SLASH r SLASH n " +
"LTStyle ss:ID= SLASH "Integer SLASH "GT SLASH r SLASH n LTNumberFormat " +
"ss:Format= SLASH "0 SLASH "/GT SLASH r SLASH n LT/StyleGT SLASH r SLASH n LTStyle " +
"ss:ID= SLASH "DateLiteral SLASH "GT SLASH r SLASH n LTNumberFormat " +
"ss:Format= SLASH "mm/dd/yyyy;@ SLASH "/GT SLASH r SLASH n LT/StyleGT SLASH r SLASH n " +
"LT/StylesGT SLASH r SLASH n ";
const string endExcelXML = "LT/WorkbookGT";

int rowCount = 0;
int sheetCount = 1;
excelDoc.Write(startExcelXML);
excelDoc.Write("LTWorksheet ss:Name= SLASH "Sheet" + sheetCount + " SLASH "GT");
excelDoc.Write("LTTableGT");
excelDoc.Write("LTRowGT");
for (int x = 0; x LT source.Tables[0].Columns.Count; x++)
{
excelDoc.Write("LTCell ss:StyleID= SLASH "BoldColumn SLASH "GTLTData ss:Type= SLASH "String SLASH "GT");
excelDoc.Write(source.Tables[0].Columns[x].ColumnName);
excelDoc.Write("LT/DataGTLT/CellGT");
}
excelDoc.Write("LT/RowGT");
foreach (DataRow x in source.Tables[0].Rows)
{
rowCount++;
//if the number of rows is GT 64000 create a new page to continue output
if (rowCount == 64000)
{
rowCount = 0;
sheetCount++;
excelDoc.Write("LT/TableGT");
excelDoc.Write(" LT/WorksheetGT");
excelDoc.Write("LTWorksheet ss:Name= SLASH "Sheet" + sheetCount + " SLASH "GT");
excelDoc.Write("LTTableGT");
}
excelDoc.Write("LTRowGT"); //ID=" + rowCount + "
for (int y = 0; y LT source.Tables[0].Columns.Count; y++)
{
System.Type rowType;
rowType = x[y].GetType();
switch (rowType.ToString())
{
case "System.String":
string XMLstring = x[y].ToString();
XMLstring = XMLstring.Trim();
XMLstring = XMLstring.Replace("&", "&");
XMLstring = XMLstring.Replace("GT", "GT");
XMLstring = XMLstring.Replace("LT", "LT");
excelDoc.Write("LTCell ss:StyleID= SLASH "StringLiteral SLASH "GT" +
"LTData ss:Type= SLASH "String SLASH "GT");
excelDoc.Write(XMLstring);
excelDoc.Write("LT/DataGTLT/CellGT");
break;
case "System.DateTime":
//Excel has a specific Date Format of YYYY-MM-DD followed by
//the letter 'T' then hh:mm:sss.lll Example 2005-01-31T24:01:21.000
//The Following Code puts the date stored in XMLDate
//to the format above
DateTime XMLDate = (DateTime)x[y];
string XMLDatetoString = ""; //Excel Converted Date
XMLDatetoString = XMLDate.Year.ToString() +
"-" +
(XMLDate.Month LT 10 ? "0" +
XMLDate.Month.ToString() : XMLDate.Month.ToString()) +
"-" +
(XMLDate.Day LT 10 ? "0" +
XMLDate.Day.ToString() : XMLDate.Day.ToString()) +
"T" +
(XMLDate.Hour LT 10 ? "0" +
XMLDate.Hour.ToString() : XMLDate.Hour.ToString()) +
":" +
(XMLDate.Minute LT 10 ? "0" +
XMLDate.Minute.ToString() : XMLDate.Minute.ToString()) +
":" +
(XMLDate.Second LT 10 ? "0" +
XMLDate.Second.ToString() : XMLDate.Second.ToString()) +
".000";
excelDoc.Write("LTCell ss:StyleID= SLASH "DateLiteral SLASH "GT" +
"LTData ss:Type= SLASH "DateTime SLASH "GT");
excelDoc.Write(XMLDatetoString);
excelDoc.Write("LT/DataGTLT/CellGT");
break;
case "System.Boolean":
excelDoc.Write("LTCell ss:StyleID= SLASH "StringLiteral SLASH "GT" +
"LTData ss:Type= SLASH "String SLASH "GT");
excelDoc.Write(x[y].ToString());
excelDoc.Write("LT/DataGTLT/CellGT");
break;
case "System.Int16":
case "System.Int32":
case "System.Guid":
case "System.Int64":
case "System.Byte":
excelDoc.Write("LTCell ss:StyleID= SLASH "Integer SLASH "GT" +
"LTData ss:Type= SLASH "Number SLASH "GT");
excelDoc.Write(x[y].ToString());
excelDoc.Write("LT/DataGTLT/CellGT");
break;
case "System.Decimal":
case "System.Double":
excelDoc.Write("LTCell ss:StyleID= SLASH "Decimal SLASH "GT" +
"LTData ss:Type= SLASH "Number SLASH "GT");
excelDoc.Write(x[y].ToString());
excelDoc.Write("LT/DataGTLT/CellGT");
break;
case "System.DBNull":
excelDoc.Write("LTCell ss:StyleID= SLASH "StringLiteral SLASH "GT" +
"LTData ss:Type= SLASH "String SLASH "GT");
excelDoc.Write("");
excelDoc.Write("LT/DataGTLT/CellGT");
break;
default:
throw (new Exception(rowType.ToString() + " not handled."));
}
}
excelDoc.Write("LT/RowGT");
}
excelDoc.Write("LT/TableGT");
excelDoc.Write(" LT/WorksheetGT");
excelDoc.Write(endExcelXML);
excelDoc.Close();
}
}
}

That's all folks....
The End