I would prefer that warning/error/todo/fixme
were provided as special functions that take StaticString
, rather than #directives
.
I find that TODOs are really often related to temporary values in cases when the data sources are not yet set up, something like:
// TODO: Hook up to weather data source
let outsideTemperature = 123
So I wrote 2 really useful functions:
func TODO(_ message: StaticString? = nil) {
if let s = message { print("TODO: \(s)") }
}
@discardableResult
func TODO<T>(_ message: StaticString? = nil, _ temporaryValue: T) -> T {
if let s = message { print("TODO: \(s)") }
return temporaryValue
}
They use print
, but the compiler could implement to issue a warning at compile-time and to just forward the temporaryValue
as the expression result, at runtime. So now when I write my temporary value, it's coupled to the fact that it's a TODO temporary, with an explanatory message.
let outsideTemperature = TODO("Hook up to weather data source", 123)
and I can find all of my TODOs by pulling up the call hierarchy for these 2 functions.
I think this generic value pass-through would be really useful to have in warning
, error
, TODO
and FIXME
(the exact names could vary, i'm just following the comment convention).