Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
tines
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
62 ms
·
871.
▲
by
tines
8y ago
Depends. If you define fp as being manipulation of immutable data (i.e. math-like), then it’s quite feasible in C++. Gimmick or no, templates aren’t even necessary.
872.
▲
by
tines
8y ago
> Those structures act like the wings of a bird or aeroplane, generating pressure differences above and below the wing to fly. I thought we had settled this, airplane wings work by deflecting air downward, not by the Bernoulli effect, ri
873.
▲
by
tines
9y ago
Sorry, I’m not familiar with what a TCB is, and google isn’t being helpful. do you have a link I could read?
874.
▲
by
tines
9y ago
That’s the thing - it has to be audited manually. I’m sure I won’t convince you here of the value of static typing but some people think it is.
875.
▲
by
tines
9y ago
This isn't type safe though, namely this part: aPerson = list_entry(node, struct Person, list); while the templated way is.
876.
▲
by
tines
9y ago
Sorry, good point. But C++ gives you templates as well as template metaprogramming, so my point still stands.
877.
▲
by
tines
9y ago
> You shouldn't need dispatching or template metaprogramming in a microkernel, as code reuse is minimal since all primitives are supposed to be orthogonal to each other. Orthogonality doesn’t obviate the need for metaprogramming tho
878.
▲
by
tines
9y ago
Usually because a build script depends on their existence or something.
879.
▲
by
tines
9y ago
>> 50 years from now when there is one person left working and 300 million retired people (I exaggerate to make the point), that guy is going to pretty busy since he’ll have to grow all the food, build and maintain all the buildings,
880.
▲
by
tines
9y ago
It seems like this article is essentially complaining about the language giving you too much control (e.g. in his copy assignment operator example), when that's exactly what its goal is.
881.
▲
by
tines
10y ago
The fact that he mentions type driven development probably means that he has dependent typing around, probably as seen in the language Idris, whose recently published book is called the same. Idris is very much not just an abstract language
882.
▲
by
tines
10y ago
Yep, macros are the only motivation needed for wrapping a language like C, and this project does a lot more than that. I've tried to come up with a way to do this myself, but I always hit a wall when it comes to integrating with the C
883.
▲
by
tines
10y ago
The paper linked anticipates your question in the sentences after grandparent's quote: > The blow-up is not due simply to the fact that we used C++ instead of pseudo notation, nor because our code style may have been verbose. Conver
884.
▲
by
tines
10y ago
Yes, but they are not conflicting in the sense that they are competing to serve the same purpose. For exploratory programming, dynamic type systems are nice. For building reliable long-running systems or ones where failure is extremely cost
885.
▲
by
tines
10y ago
This is fantastic! Forth's simplicity is a great fit for exploratory programming on resource-constrained systems, and I'm a fan of anything homoiconic. Maybe one day I'll get my dream of having a forth or lisp with the type s
886.
▲
by
tines
10y ago
Actually now that I think about it, it might be better to just make a typedef and then you can go back to using the same name everywhere. I think that would solve the problem. This technique seems to take care of the bulk of the use of temp
887.
▲
by
tines
10y ago
This is a cool technique, but I tried compiling the first block of code you posted (with ARRAY_ELEMENT_TYPE being defined to be int* ) and got "error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token" from gcc 6.2
888.
▲
by
tines
10y ago
I think the main drawback for every C implementation, including this one, is that you still have to write a new version of every algorithm for every type that you want to use your array struct with, unless you put all your functions in macr
889.
▲
by
tines
10y ago
This way you either have to declare every type you want to use this with at file scope (which is fine and some people do this, but it's a little irksome), or not be able to pass them as parameters to functions. Also it doesn't sol
890.
▲
by
tines
10y ago
You can't have the STL containers without templates though. If you want to special-case them in the compiler, then what about the algorithms library? If you want to keep the algorithms library, then what about your own code that implem
891.
▲
by
tines
10y ago
Ah good catch, I misread it.
892.
▲
by
tines
10y ago
Yes, but for the vector methods, you leave that decision up to the compiler which should be able to take the best route.
893.
▲
by
tines
10y ago
Your criticisms of vector are well put, but if anything they're all really problems with a particular implementation of the standard library, not the C++ language. If you make your own libraries you're free to do whatever you want
894.
▲
by
tines
10y ago
> Maybe approaching C++ as "C with Templates" is a more promising route. Genius. I'm doing this from now on.
895.
▲
by
tines
10y ago
It will help you either use std::vector with a custom allocator that does not throw exceptions, or else write your own non-throwing vector class with templates, which would, I hope, be more maintainable and easier to use correctly than an e
896.
▲
by
tines
10y ago
This gets messy in a couple of ways; for example, what if you want to pass two of them to a function? Then the names of the parameters generated by the ARRAY_ARG macro will clash and you'll have to add a counter to it, etc. (Also I
897.
▲
by
tines
10y ago
I'm not familiar with this approach, but I think it would entail code size increase for each use of the macros, and a runtime overhead for the typeof checks, correct? If so, C++ has a nice advantage in that all the type checks are at c
898.
▲
by
tines
10y ago
std::vector does indeed have at least one pointer member (otherwise you couldn't have a std::vector with automatic storage duration because the size would be unknowable) so there is some indirection. Maybe you're thinking of std::
899.
▲
by
tines
10y ago
I agree, which is why I mentioned that you can do what this article suggests without using anything except functions and structs. No classes or class features required.
900.
▲
by
tines
10y ago
> What if we want to be able to store more than integers in our dynamic array ? [...] The array_push_back function also needs to be refactored in order to account for the size and type of what we store in the data buffer. A possible appr
More ›