dear compiler please don't be my nanny v2

92
Dear compiler: Please don't be my Nanny Speaker Name Dino Dini NHTV University of Applied Sciences

Upload: dino-dini

Post on 29-Jun-2015

817 views

Category:

Documents


2 download

DESCRIPTION

My 6 minute contribution to the AI Summit "Turing Tantrums" GDC 2013

TRANSCRIPT

Page 1: Dear compiler  please don't be my nanny v2

Dear compiler: Please don't be my Nanny

Speaker NameDino Dini NHTV University of Applied Sciences

Page 2: Dear compiler  please don't be my nanny v2

Nanny says:

Page 3: Dear compiler  please don't be my nanny v2

Nanny says:

●Don't you ever use goto

Page 4: Dear compiler  please don't be my nanny v2

Nanny says:

●Don't you ever use goto●Regard preprocessors as bad

Page 5: Dear compiler  please don't be my nanny v2

Nanny says:

●Don't you ever use goto●Regard preprocessors as bad●Might we suggest always saying new

Page 6: Dear compiler  please don't be my nanny v2

Nanny says:

●Don't you ever use goto●Regard preprocessors as bad●Might we suggest always saying new●Fact is OOP should make you glad

Page 7: Dear compiler  please don't be my nanny v2

Nanny says:

●Don't you ever use goto●Regard preprocessors as bad●Might we suggest always saying new●Fact is OOP should make you glad●So you want overload?

Page 8: Dear compiler  please don't be my nanny v2

Nanny says:

●Don't you ever use goto●Regard preprocessors as bad●Might we suggest always saying new●Fact is OOP should make you glad●So you want overload?●La la land's where weak typing goes

Page 9: Dear compiler  please don't be my nanny v2

Nanny says:

●Don't you ever use goto●Regard preprocessors as bad●Might we suggest always saying new●Fact is OOP should make you glad●So you want overload?●La la land's where weak typing goes●Ti's right to make everything private

Page 10: Dear compiler  please don't be my nanny v2

Nanny says:

●Don't you ever use goto●Regard preprocessors as bad●Might we suggest always saying new●Fact is OOP should make you glad●So you want overload?●La la land's where weak typing goes●Ti's right to make everything private●And that brings us back to Don't.

Page 11: Dear compiler  please don't be my nanny v2

Don't you ever use goto

Page 12: Dear compiler  please don't be my nanny v2

Don't you ever use goto

Contrary to popular belief, goto is not evil. Sometimes it can be the right tool for the job, especially when:

Page 13: Dear compiler  please don't be my nanny v2

Don't you ever use goto

Contrary to popular belief, goto is not evil. Sometimes it can be the right tool for the job, especially when:

● Prototyping non production code

Page 14: Dear compiler  please don't be my nanny v2

Don't you ever use goto

Contrary to popular belief, goto is not evil. Sometimes it can be the right tool for the job, especially when:

● Prototyping non production code● Trying to fix bugs in finished code with minimal risks

Page 15: Dear compiler  please don't be my nanny v2

Don't you ever use goto

Contrary to popular belief, goto is not evil. Sometimes it can be the right tool for the job, especially when:

● Prototyping non production code● Trying to fix bugs in finished code with minimal risks● Porting legacy code

Page 16: Dear compiler  please don't be my nanny v2

Don't you ever use goto

Contrary to popular belief, goto is not evil. Sometimes it can be the right tool for the job, especially when:

● Prototyping non production code● Trying to fix bugs in finished code with minimal risks● Porting legacy code● Implementing state machines

Page 17: Dear compiler  please don't be my nanny v2

Don't you ever use goto

If the code would have been clearer with a goto, then perhaps a goto was the best thing to use.

Page 18: Dear compiler  please don't be my nanny v2

Don't you ever use goto

If the code would have been clearer with a goto, then perhaps a goto was the best thing to use.

Java does not support goto, but still reserves the keyword. Adding goto support would take minutes, and would not end the world.

Page 19: Dear compiler  please don't be my nanny v2

Don't you ever use goto

If the code would have been clearer with a goto, then perhaps a goto was the best thing to use.

Java does not support goto, but still reserves the keyword. Adding goto support would take minutes, and would not end the world.

I Feel a disturbance in the Force...

Page 20: Dear compiler  please don't be my nanny v2

Regard preprocessors as bad

Page 21: Dear compiler  please don't be my nanny v2

Regard preprocessors as bad

I can decide for myself when it is appropriate to use macros or conditional compilation.

Page 22: Dear compiler  please don't be my nanny v2

Regard preprocessors as bad

I can decide for myself when it is appropriate to use macros or conditional compilation.

Java does not even allowconditional compilation,and it is hilarious, thehoops that you have tojump through as a result.

Page 23: Dear compiler  please don't be my nanny v2

Regard preprocessors as bad

I can decide for myself when it is appropriate to use macros or conditional compilation.

Java does not even allowconditional compilation,and it is hilarious, thehoops that you have tojump through as a result.

Page 24: Dear compiler  please don't be my nanny v2

Regard preprocessors as bad

Some legitimate uses:

Page 25: Dear compiler  please don't be my nanny v2

Regard preprocessors as bad

Some legitimate uses:

●Porting legacy code

Page 26: Dear compiler  please don't be my nanny v2

Regard preprocessors as bad

Some legitimate uses:

●Porting legacy code●Avoiding repetitive boilerplate

Page 27: Dear compiler  please don't be my nanny v2

Regard preprocessors as bad

Some legitimate uses:

●Porting legacy code●Avoiding repetitive boilerplate●Abstracting of identifiers

Page 28: Dear compiler  please don't be my nanny v2

Regard preprocessors as bad

Some legitimate uses:

●Porting legacy code●Avoiding repetitive boilerplate●Abstracting of identifiers●Implementing support for multitasking

Page 29: Dear compiler  please don't be my nanny v2

Regard preprocessors as bad

Some legitimate uses:

●Porting legacy code●Avoiding repetitive boilerplate●Abstracting of identifiers●Implementing support for multitasking●Registration of string to object mapping

Page 30: Dear compiler  please don't be my nanny v2

Regard preprocessors as bad

Some legitimate uses:

●Porting legacy code●Avoiding repetitive boilerplate●Abstracting of identifiers●Implementing support for multitasking●Registration of string to object mapping● And much, much more stuff that's not computer sciency,

but helps you Get Stuff DoneTM

Page 31: Dear compiler  please don't be my nanny v2

Regard preprocessors as bad

C# learned the lesson of conditional compilation, but still will not let me use macros. Which means more...

Page 32: Dear compiler  please don't be my nanny v2

Regard preprocessors as bad

C# learned the lesson of conditional compilation, but still will not let me use macros. Which means more...

Page 33: Dear compiler  please don't be my nanny v2

Might we suggest always saying new

Page 34: Dear compiler  please don't be my nanny v2

Might we suggest always saying new

It is a sad fact of life that programs have to allocate memory, which is messy and slow and affects performance.

But to rub it in all the time is just plain senseless.

Page 35: Dear compiler  please don't be my nanny v2

Might we suggest always saying new

It is a sad fact of life that programs have to allocate memory, which is messy and slow and affects performance.

But to rub it in all the time is just plain senseless.

Vector3 vec = current + new Vector3(1,2,3);

DoSomethingImportant( new Vector3(a,b,c),new Vector3(d,e,f),new Vector3(g,h,i));

Page 36: Dear compiler  please don't be my nanny v2

Might we suggest always saying new

This is what would actually happen if experienced programmers were not constantly reminded that doing stuff causes memory allocations:

Page 37: Dear compiler  please don't be my nanny v2

Might we suggest always saying new

This is what would actually happen if experienced programmers were not constantly reminded that doing stuff causes memory allocations:

Nothing....

Page 38: Dear compiler  please don't be my nanny v2

Might we suggest always saying new

And it's not as if C# is consistent, is it?

Page 39: Dear compiler  please don't be my nanny v2

Might we suggest always saying new

And it's not as if C# is consistent, is it?

You are forced to say new all the time, but can then create accessors that could actually end the world through what looks like an innocent variable read.

Page 40: Dear compiler  please don't be my nanny v2

Might we suggest always saying new

DebugOut ( fluffyKitten.name );

Page 41: Dear compiler  please don't be my nanny v2

Might we suggest always saying new

DebugOut ( fluffyKitten.name );

Page 42: Dear compiler  please don't be my nanny v2

Fact is OOP should make you glad

Object orientated programming did not turn out to be the cure for our ills.

Page 43: Dear compiler  please don't be my nanny v2

Fact is OOP should make you glad

Are objects really the best building blocks of code?

Page 44: Dear compiler  please don't be my nanny v2

Fact is OOP should make you glad

Are objects really the best building blocks of code?

How about keeping data and functionality separate instead?

Page 45: Dear compiler  please don't be my nanny v2

Fact is OOP should make you glad

Are objects really the best building blocks of code?

How about keeping data and functionality separate instead?

The first thing an architect seems to do with OOP is separate data from functionality through interfaces.

Page 46: Dear compiler  please don't be my nanny v2

Fact is OOP should make you glad

Are objects really the best building blocks of code?

How about keeping data and functionality separate instead?

The first thing an architect seems to do with OOP is separate data from functionality through interfaces.

Compilers are generally designed around the OOP model, making it harder to solve programming problems in other ways.

Page 47: Dear compiler  please don't be my nanny v2

Fact is OOP should make you glad

This means more...

Page 48: Dear compiler  please don't be my nanny v2

Fact is OOP should make you glad

This means more...

Page 49: Dear compiler  please don't be my nanny v2

So you want to overload?

Page 50: Dear compiler  please don't be my nanny v2

So you want to overload?

Overloading functions and operators really can be very useful, but many languages refuse to support them for dubious reasons.

Page 51: Dear compiler  please don't be my nanny v2

So you want to overload?

Overloading functions and operators really can be very useful, but many languages refuse to support them for dubious reasons.

Javascript does not even support overloaded functions.

Page 52: Dear compiler  please don't be my nanny v2

So you want to overload?

Lets compare two pseudo code fragments:

Page 53: Dear compiler  please don't be my nanny v2

So you want to overload?

Lets compare two pseudo code fragments:

Vector3 N = ( pos1 - pos2 ) . Normalise();pos1 += N * speed;

Page 54: Dear compiler  please don't be my nanny v2

So you want to overload?

Lets compare two pseudo code fragments:

Vector3 N = ( pos1 - pos2 ) . Normalise();pos1 += N * speed;

// or

Vector3 N = NormaliseVector3( sub2Vector3( pos1,pos2 ));

AddToVector3( ScaleVector3( N, speed ));

Page 55: Dear compiler  please don't be my nanny v2

So you want to overload?

Lets compare two pseudo code fragments:

Vector3 N = ( pos1 - pos2 ) . Normalise();pos1 += N * speed;

// or

Vector3 N = NormaliseVector3( sub2Vector3( pos1,pos2 ));

AddToVector3( ScaleVector3( N, speed ));

Questions?

Page 56: Dear compiler  please don't be my nanny v2

La la land's where weak typing goes

Page 57: Dear compiler  please don't be my nanny v2

La la land's where weak typing goes

The only reason for strong typing is, let's face it, performance.

Page 58: Dear compiler  please don't be my nanny v2

La la land's where weak typing goes

The only reason for strong typing is, let's face it, performance.

Why, oh why, does C# insist I put an f on my floats?

Page 59: Dear compiler  please don't be my nanny v2

La la land's where weak typing goes

The only* reason for strong typing is, let's face it, performance.

Why, oh why, does C# insist I put an f on my floats?

float f = 10.5;// come on compiler, be sensible// It feels like I spend most of my// fixing this when you complain

* Disclaimer: This is a rant

Page 60: Dear compiler  please don't be my nanny v2

La la land's where weak typing goes

float f = 10.5;

Page 61: Dear compiler  please don't be my nanny v2

La la land's where weak typing goes

float f = 10.5;It's a constant! What on earth does the error serve?

Page 62: Dear compiler  please don't be my nanny v2

La la land's where weak typing goes

float f = 10.5;Here's what would happen if you relaxed...

Page 63: Dear compiler  please don't be my nanny v2

La la land's where weak typing goes

float f = 10.5;Here's what would happen if you relaxed...

Nothing....

Page 64: Dear compiler  please don't be my nanny v2

La la land's where weak typing goes

And this:Tank tank = GetObject("Tank") as Tank;

Page 65: Dear compiler  please don't be my nanny v2

La la land's where weak typing goes

And this:Tank tank = GetObject("Tank") as Tank;

OK, got it, it's a Tank!

Page 66: Dear compiler  please don't be my nanny v2

La la land's where weak typing goes

And this:Tank tank = GetObject("Tank") as Tank;

OK, got it, it's a Tank!

Page 67: Dear compiler  please don't be my nanny v2

La la land's where weak typing goes

And this:Tank tank = GetObject("Tank") as Tank;

OK, got it, it's a Tank!

Page 68: Dear compiler  please don't be my nanny v2

La la land's where weak typing goes

And this:Tank tank = GetObject("Tank") as Tank;

OK, got it, it's a Tank!

This is a tank

Page 69: Dear compiler  please don't be my nanny v2

Ti's right to make everything private

Page 70: Dear compiler  please don't be my nanny v2

Ti's right to make everything private

It started innocently enough, as:

class Foo {public:

int share_this;int share_that;// ...

}

But then this was seen as too easy by the designers of C#.

Page 71: Dear compiler  please don't be my nanny v2

Ti's right to make everything private

Since they decided that sharing information should be painful to a programmer, they insisted on:

class Foo {public int share_this;public int share_that;

// ...}

Page 72: Dear compiler  please don't be my nanny v2

Ti's right to make everything private

Since they decided that sharing information should be painful to a programmer, they insisted on:

class Foo {public int share_this;public int share_that;

// ...}

// uh uh, wait...

Page 73: Dear compiler  please don't be my nanny v2

Ti's right to make everything private

Since they decided that sharing information should be painful to a programmer, they insisted on:

public class Foo {public int share_this;public int share_that;

// ...}

Page 74: Dear compiler  please don't be my nanny v2

Ti's right to make everything private

Of course, after a while you get sick of having your compiles fail....

Page 75: Dear compiler  please don't be my nanny v2

Ti's right to make everything private

Of course, after a while you get sick of having your compiles fail....

...So you just put public in front of everything.

Page 76: Dear compiler  please don't be my nanny v2

Ti's right to make everything private● Typing public all the time is tedious

Page 77: Dear compiler  please don't be my nanny v2

Ti's right to make everything private● Typing public all the time is tedious● It slows you down when you forget

Page 78: Dear compiler  please don't be my nanny v2

Ti's right to make everything private● Typing public all the time is tedious● It slows you down when you forget● 95% of the code you write will never be part of some giant

architecture.

Page 79: Dear compiler  please don't be my nanny v2

Ti's right to make everything private● Typing public all the time is tedious● It slows you down when you forget● 95% of the code you write will never be part of some giant

architecture.● When you a prototyping you often do not know in advance

what you want to be public

Page 80: Dear compiler  please don't be my nanny v2

Ti's right to make everything private● Typing public all the time is tedious● It slows you down when you forget● 95% of the code you write will never be part of some giant

architecture.● When you a prototyping you often do not know in advance

what you want to be public● Because C# does not support the friend keyword, there is no

easy way to make data visible only to certain objects, so you make everything public anyway.

Page 81: Dear compiler  please don't be my nanny v2

Ti's right to make everything private● Typing public all the time is tedious● It slows you down when you forget● 95% of the code you write will never be part of some giant

architecture.● When you a prototyping you often do not know in advance

what you want to be public● Because C# does not support the friend keyword, there is no

easy way to make data visible only to certain objects, so you make everything public anyway.

● It's not even the right kind of privacy

Page 82: Dear compiler  please don't be my nanny v2

Ti's right to make everything private

What you really want is interfaces that can only be called by authorised modules...

Page 83: Dear compiler  please don't be my nanny v2

Ti's right to make everything private

What you really want is interfaces that can only be called by authorised modules...

Maybe it would be good if only certain modules are authorised to call AddFunds()?

Page 84: Dear compiler  please don't be my nanny v2

Ti's right to make everything private

What you really want is interfaces that can only be called by authorised modules...

Maybe it would be good if only certain modules are authorised to call AddFunds()?

Page 85: Dear compiler  please don't be my nanny v2

And that brings us back to Don't.

● Don't think you know my needs better than me

Page 86: Dear compiler  please don't be my nanny v2

And that brings us back to Don't.

● Don't think you know my needs better than me● Don't take my tools away

Page 87: Dear compiler  please don't be my nanny v2

And that brings us back to Don't.

● Don't think you know my needs better than me● Don't take my tools away● Don't restrict creativity

Page 88: Dear compiler  please don't be my nanny v2

And that brings us back to Don't.

● Don't think you know my needs better than me● Don't take my tools away● Don't restrict creativity● Don't complicate the simple in the name of an ideal

Page 89: Dear compiler  please don't be my nanny v2

And that brings us back to Don't.

● Don't think you know my needs better than me● Don't take my tools away● Don't restrict creativity● Don't complicate the simple in the name of an ideal● Don't stop me doing what needs to be done

Page 90: Dear compiler  please don't be my nanny v2

And that brings us back to Don't.

● Don't think you know my needs better than me● Don't take my tools away● Don't restrict creativity● Don't complicate the simple in the name of an ideal● Don't stop me doing what needs to be done● Don't keep arguing with me

Page 91: Dear compiler  please don't be my nanny v2

And that brings us back to Don't.

● Don't think you know my needs better than me● Don't take my tools away● Don't restrict creativity● Don't complicate the simple in the name of an ideal● Don't stop me doing what needs to be done● Don't keep arguing with me● Don't get in my way

Page 92: Dear compiler  please don't be my nanny v2

Don’t Bring Me Down