Hi all, This is my first time working with a dynamically typed environment and my first instinct is to error check all arguments. For example suppose I want to create an object to represent an octet in an IP address (a number between 0 and 256) I would do something like this:
Object subclass: #Octet instanceVariables: 'octetValue' ......
initialize super initialize. octetValue := 0.
setOctetValue: numBtw0And256 octetValue = numBtw0And256 <-------Here's where I have a problem
How do I know the numBtw0And256 is actually an integer between 0 and 256 and not 'cat' or '3.14'?
Since I came from statically typed languages I feel like I writing a whole bunch of error checking code along the lines of ifIsInteger: ... etc which doesn't seem to be in the spirit of Squeak.
What am I doing wrong?
Thanks
Deech
_________________________________________________________________ WIN up to $10,000 in cash or prizes enter the Microsoft Office Live Sweepstakes http://clk.atdmt.com/MRT/go/aub0050001581mrt/direct/01/
Hi
normally you will not do explicit check. We only test when this is really important.
Hi all, This is my first time working with a dynamically typed environment and my first instinct is to error check all arguments.
No good instinct for dynamically typed :)
For example suppose I want to create an object to represent an octet in an IP address (a number between 0 and 256) I would do something like this:
Object subclass: #Octet instanceVariables: 'octetValue' ......
initialize super initialize. octetValue := 0.
setOctetValue: numBtw0And256 octetValue = numBtw0And256 <-------Here's where I have a problem
How do I know the numBtw0And256 is actually an integer between 0 and 256 and not 'cat' or '3.14'?
Since I came from statically typed languages I feel like I writing a whole bunch of error checking code along the lines of ifIsInteger: ... etc which doesn't seem to be in the spirit of Squeak.
What am I doing wrong?
Just write your code and tests! Initialize well your state. Do only check if you absolutely want in your constructor?
Thanks
Deech
WIN up to $10,000 in cash or prizes – enter the Microsoft Office Live Sweepstakes http://clk.atdmt.com/MRT/go/aub0050001581mrt/ direct/01/
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Hi
It's seem to me that is not really a dynamical typed problem but more a design problem. If you want to specifiy to the user witch object you expected you should well name them. And make unit test so your customer can understand(and you can also remember why).
Math
stephane ducasse a écrit :
Hi
normally you will not do explicit check. We only test when this is really important.
Hi all, This is my first time working with a dynamically typed environment and my first instinct is to error check all arguments.
No good instinct for dynamically typed :)
For example suppose I want to create an object to represent an octet in an IP address (a number between 0 and 256) I would do something like this:
Object subclass: #Octet instanceVariables: 'octetValue' ......
initialize super initialize. octetValue := 0.
setOctetValue: numBtw0And256 octetValue = numBtw0And256 <-------Here's where I have a problem
How do I know the numBtw0And256 is actually an integer between 0 and 256 and not 'cat' or '3.14'?
Since I came from statically typed languages I feel like I writing a whole bunch of error checking code along the lines of ifIsInteger: ... etc which doesn't seem to be in the spirit of Squeak.
What am I doing wrong?
Just write your code and tests! Initialize well your state. Do only check if you absolutely want in your constructor?
Thanks
Deech
beginners@lists.squeakfoundation.org