Yeah, we do. However, since our primary audience of people we are talking to are on a Mac/iOS device, it doesn't really matter. And when we are on a non-Mac, we know what the square box symbol is supposed to be.
int foo(int bar):
// network call here
// write a log to disk here
// change a global value here
return happy_int
And you are woefully mistaken about about this claim as well: "it must work with the list I passed it, because it doesn't know anything else." f(x, y) = z
Where z is the mathematical sum of x and y. f :: [a] -> a
Is no harder to test in a dynamic language. let r = f([...])
assert(r, correct_value)
assert(r.type, correct_type)
It's up to the contract of the function to determine what, if any, validation needs to be done on the input. This is true regardless of type system. The only question is this: do you also check the type. 1. x <= TYPE_MAX (for free in a statically typed system)
2. x <= TYPE_MAX - y
3. y <= TYPE_MAX (for free in a statically typed system)
4. y <= TYPE_MAX - x
Plus the similar for TYPE_MIN. In the `addbase2` example, additional constraints are: 1. x power of 2
2. y power of 2
In this example, we still need to add verification for two-thirds of the constraints. def add(x, y)
assert x is int
assert y in int
return x + y
// test cases
assertIsThrown(add("foo", "bar"))
That was the test case you had. add((short)0, (long)1) // compiler error if you have an extremely rigid type system
Generic systems typically swing the pendulum far to the right requiring an extremely rigid type system. That always causes pain. The question you have to ask, is the ROI worth it. For some, it is. For others, it's not. // some collection we are holding the values in for some reason
NSMutableArray *inputValues = [[NSMutableArray alloc] init];
NSString *someInputValue = // probably read from user input or a file
NSInteger value = [someInputValue integerValue];
BOOL validInput = YES;
if (value == 0) { // we need to check that there really is a value of 0...
NSString *trimmed = [someInputValue stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
NSString *trimmed0 = [trimmed stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"0"]];
if (trimmed0.length != 0) {
// oops, actually had an error... handle it
validInput = NO;
}
}
if (validInput) {
[inputValues addObject:@(value)];
}
Of all of the places where could have had errors along the way, the last `[inputValues addObject:@(value)];` doesn't really concern me that much.