|
|
>> BTW this is with VS C# express edition (it's free), your experience with
>> other IDEs may vary :-)
>
> Well, maybe they've fixed it since I used VS J++ a few years ago. Who
> knows?
Most likely it's been improved a lot.
> As does that, assuming it does it properly. (IME, VS usually prefers to
> have all autogenerated code perform its function in the most
> over-complicated way feasible.)
In C# to handle events you register the method you want called with the
event, it's 1 line:
button1.Click += new System.EventHandler(MyMethod);
The GUI automatically adds this line to the Form Design source file when you
tell it to (usually you don't need to open this file, it is just called from
the main source file). But of course you can write that line yourself
anywhere to add/remove event handlers at runtime.
> When you say it "generates all the necessary code and resource files",
> what do you mean exactly? How much stuff do you need to make a form
> application that opens one blank form?
Well there's a "Form designer" file that holds any GUI elements you add,
that starts life as a pretty empty class definition (it just sets the class
name, Form title text and so on). The main code file is again just an empty
class definition with an initialisor method that calls the form definition
file (about 10 lines total). It also adds references to the project for the
assemblies you are likely to need (System.Windows.Forms, System.Drawing
etc), and a few settings for Windows forms.
> I would have thought you only need to write a handful of lines of code -
> in which case, having it autogenerated isn't saving you much effort.
You're right it doesn't save that much effort, but it's certainly easier to
start with that nice organised template rather than starting from scratch
each time.
>> Like if a function is getting a bit long, you can select a block of code
>> and say "extract this to another function". All parameters and return
>> values will be handled automatically.
>
> So, what, it passes everything in scope as parameters? Or just everything
> referenced?
Everything that is used/needed by the code you selected that isn't
accessible from outside the original function is passed as parameters. It
"just works" if you click it and then compile.
>> Or if you type a function name that doesn't exist yet, you can click and
>> say "generate the boilerplate code for this function".
>
> What's to generate? I'm presuming it just makes a one-line function
> stub... unless you mean it does something more complex than that?
eg if I type in "bool result = NewFunction(width,height);" and tell it to
make the stub, it will insert this immediately below the existing function:
private bool NewFunction(double width, double height)
{
throw new NotImplementedException();
}
Again, not a huge timesaver, but it's so easy to use and it comes up so
often it's worthwhile.
>> Or you can go to "Insert -> New Class" and it will create a new file with
>> the new class template in it.
>
> Again, shouldn't an empty class be trivial to write in the first place?
Sure, but it's something so common to do that even saving 30 seconds is a
benefit, especially if you want it in a new file, and that file to be saved,
added to the current project and opened in the IDE.
> OK, now does it blindly rename it *everywhere*? Like just a find &
> replace? Or does it actually apply scoping rules so that it knows it's
> renaming "the same" variable throughout?
Of course it applies scoping rules, it would be a bit useless if it didn't.
> Smalltalk VisualWorks had a feature to rename a method, but unfortunately
> it was a blind find & replace. If you wrote a class and discovered that
> one of your method names as the same as some other random class and you
> wanted to make it different, *all* the method calls would get renamed.
That wouldn't really work in .net, as the same common variable names and
methods are used repeatedly in a huge number of classes (eg the "Value" or
"Text" property, or the ToString() method). Of course people continue these
same conventions in their own code.
> It's also quite nice having the property pane that tells you what's in
> your source file at a glance. (Especially if you're working with something
> like JavaDoc that forces you to put unrelated junk in amoungst the working
> code.)
Oh one more:
8) Right click and "Go to definition" on a method. And of course the
View -> Navigate Back button afterwards :-)
Post a reply to this message
|
|