Closed sindresorhus closed 7 years ago
The util class should be added to the package.json, right? Otherwise it will not be packaged when we publish to npm registry...
@StefMa No, the binary is compiled before publish.
I would try to avoid force unwrapping as much as possible. Even where you think its okay to crash I prefer using fatalError("My message") to get more meaningful error messages than the usual "unexpectedly found nil while unwrapping an Optional value"
What's the convention for when to mark your function with throws
, silencing with try?
, printing an error and returning nil, or fatalError
? It seems like very few APIs throw with useful error messages. Usually it's up to you to handle almost every method call, which gets verbose. I kinda feel like error handling is not yet completely figured out in Swift.
I would also consider using Swift Package Manager, and using Commander or something similar to handle command line arguments.
I'm actually planning to go in another direction: https://github.com/wulkano/aperture/issues/8#issuecomment-275308988 Could use your thoughts on the issue.
Id be happy to help out if you need anything :)
That's is very nice of you. I'm already learning a lot. Will let you know :)
I would only fatalError()
there is no way of continuing execution without unexpected results.
return nil for "not found" or "invalid input" cases.
use throw if you need more information about what went wrong. You can pass along error info, and even pattern match on the error to take different actions depending on what went wrong.
use try? if you just wanna know if you got a value back or not, and don't care what the error was.
Once you get used to the swift error handling its actually quite nice. A lot of cocoa APIs are ObjC APIs, the errors thrown are NSErrors so they are not as useful as swift ones with enums for example..
Note that errors are not typed so its useful to explain what errors can be thrown in the doc block..
Awesome. Landed \o/
Thanks for all the feedback @LarsJK. I learned a lot and feel more confident in my Swift abilities now.
Btw, I did some minor additional tweaks, would you mind just checking that I didn't do anything bad: https://github.com/wulkano/aperture/pull/26/commits/b711276a4e590e6d69e16ba44c5119b006f05133 ?
And improve and simplify a lot of the code
Swift errors will now make it all the way to Kap