Microsoft and C#

About the only thing the help pages are good for are the code examples, and sometimes those are also useless.
JavaScript uses objects, therefore it’s an object oriented language. When I first worked with Fortran and COBOL, the concept of “object oriented” hadn’t even been invented let alone implemented. (Okay, maybe it was in the head of some undergrad but you know what I mean.) Fortran and COBOL did not have objects and therefore were not object oriented. I haven’t worked with either of them for years so I don’t know if there are now object oriented versions of them or not.

Fortran 90, the immediate successor to Fortran 77, has objects, as do some dialects of Cobol.

The first question that comes to mind is why? Fortran I can kind of see. It could be useful for writing math oriented software with a GUI, and I suppose that you could use a formula object, a base conversion object, a random number generator object, etc. But COBOL is (or at least was) a batch language. What would be the purpose of a GUI? I realize that objects are useful for things other than just user interfaces but for COBOL it just seems like overkill. I guess the companies that write the compilers have to keep up with the times.

I dunno specifically about COBOL, but I can say that after doing OO programming for close to 10 years now, going back to procedural is like pulling teeth for me. I just don’t think that way anymore. So my WAG is that an OO version of COBOL is for people like me, who are so used to the OO model that their brains can’t figure out how to write simple procedural instructions anymore.

And ya, OO is used for a whole lot of stuff other than GUIs. I spent a good 5 years programming OO stuff that never came CLOSE to a GUI… we’re talking the deep down guts of a codebase.

Mr. Athena still programs in FORTRAN (the non-OO version), if you can believe that. It’s not that he can’t do C/C++, it’s that his current gig is working on legacy systems that are written in FORTRAN. On occasion, we’ll talk about some hairy problem he’s having at work, and see if the two of us can brainstorm to come up with a clean solution. Inevitably, I get going, come up with something simple and elegant, and Mr. Athena has to say “Whoa, girl, that’s a great object structure, but it’s FORTRAN, missy. Come back to earth!”

I just can’t think without objects anymore.

Is it enough?

Here’s the scenario: you’ve got a collection of forms. On each form is a collection of controls. How do you match up the control with its code?


class baseWidget {
...
  virtual void doStuff(eventType &input, eventType &result) = 0;
};

class throwWidget : public baseWidget {
...
};

class yankWidget : public baseWidget {
...
};

void throwWidget::doStuff(eventType &input, eventType &result) {
  this->display->throwRod(input);
  result = Car::burstIntoFlame;
}

void yankWidget::doStuff(eventType &input, eventType &result) {
  if (this->display->yankLeash(input))
    result = Dog::stop;
  else
    result = eventType::nothing;
}

...

  widgetGroup.insert(new throwWidget);
  widgetGroup.insert(new yankWidget);

I dunno, I’d need to see it in action to compare to what we’ve got.

+= and -= are special syntax for events. You add (or remove) a delegate to the list of handlers for that object’s event.

Well, the beauty of .NET is that you can use VB (or C++, Fortran, COBOL…) instead of C#.

Or F, or ML, or Haskell, or OCamel, or Eiffel, or brainfuck :D.

C#, to me, is one of the most carefully considered and well-reasoned designs of a language I have ever seen. There are a few little niggles that I am still unsatisfied with (no manual destructors) but, on the whole, I think it serves very well for the purpose it was intended for.

If you need to go into delegates more throughly than what the VC compiler provides as glue code, then perhaps you are doing it wrong. Are you sure it’s not code that comes before the delegate code that is breaking the compiler?

But not Common Lisp.

Stupid motherfuckers (<-- only 15% hyperbole).

Well, it was the delegate line that was causing the error, but after deleting the project and starting over from scratch (it’s a very simple project) it no longer causes the compile error. Now it compiles but generates a runtime error. The error is occurring in Form Designer generated code and it’s in the line before the line that was causing the compile error. Here’s the generated code, I’ve added an arrow (–>) next to the line that’s causing the error.


		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.inputPanel1 = new Microsoft.WindowsCE.Forms.InputPanel();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			// 
			// mainMenu1
			// 
			this.mainMenu1.MenuItems.Add(this.menuItem1);
			// 
			// menuItem1
			// 
			this.menuItem1.MenuItems.Add(this.menuItem2);
			this.menuItem1.Text = "&File";
			// 
			// menuItem2
			// 
			this.menuItem2.Text = "E&xit";
			// 
			// inputPanel1
			// 
		-->	this.inputPanel1.Enabled = true;
			this.inputPanel1.EnabledChanged += new System.EventHandler(this.inputPanel1_EnabledChanged);
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(64, 40);
			this.textBox1.Size = new System.Drawing.Size(104, 22);
			this.textBox1.Text = "textBox1";
			// 
			// Form1
			// 
			this.ClientSize = new System.Drawing.Size(294, 275);
			this.Controls.Add(this.textBox1);
			this.Menu = this.mainMenu1;
			this.MinimizeBox = false;
			this.Text = "Form1";

		}
		#endregion

It causes the following runtime error:


A managed Exception occurred at
MISC::HandeAr+0x5b

MISC::HandeAr+0x5b
InputPanel::set_Enabled+0x12
Form1::InitializeComponent+0x91
Form1::ctor+0xc
Form1::Main+0x5

OK to terminate

I get this same exact error in both the emulator and the actual device. I’m pretty certain that the problem is that I’m trying to enable the InputPanel without setting up the proper conditions first. The one thing I did discover was that you need to have a MainMenu object on the form before enabling the InputPanel. I’ve added that but the problem still exists. Anyone have any thoughts? (Since this thread has moved away from a rant a mod may want to consider moving it to someplace like GQ.)

Okay, I solved this myself. I set InputPanel1.Enabled to false in the designer which removed the “this.inputPanel1.Enabled = true” line from the generated code. Then I enabled it myself in the form load event. This fixed the problem. The program runs and I can enter text into the textbox via the inputpanel. My only question is why was this necessary? Shouldn’t I be able to enable it at design time? If not, then why is it possible to do so?

That’s funny you mention datagrid…I was just coaxing a co-worker through the ins and outs of that this afternoon. She was pretty pissed off about the whole thing.

I’ve had the same sort of issues you’ve had with the datagrid. Generally, I don’t try to make the datagrid do anything like what you’re trying to do. Its just easier to design your own object.

Well, once I got the fookin’ thing subclassed and overrode the necessary functions, it wasn’t too bad to continually add stuff to the overloads to get the damn thing to work right. But I ask myself continually just who made the fucking thing, and why they decided that things that IMO should be no-brainers (like programmatically changing just about anything about the bloody thing) should be nigh impossible. Why exactly isn’t column color an attribute of a data column? Same thing with data format - am I really the only one in the word who wants to programmatically check to see if the column contains, say, a monetary value, and if so, display dollar signs and commas?

I’m fairly certain it wouldn’t have been easier to code my own data grid, given that it was showing data directly from a dataset (and that, btw, worked wonderfully. Just tell the datagrid “here’s yer data!” by handing it a dataset and voilia!). But overall I can’t imagine a more complex and difficult object. It’s like MS was so busy making it all data-knowledgable that they never thought to think that maybe it would be nice to make the damn thing not only show data directly from a database, but make the fookin’ stuff readable by the use of formatting and color.

Then it sounds like a problem with a crappy control and not C#.

Well, it’s Microsoft’s control so I wouldn’t be suprised if it’s at fault. This, to me, is one of the biggest annoyances of object oriented programming. Having to use someone else’s crappy code but not having the source available so I can fix their mistakes, omissions, and bad assumptions.
Similar problems did exist before Object oriented. Compiler bugs, for example, were a possibility and something that you couldn’t fix yourself.
But the problem wasn’t near a large as it is now. Now I have to deal with code that I have no access to, and layer after layer of complexity which increases the odds of a bug.
I guess it was inevitable that software would evolve in this direction and I can appreciate the advantages but it can be very frustrating at times.

When you have comments like this, do you send it as feedback to the “mswish” program? (That’s “program” as in “endeavor”.)

See here for more info

IMO, it’s also one of the biggest benefits of object oriented programming: You don’t need the source in order to fix this omission. You can subclass the control, add the features you want, and then use your version instead. You can even share your changes with other developers and retain the copyright.

I have managed literally hundreds of developers over the last two decades, and when one of them suggests to me that he or she has discovered a fundamental bug with a well used piece of code/object/utility, I’m disinclined to take them at their word. And, sure enough, upon examination, it is almost always a lack of understanding or willingness to read the documentation that’s at fault, not the code.

Is it impossible that Microsoft shipped a bug in the control that you managed to find with a basic, simple piece of code? No. Is it likely? Not even remotely.

C# is everything that Java should have been. I admit that I was pretty distainful of what I saw by Microsoft as an attempt to divert attention away from Java after Sun took their toys and went home. With experience, I’ve discovered that it’s actually both more practical and elegant than Java. And .NET is pretty amazing, as well, if a bit daunting at first.

Well, I guess my ignorance is showing here. I’m not really familiar with subclassing. Can you also use it to fix bugs? It still seems like it’d be better to be able to fix the original problem than to paste over it.