Hacker News new | ask | show | jobs
by galangalalgol 1380 days ago
I want Nx1 and 1xN to act differently. It is a form of type safety. I would be fine with defaulting to Nx1x1...x1 as well and have everything be a tensor where you specify which side all the singleton dimensions proceed. Disagree, but they could do this better, matrix just happens to cover most cases.

I consder default arguments code smell in every language. Or really more foot-guns than code smell. I discourage them whenever anyone will listen. Disagree on this one.

Not super fond of kwargs either but they certainly have their place. If they are going to support it, they should do so well. Agreed

I actually prefer to read vectorized notation, I wish it was more consistently performant in Julia, sometimes the for loops run faster, but they take longer for me to read and understand. The exception is if there is an einsum in there somewhere, or the equivalent auto expansions in Matlab, that takes me a few. Personal preference I guess?

I've never come across a use for mixed arrays, but everytime I come across an api that returns them I begin cursing. Agreed

Typecast rounds instead of floors? That is kinda odd, but not wrong I guess? I haven't ever run across this because I use floor or round explicitly.

In 20 years ivrmever noticed the string thing. I'll jave to read about that, thanks!

1 comments

> I want Nx1 and 1xN to act differently.

Yes. Of course you do. The problem is, you never know what you are going to get. What you actually want is a vector, but Matlab has no such thing, so then you have to write your code in a way that anticipates either Nx1 or 1xN, and handle both. Sounds, simple enough, but I have a lot of code lines dedicated to checking and handling row/column orientation. If only there were real 1D vectors!

> I consder default arguments code smell in every language. Or really more foot-guns than code smell.

I don't really understand what you mean here, but the problem is that in Matlab you handle 'default arg values' with `if nargin < 5, par5 = default_value` etc. It's just worse, and it's perfectly idiomatic matlab.

> I actually prefer to read vectorized notation

My argument is actually that vectorization works much more cleanly in Julia. If in Matlab you have `foo`, which calls `bar` which calls `baz`, etc, then you must make sure that each of these explicitly can handle array inputs. You have to think about arrays on every level, including what happens with axis broadcasting (and probably checking 1xN vs Nx1 orientations on multiple levels). In Julia, on the other hand, you can write your functions `foo`, `bar` and `baz` to handle scalar arguments, and then you vectorize the whole thing with `foo.(args)`.

So vectorized code in Julia is much simpler to write, and also simpler to read. (Just to be clear: writing vectorized Matlab code and vectorized Julia code are things I do all day, every day, so I have a decent basis for comparison.)

> sometimes the for loops run faster, but they take longer for me to read and understand.

Loops vs broadcasting should be basically the same for performance, but sometimes you can get extra performance from a loop, by exploiting algorithmic advantages. But a simple vectorization is just a dot away.

> mixed arrays

It's something one generally tries to avoid, but they are often necessary for passing along arguments to inner functions etc. Tuples are great for this, but it doesn't exist in Matlab.

> Typecast rounds instead of floors?

It's odd, but I don't mind. Mainly, I am annoyed that integers are not well supported in Matlab.

> In 20 years ivrmever noticed the string thing

The "strings" are new, a couple of versions back. Of course, you will notice that "string" is actually a 1x1 matrix of strings, so length("hello") equals 1. And indexing into strings is actually indexing into the array of strings. So `str = "hello"` then `str(1)` returns the string itself, and `str(2)` errors.

I don't want 1d vectors to exist, and ideally, I'd want everything to be infinite rank tensors with som clean notation for singletons x N or N x singletons or NxMx singletons etc. The dimension mismatch has caught more errors for me than I could ever possibly count. My functions don't check to see if something is scalar or columnar, I let the error tell the user their mistake. And using a column vector when a row vector is expected is a math error. And the same function usually works for scalar or vector or matrix for the most part.

I do like the dot notation and Julia in general, but I just don't have many complaints about Matlab. Auto expansion maybe. They do allow helper functions in the same file now, finally.

Well, in many cases, dimension mismatch causes errors, not just lets you find them. And in fact, with the recently-ish introduced broadcasting behavior, you don't even get an error, just surprising dimensional-increasing behavior.

As for "math error", it often is nothing to do with that, you just want a list of values, what should such a list be? Column or row? And often, I'm the user, calling into other people's code that sometimes wants columns, sometimes rows, and behaves surprisingly different for each (sometimes with errors, sometimes not.)

There should be a convention in Matlab about whether fundamentally 1d structures should be columns or rows, but there isn't. (Just for example: reductions work down columns, except when the columns are length-1, while iteration only occurs along rows...)

This is a huge, huge problem in my daily work. I can give many examples, but am on my phone now.

Let me put it like this: if I could change only one single thing about Matlab, I would introduce a proper vector.