1

Possible Duplicate:
Why use dynamic typing in c#?

Should the new C# type 'dynamic' be used now much in place of Type safe variables that are compile safe? Or should it only be used in to integrate with dynamic languages like JavaScript or in areas where 'magic strings' where used to access data from XML ect.. which aren't type safe to begin with?

Community
  • 1
  • 1
John Egbert
  • 5,496
  • 8
  • 32
  • 44
  • 3
    Where have you ever seen it suggested that `dynamic` is a replacement for "type safe variables"? – John Saunders Sep 10 '10 at 23:09
  • @John. You might want to use it if to many as-operators make your code unreadable. – Janko R Sep 10 '10 at 23:15
  • I know it's definately not a replacement for Type safe vars. I am just currious to see how other people interperate it, and see what peoples suggestions are for best usage practices. – John Egbert Sep 10 '10 at 23:18
  • @elgasius: Ohh.. Com'on I was trying to hide that post.. (-; – Oren A Sep 10 '10 at 23:32

2 Answers2

3

"My personal belief is that dynamic typing will be relatively rarely useful in C# 4 - basically when you're dealing with data which is already only known dynamically, e.g. reflection, or navigating XML." - Jon Skeet here
For the elaborated version: try here

Community
  • 1
  • 1
Oren A
  • 5,870
  • 6
  • 43
  • 64
1

I would say avoid it. Let the statically typed language remain statically typed. Unfortunately, some bloke is going to use it, and you're going to have to deal with their code. C# gave you compile time checking to use. It'd be a waste to let it go.

If you feel you want to use dynamic a lot, go write Ruby or Python. It's just the way you want to attack the problem, and there's definitely a language for that type of solution.

Mike
  • 19,267
  • 11
  • 56
  • 72