For Dummies 978-0-470-56348-9 Datový list

Procházejte online nebo si stáhněte Datový list pro Softwarové příručky For Dummies 978-0-470-56348-9. For Dummies C# 2010 All-in-One Uživatelská příručka

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 12
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 0
Chapter 1: Programming
Dynamically!
In This Chapter
Understanding dynamic typing
Defining variables
Putting dynamic to use
Making static operations dynamic
F
or many years, I thought that dynamic programming referred to being
really flashy and flamboyant while writing code. So, I started wearing
Hawaiian shirts and singing loudly.
Later, I found out this isn’t the case.
Dynamic programming is another one of those buzzwords that really doesn’t
have a clear definition. At its loosest, it means developing something in such
a way that the program makes more decisions about the way it runs while
running, rather than when you compile it.
Scripting languages are a great example of this. When you write something
in VBScript, you don’t compile it at all — all of the decisions are made at
runtime. Ruby is another good example: Most of the time, an entire program
can just be typed into a command prompt and run right from there.
There are examples that are not so good — like VB Classic. Remember the
Variant type? You could declare a variable to be Variant and VB wouldn’t
decide what it was supposed to be for real until the program ran. In the
best of cases, this added immense flexibility to the language. In the worst of
cases, you got Type Mismatch errors at runtime.
To give a concrete example, when you declare a variable in a dynamically
typed language, you don’t have to say what type you are making that vari-
able. The compiler will just figure it out for you. In a static language, like C#
3.0, you do have to say what type you are making that variable.
Microsoft originally promised that dynamic types would never be in C#,
but later decided that the feature had to be added. Why? Mostly, it’s
because of the development for Microsoft Office (like the reasoning for
much of the rest of Book VIII). Office uses COM, the pre-.NET structure for
Microsoft applications.
53_563489-bk08ch01.indd 76953_563489-bk08ch01.indd 769 3/19/10 8:17 PM3/19/10 8:17 PM
COPYRIGHTED MATERIAL
Zobrazit stránku 0
1 2 3 4 5 6 ... 11 12

Shrnutí obsahu

Strany 1 - COPYRIGHTED MATERIAL

Chapter 1: Programming Dynamically!In This Chapter✓ Understanding dynamic typing✓ Defining variables✓ Putting dynamic to use✓ Making static operations

Strany 2

778Running with the Dynamic Language Runtime def main Array.new(11) { gets.to_i }.reverse.each do |x| y = f(x) puts “#{x} #{(y>400) ?

Strany 3

Book VIIIChapter 1Programming Dynamically!779Running with the Dynamic Language Runtime dynamic y = f(array[i]); if (y &g

Strany 4 - Programming Dynamically

780Running with the Dynamic Language RuntimeAdd to that the reality that C# is making runtime decisions about every single variable throughout the ent

Strany 5

770Shifting C# Toward Dynamic TypingCOM expects that the languages that use it (like VB Classic and C++) will have dynamic types. This made developing

Strany 6 - Putting Dynamic to Use

Book VIIIChapter 1Programming Dynamically!771Shifting C# Toward Dynamic Typing ✦ Python ✦ Cobra (my new favorite) ✦ Groovy ✦ Boo ✦ NewspeakProgrammers

Strany 7

772Programming DynamicallyOther benefits to dynamic languages in general show up as you use them more. For instance, macro languages are usually dynam

Strany 8

Book VIIIChapter 1Programming Dynamically!773Programming DynamicallyHowever, we can do this:dynamic newCourse = SomeFunction();newCourse.Schedule();Al

Strany 9 - Dynamic Ruby

774Putting Dynamic to UseWhat happens if newCourse comes back as something that doesn’t have a Schedule method? You get a runtime error. But there are

Strany 10 - Dynamic C#

Book VIIIChapter 1Programming Dynamically!775Putting Dynamic to Use ✦ int newString = (int) dynamicVariable;: This is an explicit cast to int. The com

Strany 11 - Chapter 1

776Running with the Dynamic Language RuntimeHere is the compiled C# code: class C { [return: Dynamic] public object MyMethod([Dyna

Strany 12

Book VIIIChapter 1Programming Dynamically!777Running with the Dynamic Language Runtime Figure 1-1: The Dynamic Language Runtime. The runtime helps the

Komentáře k této Příručce

Žádné komentáře