News for hackers. Stuff that matters.
Re:From Common Lisp to Julia by galangalalgol on Tuesday September 06, 2022 @10:50PM (#32745834)
MATLAB is fairly impressive for development. It works ok for communication. What are the areas for improvement you have in mind, and what are the alternatives I should consider?
Re:From Common Lisp to Julia by adgjlsfhk1 on Tuesday September 06, 2022 @11:06PM (#32745923)
The 2 biggest problems with Matlab are price and lack of community. The price is an issue even if you can afford it because it makes it really hard to deploy widely since anyone who wants to run the code also needs to be paying Mathworks. This closely ties in to the community issue. Almost all Matlab libraries are proprietary (and written by MathWorks). If you find a bug, your only option is to file a report and wait 3 years for it to not get fixed. In an open source ecosystem, you can dig into the code and fix the problem yourself if you need to.
Re:From Common Lisp to Julia by systemvoltage on Tuesday September 06, 2022 @11:51PM (#32746131)
I once got on a call with MATLAB compiler engineer and had him fix a bug in an afternoon. I should have written a blog post about it but it is too late, I have very little recollection of the details. It was kinda awesome though. How often can you do just call up someone to fix the compiler. To be fair, I worked for a very large Fortune 50 company and had over 10k licenses of MATLAB.

Also, it is interesting that outside of SV and HN crowd, we thought MATLAB is awesome. We had all the toolboxes, there is a gazillion of them. Even obscure RF related stuff. You just can't find a library for something like a phased array analysis. May be you can, but it won't be as high quality and industry proven as this: https://www.mathworks.com/products/phased-array.html

Another topic that we often understood is that when a jet engine is hoisted up for testing and you need to get something fixed or have a question about in next 2 hours, you need commercial software support to help you out. Gravity of situation cannot be understated. It is stressful. There is OSS software support, but MATLAB is on another level. Absolutely outstanding support. Companies like Apple and SpaceX rely on MATLAB heavily outside of software engineer orgs.

Overall, A+. Will use again.

Re:From Common Lisp to Julia by DNF2 on Wednesday September 07, 2022 @04:58AM (#32748248)
If you are basically using finished code, your own code is mostly a top-level script, and you mainly need polished functionality and professional support, then Matlab toolboxes and support are very good.

But the language itself is primitive compared to OSS alternatives, so when you need to develop your own software on a larger scale, it falls short.

There is of course a sliding scale between 'user' and 'developer' in any language, but I think that the closer you are to the 'user' end of the scale, the better Matlab looks.

(BTW, I am a daily Matlab user, sorry to say.)

Re:From Common Lisp to Julia by galangalalgol on Wednesday September 07, 2022 @07:33AM (#32749242)
I don't find the language primitive at all. It just has a poor deployment story that consists of "autogenerate to hidious unreadable c c++ cuda or vhdl, or writ it again yourself". It is amazing the autogen even works, which it really does, but that code...

But back to the language. I can typically do a line by line syntax change to get pytorch (julia is a but different but not too much). The resulting matlab sometimes runs faster too. If you avoid globals and write everything vectorized it is all really clean. OO code would be hidious, but I try not to use OO or goto in any language unless there is no other option. I like that arguments to a function are pass by reference unless you write to them, in which case it does a smart copy. Julia syntax looks different sometimes because you don't have to vectorize for performance as in matlab or python, in fact sometimes you shouldn't.

All in all, if the deployment story was solved, I probably wouldn't be trying out Julia. In fact I still prototype in Matlab before implementation in pytorch or julia, its just eaier to get that first thing working.

Re:From Common Lisp to Julia by DNF2 on Wednesday September 07, 2022 @08:11AM (#32749553)
Oh, Matlab is pretty bad.

Everything is a matrix, that's horrific (especially the Nx1 vs 1xN ambiguity which pops up all the time). No default argument values (and until recently, no support for keyword args, though they have a bad version now), meaning half your code lines are input parsing. Forced vectorization does the opposite of making code clean, it makes complicated code a lovecraftian mess (unlike Julia, which lets you vectorize efficiently at the top level.) Every function must live in an m-file(#$@&%*!) Everything in your path is in scope :(

The varargin/varargout/nargout mess, with outputs specified in the signature line, instead of proper return statements.

Also, for a language that requires vectorization for performance, there should really be a proper `map`, instead of the mess that is `arrayfun`/`cellfun`/`structfun`. Their arrays are super-limited, no mixed-element arrays (use cell-arrays!), so `[3, [4,5,6], 7]` is just concatenated, while `[3, [4;5;6], 7]` errors (and check out what `[3, "hello", 7]` does(!) or `[3, 'hello', 7]`)

Poor support for integers, 2 is a double(!), and `int8(3)/int8(2) == int8(2)` (yikes.)

Their OOP is actually not that bad, though it's slow. And their graphics system is pretty ok.

Also annoying: now you have two types of strings, old-fashioned 'abc', and new-fangled "abc", which are very different, and sort-of, half-way work together. Though I think moving to the new strings is actually a good move, but painful now.

Re:From Common Lisp to Julia by galangalalgol on Wednesday September 07, 2022 @08:52AM (#32749896)
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!

Re:From Common Lisp to Julia by DNF2 on Wednesday September 07, 2022 @09:20AM (#32750191)
> 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.

Re:From Common Lisp to Julia by galangalalgol on Wednesday September 07, 2022 @10:53AM (#32751440)
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.

Re:From Common Lisp to Julia by DNF2 on Wednesday September 07, 2022 @11:53AM (#32752290)
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.

Re:From Common Lisp to Julia by systemvoltage on Wednesday September 07, 2022 @11:11AM (#32751691)
Yep, 100% agree. The language is not that great.
Re:From Common Lisp to Julia by linspace on Wednesday September 07, 2022 @12:52AM (#32746444)
> Also, it is interesting that outside of SV and HN crowd, we thought MATLAB is awesome. We had all the toolboxes, there is a gazillion of them. Even obscure RF related stuff. You just can't find a library for something like a phased array analysis. May be you can, but it won't be as high quality and industry proven as this: https://www.mathworks.com/products/phased-array.html

As a matter of fact I find most comments about Matlab here supportive. I actually do find Matlab to be a polished product, specially in the IDE and documentation part. In the end you use whatever saves you time, that's why most people that use Python have chosen Python: because of the libraries. I have personally found Matlab toolboxes quite simplistic for my own purposes. Most people, myself included, actually trust more that SW is used and deployed in the millions than any kind of support.

Re:From Common Lisp to Julia by thrown_22 on Wednesday September 07, 2022 @12:10AM (#32746219)
>How often can you do just call up someone to fix the compiler. To be fair, I worked for a very large Fortune 50 company and had over 10k licenses of MATLAB.

Very often if you're paying upwards of $10,000,000 in licenses a month.

Re:From Common Lisp to Julia by wiz21c on Wednesday September 07, 2022 @03:32AM (#32747610)
on one side:

> To be fair, I worked for a very large Fortune 50 company and had over 10k licenses of MATLAB.

on another side:

> Absolutely outstanding support.

I think I see a pattern here...

Re:From Common Lisp to Julia by sundarurfriend on Wednesday September 07, 2022 @12:49AM (#32746426)
The community issue also means that code sharing is very limited compared to other languages. If it isn't in one of the Mathworks toolboxes (that you can afford), you'll probably have to end up at the Mathworks "File Exchange" site, where you take a look at the existing code that "solves your problem" (in a non-generic, buggy way), cry your eyes out, and end up implementing it yourself.
Re:From Common Lisp to Julia by galangalalgol on Tuesday September 06, 2022 @11:09PM (#32745936)
Both fair points. And the alternative? I like Julia, but i still haven't found a workflow I like. I still typically prototype in Matlab and deploy in c++/cuda.
Re:From Common Lisp to Julia by adgjlsfhk1 on Tuesday September 06, 2022 @11:31PM (#32746044)
I'm using Julia, but if I wasn't, I probably would either be using Python or C#.
Re:From Common Lisp to Julia by galangalalgol on Wednesday September 07, 2022 @07:06AM (#32749021)
I'm trying to work entirely inside the repl. Its not bad but for large stuff the lack of go to definition hurts, and there isn't an easy way to copy commands that worked into my module. I'll try vscode next. That is what I use for c++/c. Is there anything else I should try?
Re:From Common Lisp to Julia by adgjlsfhk1 on Wednesday September 07, 2022 @08:12AM (#32749561)
I use VSCode+repl which works well for me (although the language server for Julia isn't as good as a C/C++ one). The one other workflow to look at is Pluto notebooks. They're similar to jupyter notebooks, but they track cell dependencies and automatically dependent cells, to guarantee that you maintain consistent state.
Re:From Common Lisp to Julia by galangalalgol on Wednesday September 07, 2022 @08:33AM (#32749738)
I worked in pluto for a bit. I should give that another shot. If there is an easy way that someone simply runs the script, and it doesn't try to fire off plots, that would be the ultimate in self documenting code.
Re:From Common Lisp to Julia by adgjlsfhk1 on Wednesday September 07, 2022 @10:01AM (#32750761)
Ideally Julia would have a WASM backend, but that is one that would require someone to put a bunch of time into it.
Re:From Common Lisp to Julia by JonChesterfield on Wednesday September 07, 2022 @05:49AM (#32748584)
I bought an individual license for MATLAB some years ago. Was ~$100 iirc. Deployment is presumably more expensive.
Re:From Common Lisp to Julia by dagw on Wednesday September 07, 2022 @05:59AM (#32748649)
If you read the small print on that license it almost certain says something like "for hobby use only. Not for academic or commercial use". A MATLAB license that allows commercial use starts at around 2000$/user.
Re:From Common Lisp to Julia by melony on Wednesday September 07, 2022 @01:01AM (#32746506)
MATLAB is not. The surrounding engineering and tooling is. Simulink is worth its weight in gold.
Re:From Common Lisp to Julia by NicolasL-S on Thursday September 08, 2022 @07:05PM (#32773248)
You should check out this case study of migrating Simulink to Julia at NASA: https://www.youtube.com/watch?v=tQpqsmwlfY0

From Simulink to Julia, his code went from 1000 lines to 50 lines and ran 15,000x faster.

Re:From Common Lisp to Julia by vasvir on Wednesday September 07, 2022 @03:40AM (#32747695)
Where there is GNU Octave https://octave.org/ an Open Source MATLAB clone that works ok for me but your mileage may vary.