# Syntax Surprises

**URL:** <https://discourse.julialang.org/t/syntax-surprises/92369>\
**Category:** General Usage\
**Tags:** syntax, discussion, fun, gotchas\
**Created:** [December 31, 2022, 8:00pm UTC](https://discourse.julialang.org/t/syntax-surprises/92369 "2022-12-31T20:00:02Z")\
**Posts on this page:** 1\
**Showing post:** 60

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [January 7, 2023, 12:03am UTC](https://discourse.julialang.org/t/syntax-surprises/92369/60 "2023-01-07T00:03:07Z")

</div>

> [@adienes](#):
>
> get rid of all the superfluous parens

One more to go:

```julia
f(a=1, (b=2,), c=3)

```

but there are actually _four_ syntax surprises contained in that example:

1. It’s possible to have superfluous parens around keyword args.
2. It’s possible to have superfluous parens around `NamedTuple` fieldname-value pairs.
3. Keyword args are allowed in non-final position,
4. even if they are succeeded by a semicolon!

Would you expect this?

```julia
julia> f((a=1, b=2), (c=3); d=4)
(args = ((a = 1, b = 2),), kwargs = Base.Pairs(:c => 3, :d => 4))

```

> [@adienes](#):
>
> not always the case that a struct `X` will have a constructor `X(::typeof(X))`

That’s not at issue here. At issue is a break from Julia’s convention that, where reasonable, an object’s `show` method should print working code which illustrates how to construct the object.

Obviously Julia doesn’t print working code for vectors, matrices, and functions, but it’s often unreasonable to try, and at least for those it’s pretty obvious that what has been printed isn’t executable code.

The `show` method for `Base.Pairs` here has two WATs:

1. it presents text that very much resembles a call to its constructor, but it’s not, and
2. in this context it promotes the idea that `Pair`s of `key => value` is a preferred way to package and send keyword arguments around, when infact that causes type-instability (see for example, [here](https://discourse.julialang.org/t/fixing-the-piping-chaining-issue/89654/211)).

---

_[View the full topic](https://discourse.julialang.org/t/syntax-surprises/92369)._
