C# for Java Developers Patrick Linskey plinskey@gmail.com - - PowerPoint PPT Presentation

c for java developers
SMART_READER_LITE
LIVE PREVIEW

C# for Java Developers Patrick Linskey plinskey@gmail.com - - PowerPoint PPT Presentation

C# for Java Developers Patrick Linskey plinskey@gmail.com @plinskey Who am I? Patrick Linskey 13 years of Java experience, 11 professionally 2 years of professional C# experience Who are you? Hopefully, Java developers who are


slide-1
SLIDE 1

C# for Java Developers

Patrick Linskey plinskey@gmail.com @plinskey

slide-2
SLIDE 2

Who am I?

  • Patrick Linskey
  • 13 years of Java experience, 11

professionally

  • 2 years of professional C# experience
slide-3
SLIDE 3

Who are you?

  • Hopefully, Java developers who are

interested in learning about C#

  • ... for client, server, or mobile deployment
slide-4
SLIDE 4

Apology to Readers

Much of this talk happens in Visual Studio. Sorry about that. I will make the code available at http:// github.com/pcl -- the commit history provides some detail.

slide-5
SLIDE 5

[Anders Hejlsberg]

slide-6
SLIDE 6

Some Terminology

  • Common Language Runtime, not JVM
  • Intermediate Language, not Java bytecode
  • Assembly, not JAR
  • [Attribute], not @Annotation
slide-7
SLIDE 7

[Syntax]

slide-8
SLIDE 8

Coding Conventions

  • All methods use InitialCaps
  • Constants use InitialCaps instead of

ALL_CAPS

  • Namespaces are not as consistently-scoped

as are packages in the Java world

  • Assembly names are first-class constructs
slide-9
SLIDE 9

[Unit Testing]

slide-10
SLIDE 10

MSTest vs. NUnit

  • I use NUnit because it seems more familiar
  • Without ReSharper, NUnit /

Visual Studio integration is a bit weak

slide-11
SLIDE 11

Visual Studio

  • Most people seem to use it
  • $$$
  • ReSharper (plugin from JetBrains) is a must
  • #1 awesome

Visual Studio feature: program counter manipulation during debug sessions

slide-12
SLIDE 12

[LINQ and Functions]

slide-13
SLIDE 13

LINQ

  • Can evaluate LINQ queries against

database, XML, collections, etc.

  • Anything IEnumerable or IQueryable
  • Also: JOIN, GROUP BY, HAVING, ...
slide-14
SLIDE 14

Function Objects

  • We saw Func<int, int> in fib
  • Generally: Func<TArg1, TArg2, TReturn>
  • Support for up to 16 arguments!
slide-15
SLIDE 15

Action Objects

  • Action<TArg1, TArg2, ...>
  • Also supports 16 args!
  • Equivalent to a void method return type
slide-16
SLIDE 16

Tuples

  • Tuple<T1, T2, T3, ...>
  • Up to 8 items
  • Useful for easy multi-object returns, LINQ

queries

slide-17
SLIDE 17

Anonymous Types

  • Predate tuples

var ratio = new { Numerator = 2, Denominator = 3 }; Console.Out.WriteLine( ratio.Numerator / ratio.Denominator);

slide-18
SLIDE 18

[Object-Orientation]

slide-19
SLIDE 19

Virtual keyword

  • By default, methods are resolved at compile

time

  • To get polymorphic method invocation,

highlight the methods as ‘virtual’

slide-20
SLIDE 20

The Ecosystem

slide-21
SLIDE 21

Third-Party is Weak

  • Outside UI widgets, nowhere near as much

activity as in the Java world

  • Few open-source projects
  • http://stackoverflow.com is your friend
slide-22
SLIDE 22

Spring.NET is great

  • Lags the Java Spring Framework a bit
  • I’ve only used dependency injection

and lifecycle management features

  • WPF (and presumably Silverlight) have their
  • wn resource management
  • It’s possible to bridge the two
slide-23
SLIDE 23

Yay!

  • Generics are reified, and support

covariance and contravariance

  • Dynamic method invocation with the

‘dynamic’ pseudo-type (akin to ObjC’s ‘id’)

  • += syntax for all delegate fields / properties
  • Func, Action, raw Delegate
slide-24
SLIDE 24

More Cool Stuff

  • @ strings
  • Indexers
  • Partial classes (UI and codegen)
  • Structs
slide-25
SLIDE 25

Some Missing Features

  • No anonymous inner classes (use closures /

function objects instead)

  • All inner classes are static
  • Enums cannot have state or methods
  • Can emulate methods with extension

methods

slide-26
SLIDE 26

Questions?

Patrick Linskey plinskey@gmail.com code: http://github.com/pcl