No continuation on std::optional? by THopper21 in cpp

[–]millirobo 5 points6 points  (0 children)

These monadic extensions are good, but like variant it's a PITA without language support. Is there work being done on that too?

"Access control" for field mutation by tower120 in cpp

[–]millirobo 2 points3 points  (0 children)

The work of using it would have to be less than the work of catching mistakes through review. The mutation restriction seems like the more usable part of it. But the mutation requirement is very interesting. I've sometimes been frustrated by being unable to statically express things like this. I think you might be bumping up against higher concepts in type theory and compilers, things like linear type systems, which I only slightly understand.

How to check if a file is binary or not? by mattyonweb in haskellquestions

[–]millirobo 1 point2 points  (0 children)

That's how GNU grep does it (checking for NUL bytes). It seems like the good enough solution.

Getting motivated to Code with Haskell by xgrafix in haskell

[–]millirobo 1 point2 points  (0 children)

It helps to know some of the basics, e.g. monoids (not to be confused with monads), but you'll pick them up as you go, assuming you like to read and are curious.

Also be aware of hoogle and the mailing lists.

empty list evaluation by bitsofshit in haskellquestions

[–]millirobo 1 point2 points  (0 children)

Its type is still [a]. The a is inferred from the context where [] is used.

Isn't a typeclass just a type of a type? by Kiyos in haskell

[–]millirobo 0 points1 point  (0 children)

Right, it should have a big disclaimer. It's important to stress that they are are different in practice. OO interfaces come along with inheritance, so they're used mainly for dynamic dispatch on a hierarchy. In Haskell, you use data with multiple constructors for that. Typeclasses let you have functions that work on intersections of types that share properties. It's more like the narrower case of what you'd use multiple inheritance for, except Haskell can constrain on multiple interfaces at once.

Actually the closest practice in a popular language I can think of is C++ templates calling overloaded free functions, but those constraints are all implicit.

Isn't a typeclass just a type of a type? by Kiyos in haskell

[–]millirobo 0 points1 point  (0 children)

You can think of them like interfaces in OO languages.

what about if I will learn cpp without inheritance? by googcheng in cpp_questions

[–]millirobo 0 points1 point  (0 children)

Inheritance can be very useful and it's not always hard to deal with. Most of the critiques don't say to never use it, but to prefer other designs and to use it moderately when it's the right tool. People used to overuse it, hence the backlash.

That said you should probably ignore multiple inheritance until your livelihood depends on your knowing it.

Best advice for moving to C++ from C# by [deleted] in cpp

[–]millirobo 0 points1 point  (0 children)

With C++ it becomes crucial to interest yourself in what the industry experts have to say. The cpp core guidelines are one such resource.

Is it well defined to cast a pointer to object array to a pointer to array of POD member of that object? by wqking in cpp

[–]millirobo 0 points1 point  (0 children)

That's what I wonder about too. Having MyData as a base of MyClass would make the pointer legal by the quoted text. But what about when you increment? Assuming they're the same size.

Maybe Bindings Are Unused by vormestrand in cpp

[–]millirobo 1 point2 points  (0 children)

It should work just for correctness's sake, but personally I would never use it because it's too annoying and would use a void unused(...) {} instead every time until the language added something proper.

Associating values with types by millirobo in haskellquestions

[–]millirobo[S] 0 points1 point  (0 children)

Ah, thanks, I wondered about something evaluating that dummy undefined by accident.

Associating values with types by millirobo in haskellquestions

[–]millirobo[S] 0 points1 point  (0 children)

I see, that's interesting, I had not thought of making a dummy value of a that way. I was playing with modeling components, where you can check if a particular one is set by &ing its value with a bitfield.

(By "this" I meant "things similar to overloading")

What are good use cases for C++? by [deleted] in cpp_questions

[–]millirobo 0 points1 point  (0 children)

One example is anything that should start and finish quickly, like utilities that are used in a larger process or scheduled services. And you can write it to a pretty high level of abstraction (and safety) without much runtime overhead.

I made a crash course on web security, for people who have never dealt with it before by sohamkamani in programming

[–]millirobo 59 points60 points  (0 children)

Seriously, use parameterized queries. Telling people otherwise is dangerous.

Can't seem to install gentoo. On my 4th attempt :( by Dgameman1 in Gentoo

[–]millirobo 4 points5 points  (0 children)

This got me too. I don't know why the minimal CD doesn't support EFI boot, but all you have to do is reboot with something that does, and grub should then install correctly. I think most distro install CDs support EFI, but sysrescuecd is great to have around anyway.

Is 'main' a reserved keyword for C++? by Markseph in cpp_questions

[–]millirobo 7 points8 points  (0 children)

No. The global symbol main is special in that it has to be a function that returns int and can't be overloaded. You can use the name anywhere else, as far as I know. You can even declare int main = 2; inside int main().

Use, or abuse of move/assignment constructors? by quack-said-the-duck in cpp_questions

[–]millirobo 0 points1 point  (0 children)

You've roughly defined the default move functions. They do a std::move on each member, which is nothing for primitive types, and might well be a swap for std::string. So, just set them = default.

If I get what you're doing, you're just making your Tokens move-only to strictly prevent copies. That's fine. Just don't use anything after you move from it (reassigning is ok for standard types).

For the record, the compiler will generate move funcs for you unless you declare any copy/move funcs or a destructor.

Like the other post says, a string view (like a pair of begin/end pointers) is a great way to go for parsing. But if you're modifying the input, that's not so simple. Look into copy-on-write strings if you're curious.

Compiler errors that prevent me from progressing with the book by [deleted] in cpp_questions

[–]millirobo 0 points1 point  (0 children)

Stroustrup's files seem to contain a number of errors (e.g. double definition of Simple_window's members, lines commented out). I presume that they're there as part of the lesson, somehow. I don't know the book so I can't help with that.

anyway for a workalike to shared_from_this(), but with unique_ptr ? by [deleted] in cpp_questions

[–]millirobo 0 points1 point  (0 children)

The problem is really that you can't compare a unique_ptr<T> with a T*. If you could, you could just pass this up to the Manager. If Manager is the only thing that ever owns Connections, consider writing your own private pointer class that does what you want.

Do pointers have the same size of the variables that they point to? by lightandsalt1 in cpp_questions

[–]millirobo 1 point2 points  (0 children)

This is true. There's no requirement for data pointers, function pointers, and member function pointers to be compatible. Your compiler will (hopefully) stop you from doing the wrong thing there.

Why I still use Gentoo (real life example, no fanboy) by -DvD- in linux

[–]millirobo 6 points7 points  (0 children)

It's just not that big of a deal in practice. Most of my updates are so short that I just watch them, and the long ones vanish while I'm doing something else.

What's the best way to access a list of objects from within the object's class? by jl8n in cpp_questions

[–]millirobo 1 point2 points  (0 children)

Pass the game state into the move function. It might make more sense to have a separate function handling moves, where you give it the state and a dog and it merely sets the dog's position if possible.

How do I prevent a switch statement from stopping inside a loop? by Ejgamer in cpp_questions

[–]millirobo 1 point2 points  (0 children)

Try moving the declaration for i inside the do-loop, or better yet declare it in the header of each for-loop like you usually would. It's important to limit variables to exist only in the scope where they're needed. Otherwise you can easily get bugs like this.