3 ms·
> Disagree. I don't like either Scala nor ES - but "const" is really confusing. It implies that whatever we store is constant, but it's not. I can store a mutab
by zosima 5y ago
> Disagree. I don't like either Scala nor ES - but "const" is really confusing. It implies that whatever we store is constant, but it's not. I can store a mutable object and it changes whenever I want - only the reference is constant.
That's the meaning of const in C++, C and a few more languages. In most other language, it just means that the reference stored in the cell corresponding to the variable is a const, just as you say. I don't think that's too bad, except when switching languages too often.
> Scala is really lacking a way to easily support structural typing like typescript does. ES clearly wins here, since in Scala you have to define the case class in advance. And while you can just use maps, you give up typesafety.
Scala has great support for structural typing. (One of it's main advantages IMHO), e.g.:
def callSpeak[A <: { def speak(): Unit }](obj: A) {
// code here ...
obj.speak()
}
- valenterry 5y ago> That's the meaning of const in C++, C and a few more languages. In most other language, it just means that the reference stored in the cell corresponding to the variable is a const, just as you say. I don't think that's too bad, except when switching languages too often. Haha, I see - it's been a long time since I used C/C++. But n terms of general understanding and in the context of languages becoming more functional I still think that const is not a great choice. But you have a good point. > Scala has great support for structural typing. (One of it's main advantages IMHO), e.g.: I would not call this great support. If the support were really so good, there would be no or much less need for things like shapeless and chimney. In your example you make it so that you can pass any object that has a speak method and yeah, that works. But change the type of speak to Integer, add another one for string and then create (not pass!) a simple data-holding object that you can pass to it, without defining a case class first. Then the syntax is not so nice. And composition for these kind of things becomes tricky quickly.