Earlier quoted context omitted.
I don't understand what you're saying here. #pragma once does the job that include guards used to do, but with less work, and in a less error prone way. How is it broken, and how is the size of a project relevant?
> I don't understand what you're saying here. #pragma once does the job that include guards used to do, (...) They don't. They are not C++ and at most they are compiler-specific. It's fine if you opt to not write C++ and instead target specific compilers instead. Just don't pretend it's not frowned upon or kosher.
Show HN: CXXStateTree – A modern C++ library for hierarchical state machines
21–30 of 37 posts
Re: Show HN: CXXStateTree – A modern C++ library for hierarchical state machines
#22i am by no means a C++ expert, but isn't "pragma once" frowned upon?
In the C++ community (as lots of other things are), rejecting `#pragma once` is a long-standing tradition of worshipping the decaying body of prehistoric compilers for
It's unclear what benefits this approach has achieved, but don't disturb it, or else.
Re: Show HN: CXXStateTree – A modern C++ library for hierarchical state machines
#23i am by no means a C++ expert, but isn't "pragma once" frowned upon?
But given that I haven't seen any mention of that issue in other comments, I wonder if it really is an issue.
Re: Show HN: CXXStateTree – A modern C++ library for hierarchical state machines
#24Earlier quoted context omitted.
> What major compiler does not support it? The whole point is that it's not supported and it's not standard, thus using #pragma once needlessly introduced the risk of having the code break. You should ask yourself what are you doing and why are you using non-standard constructs that may or may not work, specially when it's rather obvious and trivial to just use include guards. Using #pragma once isn't even qualify as…
The whole point of C/C++ is knowing your environment. It's not Java, it's not TypeScript. It's one level above assembly, and if you change the compiler and things break, then it's your fault. If the standards still don't have a proper replacement for include guards, then too bad for the standards. The C++ standard wasn't aware of multithreading before C++11, this didn't stop people from writing multithreaded programs…
It does with modules... and in ten year if modules support is widespread, I'll consider stoping using pragma once.
Re: Show HN: CXXStateTree – A modern C++ library for hierarchical state machines
#25there are about 1 million c++ state machines, and sml happens to be the best, or one of them. how does yours differentiate?
Re: Show HN: CXXStateTree – A modern C++ library for hierarchical state machines
#26Earlier quoted context omitted.
What major compiler does not support it?
> What major compiler does not support it? The whole point is that it's not supported and it's not standard, thus using #pragma once needlessly introduced the risk of having the code break. You should ask yourself what are you doing and why are you using non-standard constructs that may or may not work, specially when it's rather obvious and trivial to just use include guards. Using #pragma once isn't even qualify as…
Plus, it's nicer to read than #ifndef FOO_BAR_BAZ_PROJ_DIR1_DIR2_DIR3_FILE_H
#endif /* FOO_BAR_BAZ_PROJ_DIR1_DIR2_DIR3_FILE_H */
On every file.
Re: Show HN: CXXStateTree – A modern C++ library for hierarchical state machines
#27how is it better than https://github.com/boost-ext/sml ? there are about 1 million c++ state machines, and sml happens to be the best, or one of them. how does yours differentiate?
What exactly happened there? It looks like make_transition_table() is doing some serious magic. Or are the state transitions evaluated at compile-time given that there is no input in the example, and then the transition table gets compiled out?
Anyway, I think it would help OP's library to have some assembly output in the readme as well.
Re: Show HN: CXXStateTree – A modern C++ library for hierarchical state machines
#28i am by no means a C++ expert, but isn't "pragma once" frowned upon?
`#pragma once` seems to be far preferred for internal code, there's an argument for being strictly conforming if you're putting out a library. I've converted stuff to `#ifndef` before sharing it, but I think heavy C++ people usually type `#pragma once` in the privacy of their own little repository.
- `spdlog`: `#pragma once` https://github.com/gabime/spdlog/blob/v1.x/include/spdlog/as...
- `absl`: `#ifndef` https://github.com/abseil/abseil-cpp/blob/master/absl/base/a...
- `zpp_bits`: `#ifndef` https://github.com/eyalz800/zpp_bits/blob/main/zpp_bits.h
- `stringzilla` `#ifndef` https://github.com/ashvardanian/StringZilla/blob/main/includ...
Re: Show HN: CXXStateTree – A modern C++ library for hierarchical state machines
#29how is it better than https://github.com/boost-ext/sml ? there are about 1 million c++ state machines, and sml happens to be the best, or one of them. how does yours differentiate?
I was about to complain about the use of strings in both libraries, both for the lack of type safety as well as the possible runtime allocation, but then I looked at the assembly for the sml example and there are no strings in the binary other than the obvious "send" one. What exactly happened there? It looks like make_transition_table() is doing some serious magic. Or are the state transitions evaluated at compile-t…
[0]: https://en.cppreference.com/w/cpp/language/user_literal.html
[1]: https://github.com/boost-ext/sml/blob/f232328b49adf708737bef...
Re: Show HN: CXXStateTree – A modern C++ library for hierarchical state machines
#30Related idea for those using python: https://github.com/baymotion/smax .