Live data from Hacker News

Lenses in Julia

juliaobjects.github.io

31–40 of 68 posts

Re: Lenses in Julia

#31
post #21

Guys, What's you're opinion on Julia? I am thinking of using it for data science work. Any draw backs? or advantages I should know about?

Drawback, it isn't Python in community scale, remember it was born in 1996, so it had enough time to grow.

Advantages, it is yet another Lisp like language in a Algol like syntax, like Dylan and Wolfram Alpha, also another one with multi-methods support a la Common Lisp, Dylan, Clojure, and whoever else implements a subset of CLOS.

It was designed from the ground up to be compiled with a JIT, not as an afterthought.

These are the kinds of places making use of it,

https://juliahub.com/case-studies

Re: Lenses in Julia

#32
Is Julia a general purpose programming language? I mean I did check the web site which contains a "General Purpose" section, yet the articles seem to center around "scientific applications".

Re: Lenses in Julia

#33
post #21

Guys, What's you're opinion on Julia? I am thinking of using it for data science work. Any draw backs? or advantages I should know about?

I would love to love it, but for now I hate to hate it.

Dynamic yet performant language with LISPy features and focus on numerical applications? Count me in.

But then I found out that execution of some ideas is rather bad, and some ideas are great on paper, but not in practice. For example, debugging experience is a joke even compared to SBCL debugger (and you of course need to download package Debugger.jl, because who needs a good debugger in base language implementation?) And multiple dispatch is a very powerful feature... I sometimes think it is too powerful.

There is no proper IDE, and VSC extension was slow and unstable when I tried it (last time few months ago).

But my biggest gripe is with people developing Julia. Throughout the years every time people complained about something ("time to first plot", static compilation etc.) the initial responses were always "you are holding it wrong", "Julia is not intended to be used this way", "just keep you REPL open", "just use this 3rd party package", only to few releases later try to address the problem, sometimes in suboptimal way. It is nice that in the end they try to deliver solutions, but it seems to me it always require constant push from the bottom.

Moreover, I am quite allergic to marketing strategies and hype generation:

Julia doesn't run like C when you write it like Python. It can be very fast, but then it requires quite detailed tuning.

You don't need to think about memory management, until you need to, because otherwise allocations kill your performance.

You can omit types, until you can't.

Those things are quite obvious, but then why produce so much hype and bullshit people through curated and carefully tuned microbenchmarks?

It maybe solves two-language problem, but in return it gives you million packages issue. You need a package to have a tolerable debugger (Debugger.jl), you need a package to have static and performant arrays (StaticArrays.jl), you need a package to have enums worth using, you need a package to hot-reload your code without restarting REPL (Revise.jl), you need a package to compile you code to an executable (PackageCompiler.jl/StaticCompiler.jl, they started to address that in the last release) etc. And then you need to precompile them on your machine to have reasonable startup time.

TLDR: Julia is wasted potential.

Re: Lenses in Julia

#34

I have to admit I don’t really understand the point of doing this instead of just obj.a = 2 or whatever.

The other replies covered the answer about immutability well, but I have the further question: why isn't this built into languages as syntax sugar, so that OP's suggested line would work with immutable structures? As a dilettante at programming language design, I have my own toy language. It uses exclusively immutable data structures (C++ "immer"). I present it to the programmer as simple value semantics. `obj.foo[5]…

It's an interesting question, why immutability is not built into more languages as the default, so that the most intuitive syntax of assignment produces new values.

Without having any expertise in the matter, I'd guess that mutability has the advantage of performance and efficient handling of memory.

  obj.foo[5].bar.a = 2
An immutable interpretation of this would involve producing new objects and arrays, moving or copying values.

Another possible advantage of the mutable default is that you can pass around references to inner values.

Re: Lenses in Julia

#35

Is Julia a general purpose programming language? I mean I did check the web site which contains a "General Purpose" section, yet the articles seem to center around "scientific applications".

In the release 1.12 they finally implemented the ability to create compact executables, so I would say the answer to your question is "yes".

Re: Lenses in Julia

#36
post #23

Earlier quoted context omitted.

I've worked in about 40 languages and have a Ph. D. in the subject. Every language has problems, some I like, some I'm not fond of There is only one language that I have an active hatred for, and that is Julia. Imagine you try to move a definition from one file to another. Sounds like a trivial piece of organization, right? In Julia, this is a hard problem, and you can wind up getting crashes deep in someone else's c…

I guess you had a bad experience, but this hasn’t been an issue for me using it for many years now.

Lol is this meant to be an ironic comment?

Re: Lenses in Julia

#37
post #28
post #15

Earlier quoted context omitted.

This is equivalent to that for people who are irrationally terrified of mutability, and are willing to abandon performance.

Counterintuitively Julia recommends the use of immutable data types for performance reasons, because immutability enables more flexible compiler optimisations An immutable variable can be savely shared across functions or even threads without copying. It can be created on the stack, heap or in a register, whatever the compiler deems most efficient. In the case, where you want to change a field of an immutable variabl…

There is nothing counter-intuitive or julia-specific about it:

Fastest way is to have your datastructure in a (virtual) register, and that works better with immutable structures (ie memory2ssa has limitations). Second fastest way is to have your datastructure allocated on the heap and mutate it. Slowest way is to have your datastructure allocated on the heap, have it immutable, copy it all the time, and then let the old copies get garbage collected. The last slowest way is exactly what many "functional" languages end up doing. (exception: Read-copy-update is often a very good strategy in multi-threading, and is relatively painless thanks to the GC)

The original post was about local variables -- and const declarations for local variables are mostly syntactic sugar, the compiler puts it into SSA form anyway (exception: const in C if you take the address of the variable and let that pointer escape).

So this is mostly the same as in every language: You need to learn what patterns allow the current compiler version to put your stuff into registers, and then use these patterns. I.e. you need to read a lot of assembly / llvm-IR until you get a feeling for it, and refresh your feelings with every compiler update. Most intuitions are similar to Rust/clang C/C++ (it's llvm, duh!), so you should be right at home if you regularly read compiler output.

Julia has excellent tooling to read the generated assembly/IR; much more convenient than java (bytecode is irrelevant, you need to read assembly or learn to read graal/C2 IR; and that is extremely inconvenient).

Re: Lenses in Julia

#38
post #15

Earlier quoted context omitted.

This is equivalent to that for people who are irrationally terrified of mutability, and are willing to abandon performance.

Immutability gives you persistence, which can be practically useful. It’s not just fear.

Yes. O(1) snapshots are awesome! Persistent datastructures are a monumental achievement.

But that comes at a performance price, and in the end, you only really need persistent datastructures for niche applications.

Good examples are: ZFS mostly solves write amplification on SSD (it almost never overwrites memory); and snapshots are a useful feature for the end user. (but mostly your datastructures live in SRAM/DRAM which permit fast overwriting, not flash -- so that's a niche application)

Another good example is how julia uses a HAMT / persistent hash-map to implement scoped values. Scoped values are inheritable threadlocals (tasklocal; in julia parlance, virtual/green thread == task), and you need to take a snapshot on forking.

Somebody please implement that for inheritable threadlocals in java! (such that you can pass an O(1) snapshot instead of copying the hashmap on thread creation)

But that is also a niche application. It makes zero sense to use these awesome fancy persistent datastructures as default everywhere (looking at you, scala!).

Re: Lenses in Julia

#39
post #18

Earlier quoted context omitted.

The difference doesn't matter when you have a shallow structure and can access fields directly and have a few lines of code. But field access does not compose easily if you have a nested hierarchy of objects. Your natural choice in the "OOP style" is to write a lot of boiler plate to point to each different field you want to get/set. Say you get bored of the tedium and want "higher-order" accessors that compose well…

> Your natural choice in the "OOP style" is to write a lot of boiler plate to point to each different field you want to get/set. Your natural alternative to lenses in imperative languages is usually to just store a reference or pointer to the part you want to modify. Like a lens, but in-place.

But then you're modifying the thing, not creating a new object with different content. It's different semantics.

Re: Lenses in Julia

#40
post #21

Guys, What's you're opinion on Julia? I am thinking of using it for data science work. Any draw backs? or advantages I should know about?

I would love to love it, but for now I hate to hate it. Dynamic yet performant language with LISPy features and focus on numerical applications? Count me in. But then I found out that execution of some ideas is rather bad, and some ideas are great on paper, but not in practice. For example, debugging experience is a joke even compared to SBCL debugger (and you of course need to download package Debugger.jl, because w…

As for the tooling, julia-snail on emacs is supposed to be like SLIME for Lisp. But sounds like that isn't your main gripe. Having to load so many packages is a indeed a pain, but it does suggest the core language is rather minimal...
Post reply on HN