Conversation started Sep 13, 2015 at 13:41.
Sep 13, 2015 13:41
Earlier error checking
@milleniumbug But, this can correspond to a deeper thing: we are more able to reason about our types
It's easier to apply logic to static types rather than dynamic types of data.
Let's say f(x) calls g(x) which calls h(x) which calls l(x).
(also all these functions are templates)
Then, there's an invalid operation in l(x) (for example, you call x.non_existing_method() in there)
@milleniumbug okay
user1804599
Sep 13, 2015 13:44
safeFromJust :: Maybe a -> Maybe a
safeFromJust (Just x) = Just x
safeFromJust Nothing = Nothing
@VermillionAzure The result is that compiler shows every function name in the compile error
user406009
@edition Wow. Props to that poster. The true hero SO needs.
user406009
@elyse What about that example?
user406009
Isn't that just: safeFromJust = identity
user1804599
It's like fromJust, except total.
Sep 13, 2015 13:46
@milleniumbug Never mind the compiler error output (Yes! I know it's important but I wanted to focus on something else since concepts and compiler output are a pretty common cited corollary of concepts in C++)
user406009
@elyse Not really. Completely different type signature.
"You can't instantiate f(x) because you can't instantiate g(x) and you can't instantiate that because you can't instantiate h(x) and you can't instantiate it because you can't instantiate l(x) because non_existing_method() doesn't exist in x"
@milleniumbug And it's correct.
To be honest, if compilers could output messages graphically, everything would be much easier to see.
user1804599
@milleniumbug fuck duck typing.
@elyse Why is duck typing so bad
Sep 13, 2015 13:47
@VermillionAzure Correct, but also not very useful
user1804599
user image
6
@milleniumbug With the right tool and output format, you could theoretically translate the chain of errors and relations into some sort of graph to represent the affected parts of the program
@VermillionAzure That's how STLFilt does it, but it's specific to a single implementation
as in it translates the chains into a simpler error messages
If you declare a concept for x that a function instead, then the situation is different
@milleniumbug But that's not why concepts are useful to the code itself, right?
It can't just be prettier compiling outputs
So if you have a f(MustSatisfyAConcept x)
then if you call f(x), compiler can check if it satisfies a concept
user1804599
Sep 13, 2015 13:50
Concepts in code are useful, because now they are checked by the compiler instead of residing in the manual only.
If it doesn't it can just say
@elyse ok, that was funny
user1804599
Without concepts in code, you have to check them manually and write them down in the docs.
"x doesn't satisfy MustSatisfyAConcept in f(x)"
Concepts and types seem related to sets and maybe category theory (idk about category)
user1804599
Sep 13, 2015 13:51
With concepts in code, they are checked automatically and they are extracted into the docs automatically.
user1804599
Double win.
compare it to
4 mins ago, by milleniumbug
"You can't instantiate f(x) because you can't instantiate g(x) and you can't instantiate that because you can't instantiate h(x) and you can't instantiate it because you can't instantiate l(x) because non_existing_method() doesn't exist in x"
Also, if I'm not mistaken, concepts will allow to get rid of some SFINAE madness.
user1804599
For the same reason preconditions and postconditions should be in code, and types too (fuck Python).
Why don't people try harder to directly translate set theory and classic logic into code?
Sep 13, 2015 13:52
@VermillionAzure they're the main motivation, but there are some other benefits from concepts
user1804599
Set theory is only really interesting with infinite sets, and somehow people haven't found a nice way to encode infinite sets in memory.
Eh, Python has moved to « Types are not so bad. We can't fully show out support, but here, have type hints at least ».
@elyse But that's also not really true.
Types themselves can be considered sets in of themselves
user1804599
@Morwenn can't wait till Mypy goes stable
user1804599
it uses Python 3.5 type hints
Sep 13, 2015 13:54
The second reason C++ compile errors are terribad is because of compiler ~helpfully~ listing all the overloads if it can't fit any of them
@elyse It seems that many projects are beginning to use type hints. That's good.
user1804599
the problem is that generics won't be reified
user1804599
so downcasts are unsafe
@milleniumbug It is helpful, because otherwise debugging too strict SFINAE conditions would be a PITA.
Which is a helpful information all right, but it's too much and it gets interesting when the function declaration is template<typename T, typename std::enable_if<std::is_convertible<T>::value && std::is_whatever::value>::type* = nullptr, ...> void f(T whatever)
Sep 13, 2015 13:57
What I wanted to say was that, aren't concepts are a model to define traits or predicates that define membership of sets which model types?
user1804599
templates are pretty bad really
Concepts could also be useful there if you can overload on them
user1804599
you need something that's fully checked before instantiation, like C# generics and Rust traits
user1804599
otherwise it's just dynamic typing at compile-time, i.e. a PITA
Third reason C++ compile errors are bad is because the typedefs are substituted with a full name of the type
user1804599
Sep 13, 2015 13:59
and also not Turing-complete oh god wtf
So std::vector<std::string> becomes std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char>>>
Some compilers can help there by not listing default template arguments
I don't think you can fix this easily
user1804599
I don't see why not.
@milleniumbug figured out what I needed to do to get the msys2 installed mingw64 to work with CLion :)
The problem is that the compiler can't always tell which parameters you want to know about...
@melak47 good, good
user1804599
Sep 13, 2015 14:03
have the compiler emit HTML
user1804599
with buttons to expand types
@milleniumbug had to install the mingw-w64-x86_64-make, gdb packages, so that copies of the binaries ended up in the msys2/mingw64/bin folder where CLion looks for them
user1804599
and syntax highlighting and code formatting
user406009
@elyse Lol.
user406009
And JavaScript for interactivity as well, right?
Sep 13, 2015 14:04
well, that would help all right
I'd rather use a separate tool for that
Well yeah, that's exactly what we need: smart error message tools in IDEs instead of bare error message dumps.
So a compiler can output the info and the IDE can parse it
Lint tools and unit testing tools often produce formatted output, why couldn't a compiler do that?
 
Conversation ended Sep 13, 2015 at 14:05.