# Some nice-to-have syntax

**URL:** <https://discourse.julialang.org/t/some-nice-to-have-syntax/24331>\
**Category:** Internals & Design\
**Created:** [May 17, 2019, 6:01pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331 "2019-05-17T18:01:48Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)\
**Post date:** [May 17, 2019, 6:01pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/1 "2019-05-17T18:01:48Z")

</div>

Here’s two syntax features I think would be nice additions:

1. allow newline before `where`, so I can nicely align my arguments:

```julia
function f(x::T, y::S)
         where T <: AbstractMatrix{El}
         where S <: AbstractVector{El}
         where El <: Number
    <implementation>
end

```

1. A “Not Implemented” syntax like Perl has. In Perl, `...` is a valid expression (!), and it raises a not-implemented error:

```bash
$ perl <<PERL
> if (0) {
> print "hello, world!\n"
> } else {
> ... # TODO
> }
> PERL
Unimplemented at - line 5.

```

If I find a spare afternoon, would this be worth my time?

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [May 17, 2019, 6:14pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/2 "2019-05-17T18:14:35Z")

</div>

You can easily define a function to error

```julia
julia> ⋯() = error("Not implemented")
⋯ (generic function with 1 method)

julia> ⋯()
ERROR: Not implemented
Stacktrace:
 [1] ⋯() at ./none:1
 [2] top-level scope at none:0

```

Or perhaps the double dot

```julia
julia> ..() = error("Not implemented")
.. (generic function with 1 method)

julia> ..()
ERROR: Not implemented
Stacktrace:
 [1] ..() at ./none:1
 [2] top-level scope at none:0

```

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [May 17, 2019, 6:15pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/3 "2019-05-17T18:15:58Z")

</div>

Note that you can already do

```julia
function f(x::T, y::S) where {E1 <: Number,                            
                              T <: AbstractMatrix{E1},                 
                              S <: AbstractVector{E1}}
end

```

while I agree that it’s a little hard to know that’s exactly what you need to do (you need to remember to put `E1` first), I think it’s fairly nice syntax. Perhaps some more documentation or examples are in order.

I think it would be nice if there were a `NotImplementedError <: ErrorException` in base. It’s easy enough to implement your own, but I like the idea of standardizing it by putting it in `Base`. I can’t say I like the `...` because I don’t find it at all obvious that that’s what that means, though I guess opinions will vary on that.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [May 17, 2019, 7:18pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/4 "2019-05-17T19:18:35Z")

</div>

Or have a `@todo` macro:

```julia
macro todo()
    :(error("not implemented"))
end

```

Allowing `where` on the following line would be nice.

---

<div class="post-metadata">

**Author:** ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)\
**Post date:** [May 17, 2019, 7:34pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/5 "2019-05-17T19:34:35Z")

</div>

> [@ExpandingMan](#):
>
> I think it would be nice if there were a `NotImplementedError <: ErrorException` in base. It’s easy enough to implement your own, but I like the idea of standardizing it by putting it in `Base` .

Yes, me too. I like the `@todo` macro as a nice alternative as well. (One thing I like about `...` is that many people will write that in code snippets anyway. I found it pretty cool when it turned out to be copy-pastable and runnable in Perl.)

Is it at all possible to put new symbols in `Base` in the 1.x series, with backwards compatibility in mind?

> [@StefanKarpinski](#):
>
> Allowing `where` on the following line would be nice.

I might give that a stab some time.

---

<div class="post-metadata">

**Author:** ![haberdashPI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/haberdashpi/32/26337_2.png) [@haberdashPI](https://discourse.julialang.org/u/haberdashPI)\
**Post date:** [May 17, 2019, 8:06pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/6 "2019-05-17T20:06:00Z")

</div>

> [@tkluck](#):
>
> Is it at all possible to put new symbols in `Base` in the 1.x series, with backwards compatibility in mind?

Note that `...` is not a new symbol. It is used for function varargs and splatting (e.g. `f(x,y,rest...)`)

I agree with @ExpandingMan that this usage of `...` could be pretty confusing. I think `@todo` would be better.

---

<div class="post-metadata">

**Author:** ![cortner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cortner/32/204_2.png) [@cortner](https://discourse.julialang.org/u/cortner)\
**Post date:** [May 18, 2019, 6:35am UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/7 "2019-05-18T06:35:00Z")

</div>

+1 for where on a new line

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [May 18, 2019, 11:50am UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/8 "2019-05-18T11:50:16Z")

</div>

The multiline `where` syntax would be essential, I have much too long lines of code on many functions because of that issue.

> [@StefanKarpinski](#):
>
> Allowing `where` on the following line would be nice.

Could such a change be backported to 1.0 for compatibility, if implemented?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [May 18, 2019, 12:05pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/9 "2019-05-18T12:05:36Z")

</div>

> [@chakravala](#):
>
> Could such a change be backported to 1.0 for compatibility, if implemented?

Nope. Features are not backported.

---

<div class="post-metadata">

**Author:** ![Andrea\_Pagnani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrea_pagnani/32/3136_2.png) [@Andrea\_Pagnani](https://discourse.julialang.org/u/Andrea_Pagnani)\
**Post date:** [May 18, 2019, 2:55pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/10 "2019-05-18T14:55:50Z")

</div>

The new line before where is really a good idea!

---

<div class="post-metadata">

**Author:** ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)\
**Post date:** [May 18, 2019, 2:55pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/11 "2019-05-18T14:55:56Z")

</div>

I _almost_ thought it was easy to add newline-before-where, except that now the parser chokes on [this one here](https://github.com/JuliaLang/julia/blob/b6f10cb6066204244668b870553ea73960dee7a1/base/loading.jl#L205) 😂

I’ll see if I can easily fix this.

Unrelatedly, I just remembered a similar use case:

```julia
n = iseven(n)
  ? div(n, 2)
  : 3n + 1

```

or (according to taste)

```julia
n = iseven(n)
    ? div(n, 2)
    : 3n + 1

```

That needs a similar peek on the next line. Any opinions about that one?

---

<div class="post-metadata">

**Author:** ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Post date:** [May 18, 2019, 5:01pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/12 "2019-05-18T17:01:12Z")

</div>

We defined it ourselves in YaoBase.jl （I mean `NotImplementedError`)

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [May 18, 2019, 5:10pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/13 "2019-05-18T17:10:18Z")

</div>

> [@tkluck](#):
>
> Unrelatedly, I just remembered a similar use case:
> 
> ```julia
> n = iseven(n)
> ? div(n, 2)
> : 3n + 1
> 
> ```
> 
> or (according to taste)
> 
> ```julia
> n = iseven(n)
> ? div(n, 2)
> : 3n + 1
> 
> ```

This one should just be written

```julia
n = (iseven(n)
     ? div(n, 2)
     : 3n + 1)

```

---

<div class="post-metadata">

**Author:** ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)\
**Post date:** [May 18, 2019, 5:47pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/14 "2019-05-18T17:47:24Z")

</div>

> [@Mason](#):
>
> This one should just be written
> 
> ```julia
> n = (iseven(n)
> ? div(n, 2)
> : 3n + 1)
> 
> ```

Why?

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [May 18, 2019, 5:53pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/15 "2019-05-18T17:53:55Z")

</div>

Because it already works and it’s not horrifically ambiguous.

Making it work without the parens would put even more syntactic special cases on `?` and `:` making new uses for them even more difficult.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [May 18, 2019, 7:34pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/16 "2019-05-18T19:34:32Z")

</div>

> [@StefanKarpinski](#):
>
> Or have a `@todo` macro

Why a macro, not just a `todo` function?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [May 19, 2019, 2:03pm UTC](https://discourse.julialang.org/t/some-nice-to-have-syntax/24331/17 "2019-05-19T14:03:21Z")

</div>

Seems like slightly better syntax. But sure, it could also be a function. A macro could probably print a somewhat better message too.
