# 1.0 annoyances and Matlab comparison

**URL:** <https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433>\
**Category:** Internals & Design\
**Created:** [March 1, 2018, 9:49pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433 "2018-03-01T21:49:56Z")\
**Posts on this page:** 20\
**Page:** 4

<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:** [March 3, 2018, 5:59pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/62 "2018-03-03T17:59:29Z")

</div>

Maybe something like `blob` for unformatted memory blob

```julia
Array{T}(blob,7)

```

or `byob` for bring your own bits

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 3, 2018, 6:01pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/63 "2018-03-03T18:01:27Z")

</div>

> [@Keno](#):
>
> Base has a lot of performance sensitive code and the people working on it fall squarely in the “know what they’re doing” category.

I imagine a lot of Julia’s users will also write performance sensitive code (that’s why they chose Julia, after all), and I would allow for the possibility that some of them will know what they are doing.

IMO using the length of a variable name to indicate “risky” semantics is not a good design choice, and it is not the way APIs have worked so far in Julia. Especially given that it is `export`ed at the same time, so it is part of the API but ostensibly one will be discouraged from using it because it is long? `ArgumentError` has the same number of characters, does this mean we should approach it with caution, too?

As I said above, I can live with `uninitialized`, and I can also accept the reasoning that `junk` [was suggestive of stochastic initialization](https://github.com/JuliaLang/julia/pull/24400#issuecomment-341727520) and was not “dignified” enough.

My primary practical problem with **not** using `uninitialized` all the time is the following: suppose I have a function that takes a collection `A` with eltype `T`, and calculates a result `B::Array` which has a similar eltype but a different shape. The result is filled up elementwise, and preallocated at the beginning. The most obvious way I see to start that function is

```julia
B = Array{T}(uninitialized, dims)

```

The alternative I imagine is

```julia
B = fill(first(A), dims)

```

which is clunky and does not express my intent (`first(A)` is nothing special, I will be overwriting it, but `fill` needs an element). So even though the first one is more verbose expect I will use it all the time.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [March 3, 2018, 6:16pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/64 "2018-03-03T18:16:54Z")

</div>

I’d use `similar(A, dims)` in the case you described.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [March 3, 2018, 6:19pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/65 "2018-03-03T18:19:35Z")

</div>

I like `uninitialized`: it evokes the right mental image and it is not very likely to conflict with user-named variables.

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [March 3, 2018, 6:31pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/66 "2018-03-03T18:31:21Z")

</div>

reaallly, who cares? What was the post about, I forgot

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 3, 2018, 6:53pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/67 "2018-03-03T18:53:44Z")

</div>

Which works great, except for the cases where `similar` is not defined (eg `A` is not an [`AbstractArray`](https://docs.julialang.org/en/latest/manual/interfaces/#man-interface-array-1)).

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [March 3, 2018, 10:11pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/68 "2018-03-03T22:11:33Z")

</div>

> [@Keno](#):
>
> because you’re not supposed to be using it, unless you know what you’re doing. The best way to initialize an array is to pick whatever value makes sense for you (e.g. fill(0, m, n)).

Julia is considered a performance language, right? All performance languages I’m aware of declare variables uninitialized by default. Even in Lua, all variables point to `nil` until they are assigned a value or initialized. Since my day-1 using Julia (5 years ago), I declare arrays `Array(T,dims)` and don’t use `zeros` (it will be deprecated after all). The language shouldn’t force the user to fill an array with zeros or whatever, when it will be assigned different values later any way. If I wasn’t searching for performance, I’d have stuck with MATLAB. All Julia users, I assume, care about performance and know exactly what they do.

I think perhaps the whole array constructor design should be reconsidered (my recommendation), or just choose an easier name, `nil`, `junk`, … I know it’s somehow late, but better late than never.

Personally, I’ve been lately (with 0.7 release) using something like this a lot:

```julia
F64(n...) = Array{Float64}(uninitialized, n)
F32(n...) = Array{Float32}(uninitialized, n)
I64(n...) = Array{Int}(uninitialized, n)
Bol(n...) = Array{Bool}(uninitialized, n)

```

I really miss Fortran’s `real A(m,n)`.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [March 3, 2018, 10:18pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/69 "2018-03-03T22:18:12Z")

</div>

Since I was almost always creating uninitialized vectors, not matrices, of varying types, I made a simple, easy to understand function:

```julia
uninit(T, len) = @static isdefined(Base, :uninitialized) ? T(uninitialized, len) : T(len)
create_vector(T, len) = uninit(Vector{T}, len)

```

This also allows my code to be more readable (IMO), and work the same in both master and earlier releases.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [March 3, 2018, 10:51pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/70 "2018-03-03T22:51:12Z")

</div>

I like the new syntax, but `uninitialized` is indeed a bit long and hard to type. We could probably find something shorter but with more dignity than `junk`. Maybe `raw`? `unfilled`? `blank`?

---

<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:** [March 3, 2018, 10:51pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/71 "2018-03-03T22:51:50Z")

</div>

`junk`?

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [March 3, 2018, 11:08pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/72 "2018-03-03T23:08:28Z")

</div>

`unin` + tab is all it takes for me to get `uninitialized` to appear on 0.7.  
Doesn’t work of course if you have other variables that start with unini in your name space.

EDIT:  
Something else you can look into:

> **[Snippets in Visual Studio Code](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_creating-your-own-snippets)**
>
> It is easy to add code snippets to Visual Studio Code both for your own use or to share with others on the public Extension Marketplace. TextMate .tmSnippets files are supported.

While I prefer `uninitialized` over `junk`, I don’t really care either way.

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [March 3, 2018, 11:57pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/73 "2018-03-03T23:57:10Z")

</div>

Perhaps we can get out of this dilemma if we are able to redefine `fill` to work with types the same way as it works with values. For example, the following two statements could be made equal:  
`A = fill(Float64, m, n)`  
`A = Array{Float64}(uninitialized, m, n)`.

This way, `uninitialized` can be left intact and used inside base and packages, without forcing the user to use it or loose performance from calling `zeros(m, n)` or `fill(0.0, m, n)`.

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [March 4, 2018, 12:01am UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/74 "2018-03-04T00:01:19Z")

</div>

> [@Seif\_Shebl](#):
>
> fill(Float64, m, n)

```julia
julia> fill(Float64, 2, 2)
2×2 Array{DataType,2}:
 Float64 Float64
 Float64 Float64

```

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [March 4, 2018, 1:20am UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/75 "2018-03-04T01:20:41Z")

</div>

> [@nalimilan](#):
>
> more dignity

Since when was programming dignified???

---

<div class="post-metadata">

**Author:** ![jeff.bezanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff.bezanson/32/48_2.png) [@jeff.bezanson](https://discourse.julialang.org/u/jeff.bezanson)\
**Post date:** [March 4, 2018, 3:26am UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/76 "2018-03-04T03:26:51Z")

</div>

The goal was not to protect against uninitialized data via the length of the name, but just by forcing you to be explicit. I do find `uninitialized` very long though; I would be fine with simply renaming it to `uninit`.

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [March 4, 2018, 7:34am UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/77 "2018-03-04T07:34:04Z")

</div>

Which kind of initialization we have to wait after deprecation phase?

Edit:

> [@nalimilan](#):
>
> I like the new syntax, but uninitialized is indeed a bit long and hard to type. We could probably find something shorter but with more dignity than junk. Maybe raw? unfilled? blank?

And BTW could you explain what exactly do you like? What will be more simple or more clear?

Why not to keep default Array constructor to use uninitialized memory?

---

<div class="post-metadata">

**Author:** ![y4lu](https://avatars.discourse-cdn.com/v4/letter/y/47e85d/32.png) [@y4lu](https://discourse.julialang.org/u/y4lu)\
**Post date:** [March 4, 2018, 9:42am UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/78 "2018-03-04T09:42:08Z")

</div>

> [@jeff.bezanson](#):
>
> I do find uninitialized very long though; I would be fine with simply renaming it to uninit

👍

I guess it won’t be optional, so could there be other values to pass here, like a valid default value &/or the original `uninit / junk / inseclogindeets` (lol). A default would probably be handy for arrays of Union types, and could even be performant if done lazily? ie set or return the default value on read if still undefined / unwritten, like a hidden(?) union of type x + initialized boolean that will fall back to type x on true (initialized)

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [March 4, 2018, 11:26am UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/79 "2018-03-04T11:26:29Z")

</div>

I’d also really like to see a convenience constructor for constructing an arbitraily initialized array complementing `ones, zeros,` etc.

I’d really like a naive `empty(T, dims...)` from a users perspective. But I guess I can also live with `uninit(T, dims...)` given the fact that there is an `empty` function already with a different meaning.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [March 4, 2018, 12:10pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/80 "2018-03-04T12:10:08Z")

</div>

> [@Liso](#):
>
> And BTW could you explain what exactly do you like? What will be more simple or more clear?
> 
> Why not to keep default Array constructor to use uninitialized memory?

See [Array{T}(initialization,...) syntax - #2 by mbauman](https://discourse.julialang.org/t/array-t-initialization-syntax/9298/2).

---

<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:** [March 4, 2018, 12:11pm UTC](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433/81 "2018-03-04T12:11:00Z")

</div>

> [@carstenbauer](#):
>
> I’d really like a naive empty(T, dims…) from a users perspective

You would need to use e.g. `OffsetArray{T}(uninitialized, dims...)` for any `AbstractArray` other than `Array`s. Creating a bunch of `Array` specific functions when there are so many other type of `AbstractArray`s seems less good than having functions that work for all of them.

[Previous page](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433.md?page=3)

[Next page](https://discourse.julialang.org/t/1-0-annoyances-and-matlab-comparison/9433.md?page=5)
