Go doesn't provide assertions. They are undeniably convenient, but our experience has been that programmers use them as a crutch to avoid thinking about proper error handling and reporting. Proper error handling means that servers continue operation after non-fatal errors instead of crashing. Proper error reporting means that errors are direct and to the point, saving the programmer from interpreting a large crash trace. Precise errors are particularly important when the programmer seeing the errors is not familiar with the code.
As regular visitor of /prog/ autism/general, I strongly disagree.
Name:
Anonymous2011-02-08 0:09
An assert will do the same thing as an unchecked exception would, the only exception is that the assert (normally) should not be kept for the final product.
If you build a safety net for yourself while debugging and building the system why would you deny this safety net for the actual enduser of the code. Use exceptions exclusively for both asserts and exceptional situations. By creating an appropriate exception hierarchy you will be able to discern very quickly one from the other. Except this time the assert remains in place and can provide valuable information in case of failure that would otherwise be lost.
So I fully understand the creators of Go by removing asserts altogether and forcing programmers to use exceptions to handle the situation. There is a simple explanation for this, exception are just a better mechanism for the job why stick with the archaic asserts?
>>7
why would you want to throw an exception for a bug in your program? The whole point of assert is that after you see one, something already went wrong, and a method for continuing from that state has either not been thought of or at least has not been implemented. If you have code with asserts in other situations, then yes, it could make sense to throw instead. But it's pretty common to use assert to check something about function params, and easier to debug with a c++ debugger, than to throw an InvalidArgException or something.
Name:
Anonymous2011-02-08 16:51
assert(true)
if !(true){
panic("Assert failed in module herp on line derp.");
}
If you're writing a complete software application and don't have any facilities for third party plugins, or aren't writing a plugin/component for another system, then you have no reason to recover from application errors--any errors you didn't foresee are your own fault, and the program is already fucked, you might as well just abort and have the user restart it.
Exception handling is quite useful, but it shouldn't be used to recover from your own fucking errors. It should be used to recover from exceptional system conditions, like maybe your application doesn't have correct security permission to access a particular file. Or it should be used to notify other components of exceptional conditions if you're writing a driver/component/etc. for some other system. Keep in mind that exception handling has a fair amount of overhead as it increases code bloat and thus instruction cache misses. In C++, turning exception handling off at the compiler level (-fno-except in GCC), can cut your binary size down by as much as 15%-20%.
Most game developers don't use exception handling, at least not on consoles, instead they use a lot of asserts as they're developing something they have full control over.
>>21
What Python forced so far: Indentation of code.
One-linerization of lambdas
Statementification of assignments.
What Go forced so far: Capitalization of exported symbols
Stringization of imported modules
Handling of exceptions.
K&Rification of code (>>20)
Now I understand why they said it's ``based on Python''.
>>20
People that use that code style deserve to die anyway,
Name:
Anonymous2011-02-08 18:38
>>23
So it forces the use of error return codes for error propagation from all functions?
Name:
Anonymous2011-02-08 18:49
No, neither goto nor assert are evil. But both can be misused.
Assert is for sanity checks. Things that should kill the program if they are not correct. Not for validation or as a replacement for error handling.
Name:
Anonymous2011-02-08 18:50
>>24
Go has panic("reason") and recover() for times when control flow should stop (similar to assert, but doesn't automatically kill everything).
In place of exceptions, there's a convention where functions that can error should return a second value indicating if there was an error, so: func readFile(fileName string) (result string, err os.Error){
blah
}
// Then, you do the following
result, err = readFile("blah")
if err != nil{
// That didn't execute properly
}
>>25
It doesn't have anything that's considered harmful:
no gotos, no asserts, NO EXCEPTIONS, no templates, no generics, no macros, no Lisp macros (yes, they really think they are harmful), no metaprogramming support, no continuations, ....
>>25
I beg to differ on goto. assert offers something useful, something that can't be easily replaced. I've yet to see a problem where a goto was actually the best solution.
>>34 http://www.antiifcampaign.com/
I thought, I'm the only who is that smart, because in my Lisp DSL I dont use `if`s at all.
{symbol? -> handleSymbol; else -> error "go fuck your mom"}
CAR CAR CAR CAR CDR CDR CDR CDR CAR CDR EVAL APPLY CAR CDR EVAL APPLY CAR CDR EVAL APPLY CAR CDR EVAL APPLY CAR CDR EVAL APPLY CAR CDR EVAL APPLY
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPUTER WITH OUR SPELLS
WE CONJURE THE SPIRITS OF THE COMPU
>>36
and, btw, these guys talking about replacing `if`s with dispatchers, that is just a form of limited pattern matching. The same stuff parsers, like bison, do.
implying he has a parser
Even a recursive descent parser is a parser. Even a stupid code walker must do some parsing. Infix notation needs a parser aware of the operators' precedence.