No Silver Bullet · Introduction A number of different programming techniques have been put forward...
Transcript of No Silver Bullet · Introduction A number of different programming techniques have been put forward...
![Page 1: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/1.jpg)
No Silver Bullet
Mike Swaim
April 17, 2012
![Page 2: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/2.jpg)
Introduction
A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software development beast. This talk is to give a decent high level overview of some common techniques, their advantages and disadvantages.
![Page 3: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/3.jpg)
![Page 4: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/4.jpg)
High Level Languages- Advantages
• A single programmer can only write so many lines of code per day
• Studies have shown that productivity decreases exponentially with program size (measured in lines of code)
• If you can get the same work done with fewer lines of code, the program will be finished sooner, and have fewer bugs
![Page 5: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/5.jpg)
High Level Languages- Advantages
• The right high level language can produce a 3-5x increase in programmer productivity. (Involves suitability to task and familiarity.)
![Page 6: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/6.jpg)
References
• Mythical Man Month- Chapter 8- Calling the Shot (Fredrick Brooks)
• Code Complete: Chapter 4, section 1- Choice of Programming Language (Stephen McConnell)
• http://stackoverflow.com/questions/966800/mythical-man-month-10-lines-per-developer-day-how-close-on-large-projects
![Page 7: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/7.jpg)
High Level Languages - Disadvantages
• Some optimizations cannot be done in a high level language- The C++ version of Quake ][ ran at ~ 70% of the speed of the version that shipped. The shipped version interleaved fp and integer math, running both math units in parallel.
• http://www.vertigosoftware.com/Quake2.htm
• http://groups.google.com/group/microsoft.public.dotnet.framework.performance/browse_thread/thread/e22a2c941e518428/990e084440d47623?hl=en&ie=UTF&q=quake+.net+assembly
![Page 8: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/8.jpg)
High Level Languages - Disadvantages
• May not be able to take advantage of processor features- SSE on intel/AMD hardware or ALTiVEC on PowerPC (Xbox, Wii, PS3)
• A DirectShow implementation had a 25x performance increase by using SSE instructions
• http://software.intel.com/en-us/blogs/2010/12/20/visual-studio-2010-built-in-cpu-acceleration/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+IntelSoftwareNetworkBlog+%28Intel+Software+Network+Blog%29
![Page 9: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/9.jpg)
High Level Languages - Disadvantages
• High level languages may have inappropriate runtime requirements
• On NT when servicing some interrupts, the memory manager may be inactive, so any page faults would hang the OS, limiting the use of some languages and runtimes
![Page 10: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/10.jpg)
Object Oriented Programming
• public struct IntPair • { • public IntPair(int x, int y) • { • Val1 = x; • Val2 = y; • }
• public int Val1; • public int Val2; • }
![Page 11: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/11.jpg)
Object Oriented Programming
• Examples: C++, Java, C#, SmallTalk, Objective C
• Dynamic Dispatch
• Encapsulation
• Inheritance
• Polymorphism
![Page 12: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/12.jpg)
Object Oriented Programming Advantages
• Data Encapsulation
• Modularity
• Promotes Code Reuse
![Page 13: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/13.jpg)
Disadvantages
• “Everything is an object” often fails in practice.
• You end up with static classes which are simply collections of methods.
• Modeling your problem with objects can be tricky.
• Class Library/Framework Explosion
![Page 14: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/14.jpg)
Dependency Graph 1
![Page 15: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/15.jpg)
Dependency Graph 2
![Page 16: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/16.jpg)
Dependency Graph 3
![Page 17: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/17.jpg)
Links
• http://odetocode.com/Blogs/scott/archive/2011/10/04/rise-and-fall-of-classic-oop.aspx
• http://thedailywtf.com/Articles/Enterprise-Dependency-The-Next-Generation.aspx
• http://thedailywtf.com/Articles/The-Enterprise-Dependency.aspx
• http://thedailywtf.com/Articles/Enterprise-Dependency-Big-Ball-of-Yarn.aspx
![Page 18: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/18.jpg)
Declaritive Languages
select e.event_id, e.locked, eg.event_group_id, eg.locked,
fv1.value, fv2.value, fv1.flags, fv2.flags
from event e join event_group eg on e.event_group_id = eg.event_group_id
left outer join float_value fv1 on e.event_id = fv1.event_id
left outer join float_value fv2 on e.event_id = fv2.event_id
where e.attribute_group_id = @ag and
eg.data_form_id = @form and
fv1.attribute_id = @a1 and
fv2.attribute_id = @a2
![Page 19: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/19.jpg)
Declarative Languages
• Examples:Prolog, SQL
• Pro: The programmer is able to describe what they want without having to describe how it is to be done.
• Con: Performance can be problematic
![Page 20: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/20.jpg)
Functional Programming
(define factorial
(lambda (n)
(if (= n 0) 1 (* n (factorial (- n 1))))
))
![Page 21: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/21.jpg)
Functional Programming
• Examples: Lisp, Scheme, ML, OCaml, Haskell, Erlang, F#, APL, J
• First Class Functions
• Pure Functions
• Recursion
• Lazy Evaluation
![Page 22: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/22.jpg)
Functional Programming Advantages
• Stateless
• Thread Safe (when using immutable objects)
• Pure functions are easy to test, since they have no side effects
![Page 23: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/23.jpg)
Functional Programming Disadvantages
• Longer Argument Lists
• You may want side effects/state
• More Object Creation/Destruction overhead
![Page 24: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/24.jpg)
References
• Real-World Functional Programming with Examples in F# and C# (Tomas Petricek)
• http://stackoverflow.com/questions/1012573/how-to-learn-haskell/1016986#1016986
• http://prog21.dadgum.com/114.html
![Page 25: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/25.jpg)
Data Oriented Design
• OO:class Ball { Point pos; Color color; double radius; void draw(); }; vector<Ball> balls; • DOD:class Balls { vector<Point> pos; vector<Color> color; vector<double> radius; void draw(); };
![Page 26: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/26.jpg)
Data Oriented Design
• I am not aware of any languages that directly support Data Oriented Design
• The goal of DOD is to minimize cache misses by grouping data in space that will be processed together in time.
• This violated OO because you’re grouping data based on how you’re going to process it, rather than how it’s logically related.
![Page 27: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/27.jpg)
Data Oriented Design
![Page 28: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/28.jpg)
Data Oriented Design Advantages
• Speed! (Up to 35%)
• Parallelization is often simpler
![Page 29: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/29.jpg)
Data Oriented Design Disadvantages
• Breaks the OO model
• Requires care allocating memory
• Data items must be processed sequentially
![Page 30: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/30.jpg)
Data Oriented Design Gotcha
• In Java/C# collections of objects (including arrays) are collections of pointers. The objects are stored on the heap.
• In C#, arrays of structs ARE stored contiguously. Structs behave subtlety differently than objects, especially when passed as function arguments.
![Page 31: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/31.jpg)
Links
• http://research.scee.net/files/presentations/gcapaustralia09/Pitfalls_of_Object_Oriented_Programming_GCAP_09.pdf
• http://gamesfromwithin.com/data-oriented-design
• http://software.intel.com/en-us/blogs/2009/06/30/highlights-and-challenges-during-ghostbusters-development-part-3/
![Page 33: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/33.jpg)
Metaprogramming
template <class myType> myType GetMax (myType a, myType b) { return (a>b?a:b); }
![Page 34: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/34.jpg)
Metaprogramming
• Examples: C++ Templates, C# Generics, Java Generics, Lisp Macros, Yacc, Bison, .net T4
• Code that generates code
• Useful when you want to do similar things repeatedly, with only some specifics changing.
![Page 35: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/35.jpg)
Metaprogramming
Advantages
• Less code to maintain
• Simpler code
Disadvantages
• Conceptually harder
• Often harder to debug (specifically in C++)
![Page 36: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/36.jpg)
Metaprogramming Links
• Modern C++ Design: Generic Programming and Design Patterns Applied (Andrei Alexandrescu)
![Page 37: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/37.jpg)
Static Typing
• Int x = foo()
• Found in most compiled languages.
• Data types are explicit, and can’t change.
• Functions and variables are bound at compile time.
![Page 38: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/38.jpg)
Static Type Advantages
• Find errors at compile time
• Many modern IDEs can use type information for name completion
![Page 39: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/39.jpg)
Static Type Disadvantages
• Inflexible: Frameworks often expect objects to have a specific base class or interface to work correctly.
![Page 40: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/40.jpg)
Dynamic Typing
• movies = ["The Holy Grail", "The Life of Brian", "The Meaning of Life"]
• Type is inferred at runtime.
• Functions and variables are bound at run time.
• Sometimes referred to as “Duck Typing”
![Page 41: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/41.jpg)
Duck Typing
• If it walks like a duck, and quacks like a duck, it’s probably a duck.
• If a class exports the methods that you want to call, then it’s probably the type that you want.
![Page 42: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/42.jpg)
Advantages
• The language is simpler
• Easier to test, because you don’t have to worry about creating/faking interfaces
• Source code is often more like psudo-code
• Easier to pass objects between modules because you don’t have to worry about linker definitions.
• Metaprogramming is easier
![Page 43: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/43.jpg)
Disadvantages
• Slower generated code
• Many coding errors won’t be caught until runtime
![Page 44: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/44.jpg)
Links
• http://thesis.haverford.edu/dspace/bitstream/handle/10066/624/2004RushtonM.pdf?sequence=2
• http://stackoverflow.com/questions/125367/dynamic-type-languages-versus-static-type-languages
• http://www.tbray.org/ongoing/When/201x/2011/12/27/Type-Systems
![Page 45: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/45.jpg)
Garbage Collection
static int Foo()
{
Bar b = new Bar();
return b.Qux();
}
![Page 46: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/46.jpg)
Garbage Collection
• VB, Java (JVM based languages), C# (CLR based languages), Python, Lisp
• Programmer doesn’t have to track memory usage
• Programmer often cannot access memory directly
• Programmer often cannot directly destroy objects
![Page 47: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/47.jpg)
Advantages
• Programmer doesn’t have to worry about tracking object lifetime manually
• Memory leaks are greatly reduced, if not completely eliminated
• Heap fragmentation is often greatly reduced
![Page 48: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/48.jpg)
Disadvantages
• Typically only tracks memory (not file/OS object handles, ports)
• Lulls programmer into false sense of security (see above)
• GC time is more or less proportional to number of “live” objects in the system
• The system controls when a GC is done
• Garbage collection often invalidates the cache
![Page 49: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/49.jpg)
Disadvantages
• Application cannot have custom memory manager (Although host can. Ex. SQL Server)
• Example of a custom memory manager: The current Delphi memory manager is based on the fastMM project hosted on SourceForge
![Page 50: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/50.jpg)
Links
• http://stackoverflow.com/questions/3214980/what-are-the-disadvantages-in-using-garbage-collection
• http://www.artima.com/insidejvm/ed2/gcP.html
• http://msdn.microsoft.com/en-us/library/0xy59wtx.aspx
• http://sourceforge.net/projects/fastmm/
![Page 51: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/51.jpg)
Allocating on the Stack
{
File f("/some/path/name");
// use f
}
![Page 52: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/52.jpg)
The Stack
• The stack is used by the current thread to hold temporary data. Memory is allocated and deallocated in linear blocks. Memory is typically allocated when a function is called, and freed when the function returns.
• Functions store local variables (and function return addresses) on the stack.
![Page 53: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/53.jpg)
Stack Based Languages
• Forth, Postscript are explicitly stack based languages
• C, C++, Lisp, Java, Python, Ruby
• The first version of Fortran did not use the stack (or support recursion)
![Page 54: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/54.jpg)
Advantages
• Faster than allocating memory on the heap
• Freeing memory is faster than using the Heap (either GC or manual memory management)
• Don’t have to worry about fragmentation
• Objects are automatically (via compiler generated code) freed when a function returns
![Page 55: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/55.jpg)
Disadvantages
• The stack is MUCH smaller than the heap
• Stack space is allocated with each function call, so deeply nested functions can have much less memory to work with.
• Object lifetimes are limited to the current function call.
![Page 56: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/56.jpg)
C# Note
• Classes are always allocated on the heap
• Structs are allocated on the stack
• Structs that have a lifetime longer than the current function have to be “boxed” inside an object
• Almost all iterators are structs
![Page 57: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/57.jpg)
Links
• http://msdn.microsoft.com/en-us/library/aa288471(v=vs.71).aspx
• http://stackoverflow.com/questions/203695/structure-vs-class-in-c-sharp
• http://stackoverflow.com/questions/161053/c-which-is-faster-stack-allocation-or-heap-allocation
![Page 58: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/58.jpg)
Tail Call
function bar(data)
{
if ( a(data) )
{
return b(data);
}
return c(data);
}
![Page 59: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/59.jpg)
Tail Call
• If the compiler is smart enough, when the last statement in a function is another function call, it’ll reuse the stack space of the calling function in the new function
![Page 60: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/60.jpg)
Tail Call
Advantages
• Stack space is used much more efficiently
• Used by almost all Lisp variants
Disadvantages
• Lose debugging information as stack frames are reused
![Page 61: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/61.jpg)
Links
• http://en.wikipedia.org/wiki/Tail_recursion
• http://blogs.msdn.com/b/abhinaba/archive/2007/07/27/tail-recursion-on-net.aspx
![Page 62: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/62.jpg)
Resource Acquisition is Initialization
• In C++, objects created on the stack are destroyed when the current function returns.
• Why not use this as a primitive, yet fast garbage collector?
• This is how smart pointers came to be in C++.
![Page 63: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/63.jpg)
Resource Acquisition is Initialization
• C# has something similar for IDisposable objects with the using() keyword.
• Using (Foo foo = new Foo(bar) {})
• C# Structs behave like C++ objects allocated on the stack. C# structs cannot have a destructor.
![Page 64: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/64.jpg)
Links
• http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization
• http://blogs.msdn.com/b/hsutter/archive/2004/07/31/203137.aspx
![Page 65: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/65.jpg)
Multiprocessing
![Page 66: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/66.jpg)
Symmetric Multithreading
• All processors are considered equivalent
• Memory is shared by all processors
• Used by programs that create threads, use thread pools, use task parallel libraries
![Page 67: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/67.jpg)
Advantages
• Conceptually simple
• Tools are plentiful
• Only requires a single compiler/runtime
![Page 68: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/68.jpg)
Disadvantages
• Race conditions
• Locking/synchronization overhead for memory shared between threads
• Limited memory bandwidth. With more processors, the greater the chance of saturating the memory bus and processors being starved for memory.
• If two processors are accessing the same page of memory, you can get cache thrashing
![Page 69: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/69.jpg)
Links
• http://en.wikipedia.org/wiki/Simultaneous_multithreading
• http://blogs.msdn.com/b/pfxteam/
![Page 70: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/70.jpg)
Heterogeneous Multitasking
• All processors may or may not share the same memory
• Processors may or may not share the same architecture
• Typically, one processor acts as a controller, directing the others
![Page 71: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/71.jpg)
Heterogeneous Multitasking
• IBM Cell Architecture (PS3)
• Clusters
• Tibco Rendezvous
• Applications using special purpose processors (like graphics engines)
![Page 72: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/72.jpg)
Advantages
• Performance scales better than SMT. (Often nearly linearly)
• For tasks where they’re suited, special purpose processors are often much faster than general purpose processors.
![Page 73: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/73.jpg)
Disadvantages
• More overhead for communication between processors
• May need more than one compiler (OpenCL makes this easier)
• Debugging tasks on a SPE (special purpose engine) may be difficult
![Page 74: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/74.jpg)
Links
• http://www.khronos.org/opencl/
• http://developer.nvidia.com/opencl
• http://www.amd.com/us/products/technologies/stream-technology/opencl/pages/opencl.aspx
![Page 75: No Silver Bullet · Introduction A number of different programming techniques have been put forward over the years as being the “silver bullet” that would slay the software](https://reader033.fdocuments.us/reader033/viewer/2022052019/603285179a669459782355d4/html5/thumbnails/75.jpg)
Questions?