Monday, April 11, 2005

C# Course day one

A day-by-day, blow-by-blow account of my Microsoft C# course. I'll update this particular entry throughout the day.

First of all, why would I attend a C# course when I've been a Java guy for so long... Well this just comes down to ensuring that I'm open to all technologies. I know people who talk poorly about technologies that aren't their favorite and usually they bash away without knowing what they're talking about. Personally I like to bash from a position of knowledge not ignorance. ;-)

Secondly, I already looked at C# about a month ago and was fairly happy with what I saw. I'm really only lacking some knowledge about the frameworks.

Finally, it's free. A company I worked for about two and a half years ago already paid for this so why not take advantage of it.

So now onto the course...

  • 10:30 AM I've learned nothing so far. Boring.

  • I've sat quietly through some Sun, Java bashing from the instructor no less. That was a bit irritating. That will definitely come up in my evaluation.

  • 12:16 PM Namespaces usually take the form of CompanyName.Application.Layer (e.g., Sundog.Retail.Data)

  • Can have multiple entry points in an app (many classes with Main methods) just need to specify which one in compiler settings

  • csc.exe is the command line compiler

  • a "module" is equivalent to a Java .class file

  • an "assembly" is equivalent to a Java .jar file. Contains a Manifest file that specifies version and other meta data.

  • ilasm.exe produces assemblies (not sure about this...)

  • ildasm.exe is a disassembler to look at manifest and generated MSIL code. ".NET Reflector" is a 3rd party tool that disassembles into C#, VB, or Delphi. Obfuscator may be good for commercial .NET

  • Can use ngen.exe to precompile assemblies into native code. Not always better.

  • Application Domains are like separate processes for different applications in one VM. It's done programatically so usually used by app server not individual apps.

  • Can create C# alias when multiple classes from multiple namespaces have the same name. e.g., using CSStringComp = CompCS.StringComponent;

  • 4:11 PM ASP Output cache allows the reserving of previously generated output. If the data's not changing quickly, this may be useful. Also works with page fragments.

  • .NET Framework around 24MB. How does that compare to Java. Everyone used to complain about how bit it was.

  • App can be launched from HTTP or File server and execution rights are reduced unless app is signed. Very much like Java WebStart.

  • No DLL Hell. Assemblies are typically deployed privately (in the same dir as the exe).

  • There is a "Gloabl Assembly Cache" (GAC) in c:\windows\assembly which is shared and can contain multiple versions of assemblies.

  • Assemblies must be signed to go into the GAC. Apps are compiled against a specific version. Versioning is much better handled in .NET than Java.

  • Visual Studio has a Setup project that can be added to a solution to create an MSI file (MS Installer). Nice touch.

  • Java got bashed a couple more times and I had to correct the instructor and let him know that autoboxing, enums and attributes are all part of Java and that the default behavior of virtual methods isn't necessarily a bad thing. Jeesh. I hope he shuts up now. ;-)

  • C# has structs but the instructor and apparently MS discourages using them. You don't get a performance boost and they're less flexible. Use only when you're interfacing with legacy code.

  • enums are also good for interfacing with legacy code. The [Flags] attribute can be used to assign bit values.

  • The internal keyword marks something for use by classes in the same assembly. Not quite the same as the package scope in Java.

  • Use Object.ReferenceEquals() instead of Equals() (unlike Java). Here == and Equals() should mean the same thing.

  • Can overload operators (+,-,*,/,%,<,>,==, etc) in C# using something like static public bool operator == (Class obj1, Class obj2){[...]}

  • ToString() is here too

  • Instructor made a big deal that implementing a Singleton in Java was hard. Here's an article he was referencing. Basically you do this in C#: public static readonly ExampleClass Instance = new ExampleClass(); Well in Java you do private static ExampleClass instance = new ExampleClass(); and provide a static accessor.

  • Instead of using ExampleClass.class in Java you use typeof(ExampleClass) in C#.

  • Operators like is, as, and typeof for working with Types.

  • generics will show up in .NET 2.0. Already there in Java 1.5, but Anders Hejlsberg (MS .NET Architect) suggests that the Java implementation isn't as good, primarily because Sun chose not to introduce new bytecodes in the VM to implement this functionality.

  • Can implement two interfaces that specify the same signature by explicitly defining the name of the interface in the method implementation.

  • pinvoke is the way to call "classic" DLLs. Looks much easier than JNI.

  • For COM compatibility .NET objects can be exposed as COM objects and COM objects can show up as .NET classes. Very reminiscent of Delphi.

No comments: