News for hackers. Stuff that matters.
Re:The Use of assert() in SQLite by shaklee3 on Friday April 26, 2019 @09:30PM (#19763178)
> The SQLite developers believe that the lack of assert() disqualifies Go as a language for serious development work.

Great comment.

Re:The Use of assert() in SQLite by zaroth on Friday April 26, 2019 @10:05PM (#19763319)
It seemed random and out of place to me. Like some sort of Wiki vandalism.

Why do I care about their opinion of Go in SQLite dev docs?

Re:The Use of assert() in SQLite by smitty1e on Friday April 26, 2019 @10:07PM (#19763326)
Whoever wrote that was probably shooting from the Hipp.
Re:The Use of assert() in SQLite by geezerjay on Saturday April 27, 2019 @02:38AM (#19764174)
> Why do I care about their opinion of Go in SQLite dev docs?

Apparently some peoplr care, considering the number of comments on how Go can, does and should handle this usecase.

Re:The Use of assert() in SQLite by rileymat2 on Friday April 26, 2019 @09:36PM (#19763208)
I did not understand this comment, as they also wrote ALWAYS, NEVER and testcase. Why could you not write your own assert in Go? (I have not programmed in Go)
Re:The Use of assert() in SQLite by fwip on Friday April 26, 2019 @10:17PM (#19763365)
I dunno either, because it's incredibly trivial.

    func assert(cond bool){
      if !cond {
        panic("whoopsies")
       }
    }
Re:The Use of assert() in SQLite by rabidrat on Friday April 26, 2019 @11:01PM (#19763499)
And then you can just #define assert(...) to eliminate it...oh wait, Go doesn't have a macro-preprocessor.
Re:The Use of assert() in SQLite by pstuart on Friday April 26, 2019 @11:09PM (#19763531)
To play along....

Go does have build tags, so one could have 2 files for the assert function, each with opposite build tag logic. It does allow for an effective NOP (it would be a stub function and I believe the compiler would eliminate that).

Re:The Use of assert() in SQLite by helper on Saturday April 27, 2019 @12:00AM (#19763695)
I tested this and it does indeed eliminate that code.
Re:The Use of assert() in SQLite by deathanatos on Saturday April 27, 2019 @12:19AM (#19763756)
I'm wondering if it inlines it (and thus eliminates it).

But this would come with a performance penalty: it makes the function you assert() in no longer a leaf function (it calls assert()) and AFAIK, Go only inlines leaf functions. (So, any function in which you call assert() is no longer eligible for inlining.)

Re:The Use of assert() in SQLite by helper on Saturday April 27, 2019 @12:53AM (#19763862)
chrchang523 is correct. In my test the caller function can still get inlined.
Re:The Use of assert() in SQLite by chrchang523 on Saturday April 27, 2019 @12:28AM (#19763780)
deathanatos: Go 1.12 can inline non-leaf functions, and I’d be surprised if it still fails to do the right thing here.
Re:The Use of assert() in SQLite by int_19h on Monday April 29, 2019 @01:09AM (#19775976)
It would still evaluate the condition in both cases, unless it can guarantee that the condition is a pure function with no observable side effects.
Re:The Use of assert() in SQLite by drb91 on Friday April 26, 2019 @09:39PM (#19763231)
You can always log to stderr with a stack trace and exit with a non zero static code. I’m guessing they’re referring to the fact that the built in panic keyword can be “caught” further up the stack a la an exception.
Re:The Use of assert() in SQLite by hermitdev on Friday April 26, 2019 @09:49PM (#19763275)
IMO, far better to log, then abort/core. I want to be able to inspect the state of the failed case, not just know that it failed.
Re:The Use of assert() in SQLite by catlifeonmars on Friday April 26, 2019 @10:00PM (#19763302)
It’s far better to let the caller decide. As a user of a library, I absolutely do not want a library terminating my process. Sure, some programs can benefit from this, but some programs need to guarantee that they keep running. Being able to recover (Go’s counterpart to panic()) allows the caller to decide which behavior they want.
Re:The Use of assert() in SQLite by hermitdev on Friday April 26, 2019 @10:38PM (#19763423)
I'm not sure I agree. There's a very, very small limited set of conditions that a client can recover from a condition that would trigger an assertion failure. Dont want an abort? Then use the release libs where those have been preprocesed out.

Conversely, at a former employer we used a set of 3rd party database libs for ODBC on Linux that for the smallest config error would emit nothing to stderr and call exit(1) from a shared lib. that was beyond annoying

Re:The Use of assert() in SQLite by catlifeonmars on Friday April 26, 2019 @10:50PM (#19763452)
I was afraid someone would mention preprocessing out the asserts :)

That also has its advantages, but would argue that it is impossible to selectively opt in or out.

Honestly, for a well tested piece of code, the point is moot, since the assert(s) will never evaluate false anyway.

Re:The Use of assert() in SQLite by hermitdev on Saturday April 27, 2019 @10:12PM (#19768863)
> I was afraid someone would mention preprocessing out the asserts :)

Problem is, you need to understand what you're using, and like it or not, assert is defined as a macro by the C standard. And, assert is conditionally defined (and it's not the only conditionally defined macro).

I know its long, verbose, and dry; but if you want to understand C (or C++ for that matter), you really need to read the ISO standards that correspond to the implantation.

Re:The Use of assert() in SQLite by drb91 on Sunday April 28, 2019 @01:33AM (#19769533)
You can also easily enable runtime failures so the point is indeed moot.
Re:The Use of assert() in SQLite by int_19h on Monday April 29, 2019 @01:10AM (#19775983)
If you're in the same process as the code that had its invariant fail, how can you ensure that your process is in a safe state afterwards? A failed invariant, by definition, means that you're in uncharted territory - any anticipated failures are (assuming proper design) reported via the usual error mechanisms.
Re:The Use of assert() in SQLite by marvy on Friday April 26, 2019 @09:36PM (#19763212)
To draw_down: your comments are showing up as dead,

As for assert in Go... couldn't you just make a function that takes a Boolean and panics?

Re:The Use of assert() in SQLite by everdev on Friday April 26, 2019 @10:56PM (#19763478)
You could, but then when you get an error, you'll see the file and line number of the assert function rather than the code that actually produced the error.
Re:The Use of assert() in SQLite by bbatha on Saturday April 27, 2019 @12:30AM (#19763788)
The runtime package allows you to grab the current trace, you can just pop the last frame off and print that.
Re:The Use of assert() in SQLite by everdev on Saturday April 27, 2019 @10:04AM (#19765579)
True. The only other challenge is that in production software you rarely want to call panic()
Re:The Use of assert() in SQLite by IanS5 on Saturday April 27, 2019 @12:01PM (#19766161)
As another comment mentioned you can just use build tags to make assert a no-op in release builds
Re:The Use of assert() in SQLite by rabidrat on Friday April 26, 2019 @11:01PM (#19763496)
Also, there is no way to eliminate the assert clause in a high-performance (release) build.