# Maybe is a problem

**URL:** <https://discuss.kotlinlang.org/t/maybe-is-a-problem/2839>\
**Category:** Language Design\
**Created:** [May 24, 2017, 9:58am UTC](https://discuss.kotlinlang.org/t/maybe-is-a-problem/2839 "2017-05-24T09:58:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![flyliufu](https://avatars.discourse-cdn.com/v4/letter/f/a3d4f5/32.png) [@flyliufu](https://discuss.kotlinlang.org/u/flyliufu)\
**Post date:** [May 24, 2017, 9:58am UTC](https://discuss.kotlinlang.org/t/maybe-is-a-problem/2839/1 "2017-05-24T09:58:26Z")

</div>

```
val x = p0.x * u * u * u * u
+4f * p1.x * u * u * u * t
+6f * p2.x * u * u * t * t
+4f * p3.x * u * t * t * t
+p4.x * t * t * t * t

logd("$x")
logd("${p0.x * u * u * u * u
    + 4f * p1.x * u * u * u * t
    + 6f * p2.x * u * u * t * t
    + 4f * p3.x * u * t * t * t
    + p4.x * t * t * t * t}")

```

Why the “x” value doesn’t equals the express’s value

D/Bezier (24518): 0.0 =\> this is x’s value  
D/Bezier (24518): 347.0 =\> this is express’s value

---

<div class="post-metadata">

**Author:** ![fvasco](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fvasco/32/1961_2.png) [@fvasco](https://discuss.kotlinlang.org/u/fvasco)\
**Post date:** [May 24, 2017, 10:04am UTC](https://discuss.kotlinlang.org/t/maybe-is-a-problem/2839/2 "2017-05-24T10:04:28Z")

</div>

“val x = p0.x \* u \* u \* u \* u” is a valid statement  
“+4f \* p1.x \* u \* u \* u \* t” is a valid statement

```
val x = p0.x * u * u * u * u +
        4f * p1.x * u * u * u * t +
        6f * p2.x * u * u * t * t +
        4f * p3.x * u * t * t * t +
        p4.x * t * t * t * t

```

is the correct statement

---

<div class="post-metadata">

**Author:** ![flyliufu](https://avatars.discourse-cdn.com/v4/letter/f/a3d4f5/32.png) [@flyliufu](https://discuss.kotlinlang.org/u/flyliufu)\
**Post date:** [May 24, 2017, 10:12am UTC](https://discuss.kotlinlang.org/t/maybe-is-a-problem/2839/3 "2017-05-24T10:12:38Z")

</div>

OH that’s right thanks for a lot

---

<div class="post-metadata">

**Author:** ![sundayrobot](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@sundayrobot](https://discuss.kotlinlang.org/u/sundayrobot)\
**Post date:** [October 12, 2017, 3:44pm UTC](https://discuss.kotlinlang.org/t/maybe-is-a-problem/2839/4 "2017-10-12T15:44:55Z")

</div>

I made the same mistake as flyliufu.  
I think that such a description should be a compile error (at least a warning).  
Even though the following description is grammatically valid, it is semantically invalid.

“+ 4f \* p1.x \* u \* u \* u \* t”

If the above description is a compile error, the following description also causes a compile error.

list.add(element)

As for this problem, I think that it can be avoided by annotating the add () method to indicate that the return value is optional.

---

<div class="post-metadata">

**Author:** ![pdvrieze](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/pdvrieze/32/1882_2.png) [@pdvrieze](https://discuss.kotlinlang.org/u/pdvrieze)\
**Post date:** [October 13, 2017, 2:53pm UTC](https://discuss.kotlinlang.org/t/maybe-is-a-problem/2839/5 "2017-10-13T14:53:45Z")

</div>

This is an unfortunate consequence of the fact that Kotlin does not require "`;` " separators for statements. Maybe `unaryPlus` could be special cased, but `unaryMinus` is a valid operator. The fact that expressions are valid statements interacts with this as well (also a desirable language design choice). As the expression could very well have side effects there is no valid way for any static analysis system to be certain what the valid code is.

---

<div class="post-metadata">

**Author:** ![sundayrobot](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@sundayrobot](https://discuss.kotlinlang.org/u/sundayrobot)\
**Post date:** [October 14, 2017, 11:22am UTC](https://discuss.kotlinlang.org/t/maybe-is-a-problem/2839/6 "2017-10-14T11:22:19Z")

</div>

Thank you for your comment.

> This is an unfortunate consequence of the fact that Kotlin does not require “;” separators for statements.

I agree.  
For programmers who are familiar with C and Java have to be aware that line breaks are different from blank characters.  
As an answer to flyliufu, I noticed that there is also “enclose the entire right-hand side with parentheses”.  
(The code with operators written at the end of the line seems a little strange to me.)

---

<div class="post-metadata">

**Author:** ![vbezhenar](https://avatars.discourse-cdn.com/v4/letter/v/35a633/32.png) [@vbezhenar](https://discuss.kotlinlang.org/u/vbezhenar)\
**Post date:** [October 14, 2017, 11:56am UTC](https://discuss.kotlinlang.org/t/maybe-is-a-problem/2839/7 "2017-10-14T11:56:17Z")

</div>

I can’t imagine why would anyone write “+1” or “-1” as a separate statement. It should be a warning, if making it an error is too late. I remember that some library used operator overloading for unary “+” for some strange thing, but it’s a clear demonstration that abusing operator overloading is a bad idea.
