News for hackers. Stuff that matters.
Re:Writing Python inside Rust by 6gvONxR4sf7o on Saturday April 18, 2020 @01:43AM (#22905610)
I know this project may just be for fun, but with WASM targets for all sorts of languages, I'm hoping we get to a future where mixing and matching different languages for different parts of your program will be seamless. Imagine starting a project in an easy language, then migrating pieces to a faster "bare metal" language as needed in a super piecemeal way. Same with moving pieces to a safer language as the project grows, slowly expanding the boundaries of the safe bits as appropriate.
Re:Writing Python inside Rust by pjmlp on Saturday April 18, 2020 @01:57AM (#22905654)
Re:Writing Python inside Rust by jasode on Saturday April 18, 2020 @05:38AM (#22906485)
>Just like the JVM and CLR I guess. (List_of_JVM_languages, List_of_CLI_languages)

I don't see JVM & CLR even with the dozens of language choices on top of the virtual machine runtimes as giving you ways to do "bare metal" programming. I guess one could arguably squint and say Java's JNI or C# P/Invoke and "unsafe{}" gets you some "bare metal" capabilities but that's a stretch.

I go back to the gp's sentence: "Imagine starting a project in an easy language, then migrating pieces to a faster "bare metal" language as needed in a super piecemeal way."

For example, JVM/Java doesn't have value types[1] (yet) and that's required for programmer's control of exact and efficient memory layout for many bare metal domains. It doesn't matter what flavor of JVM language you use because you're ultimately limited by the JVM's capabilities which causes excessive pointers to pointers which is inappropriate for some high-performance code.

In C#, some future tech like CoreRT might open up some more "bare metal" programming possibilities but that's not production yet[2]. I remember you couldn't even develop a Windows Explorer right-click menu shell extensions in C# because it was a bad idea to load up 2 different versions of the NET Framework runtimes (until NET 4.0). That's not even that low a level of programming and yet C++ had no such limitation.

I use C# as much as I can but I still have to do 50% my projects in C++ because JVM/CLR are not "bare metal" enough.

[1] https://en.wikipedia.org/wiki/Criticism_of_Java#Compound_val...

[2] https://github.com/dotnet/corert#user-content-net-core-runti...

Re:Writing Python inside Rust by pjmlp on Saturday April 18, 2020 @05:49AM (#22906537)
Since when is WebAssembly bare metal?!?

Apparently you missed the Windows 8, 8.1 and 10 train regarding your "bare metal" compilation from C# and VB.NET code.

.NET 4.0 was released in 2008 and I have been able to use C++ as .NET language since 2001, so ....

In fact one of my first .NET projects, in 2002, was to integrate C++ RPC library into Managed C++, long replaced replaced by C++/CLI with .NET 2.0 release.

Going back to Java, IBM, Aicas, PTC, Gemalto will happily sell you Java compilers that generate AOT native code for embedded deployment targets, not to mention what is running on my phone, where 95% of the OS APIs are exposed only via Java and where your beloved C and C++ code needs to use JNI to access them.

Re:Writing Python inside Rust by jasode on Saturday April 18, 2020 @05:55AM (#22906575)
>Since when is WebAssembly bare metal?!?

Not sure what that is referring to.

>C++ as .NET language

We seem to be talking about 2 different things. Using "C++" style syntax (C++/CLI) in a managed language with GC is not what many systems programmers call "bare metal". I thought it was clear from context that my mention of C++ is traditional "real C++" such as gcc/clang/MSVC and not the C++/CLI.

>Going back to Java, IBM, Aicas, PTC, Gemalto will happily sell you Java compilers that generate AOT native code

But that's not the JVM runtime though. The JVM is what you originally wrote and that's the scope of what I was replying to: ("Just like the JVM and CLR I guess. (List_of_JVM_languages ...)")

The _JVM_ doesn't really give you low-level bare-metal programming and it doesn't matter what flavor of JVM-language you choose to run on top of it.

And at the risk of further muddying up the discussion with the tangent subject of Java AOT... do any of those Java compilers give true value type semantics or is still references with pointer chasing? I'm not familiar with those compilers.

>and where your beloved C and C++ code

"beloved"?!? Can we tone down this down a bit? I'm just trying to clarify that JVM & CLR really don't span the entire spectrum of programming all the way down to "bare metal" in the way low-level programmers are typically using that phrase. I thought I was making a neutral and factual statement. I.e. I'm not interested in an emotional flamewar.

Re:Writing Python inside Rust by AsyncAwait on Saturday April 18, 2020 @07:32AM (#22906982)
If I had to guess, I'd say OP meant that just like CLR or the JVM, WebAssembly couldn't be used to target bare metal and since Wasm is discussed in the original post, there's no practical difference between it and CLR/JVM for language intermixing at present - it's just another "common language runtime" if you will.

But I agree that the tone used wasn't the best.

Re:Writing Python inside Rust by pjmlp on Saturday April 18, 2020 @10:12AM (#22907852)
Maybe the tone wasn't be best one, but I would like to know how WebAssembly is bare metal programming to start with.

Also would like to know in what way compiling natively to machine code has to do with having value type semantics on the source language.

Re:Writing Python inside Rust by jasode on Saturday April 18, 2020 @10:39AM (#22908062)
>, but I would like to know how WebAssembly is bare metal programming to start with.

We are getting into "splitting hairs" territory but let me attempt to untangle this thread because it seems to be hung up on what "bare metal" means.

Yes, if we're using "bare metal" to only mean real semiconductor chip, WASM is not that. It's an abstract virtual machine. So yes, in that strict sense, WASM is analogous to JVM and CLR.

But.....

I'm charitably interpreting gp's comment (6gvONxR4sf7o) and he's using WASM as his _relative_ (not absolute) perspective of _that_ being "bare metal". Ok, if we play along with that, WASM is not analogous the JVM/CLR because it is lower level[1]. Thus a non-managed language like C++ can more easily target WASM-flavor-of-bare-metal for high performance rather than a managed-C++/CLI targeting .NET CLR.

Yes, it's a subtle difference. WASM is more "bare-metal-ish" than JVM ... relatively speaking. I just don't think JVM languages can really do the same thing as WASM as the Google/Mozilla/Apple/MS specifically engineered Web Assembly to be a target for low-level-bare-metal languages like C/C++. In contrast, Sun & James Gosling deliberately didn't engineer JVM Java byte code to be a compilation target for low-level C/C++.

This means something cpu-intensive like AutoCAD or possibly Adobe Premiere Pro can hypothetically be written to target WASM and will perform better than if those apps were re-written in Java to target a Java web browser plugin. E.g. Java's JVM doesn't have value types and that architecture choice is very unfriendly to storing/manipulating millions of 3d points for a CAD program. In contrast, WASM's architecture opens up a few more "bare-metal-ish" programming domains.

The various choices of JVM languages like Kotlin/Clojure/JRuby/etc actually don't address what WASM is attempting to accomplish.

[1] https://www.quora.com/How-does-Java-bytecode-compare-to-WASM...

Re:Writing Python inside Rust by pjmlp on Saturday April 18, 2020 @04:47PM (#22910977)
Yet, GraalVM compiles LLVM bitcode and WASM bytecode just fine.

https://www.graalvm.org/docs/reference-manual/languages/llvm...

https://www.graalvm.org/docs/reference-manual/languages/wasm...

A JVM and respective JIT compiler all written in Java.

And I still doesn't understand what WASM does for C++ that CLR doesn't do, given that I can write straight C89 or C++ with C++/CLI, just like using gcc or clang doesn't force me to use their language extensions.

Re:Writing Python inside Rust by 6gvONxR4sf7o on Saturday April 18, 2020 @02:06AM (#22905678)
Same idea, yeah, but hopefully with better common adoption. For various reasons users didn't adopt those (e.g. numpy on JVM would be a ton of effort, especially a decade ago). But the web is an irresistable force, maybe. I'm hopeful (though not necessarily optimistic).
Re:Writing Python inside Rust by pjmlp on Saturday April 18, 2020 @02:41AM (#22905808)
But they did, just not with the languages that are loved on HN as "taking over the world".

Most people on JVM land, use a mix of Java, Kotlin, Scala, Clojure, Groovy, JRuby.

Whereas on CLR land it is C#, F#, VB.NET and C++/CLI (for low level stuff).

Naturally those that want to kill Java, or rather not touch Windows, aren't aware of this.

Re:Writing Python inside Rust by akiselev on Saturday April 18, 2020 @05:10AM (#22906358)
Every single language I've seen that has been 'loved on HN as "taking over the world"' has had C FFI interop, whether it is Node, Rust, Python, Ruby, C#, Java, Haskell, Zig, Crystal, Julia, LUA, etc.

Web assembly is the browser C FFI, not some high level platform like Java or .Net. Your examples aren't comparable.

Re:Writing Python inside Rust by pjmlp on Saturday April 18, 2020 @05:36AM (#22906477)
Failure to understand what bytecode based execution runtimes is all about it seems.

Also failure to understand that C ABI does not exist, rather it is the OS ABI from OS written in C, and that other OS, not written in C, don't have such thing as C ABI across all languages.

Examples of such OSes, IBM i, z/OS, Unisys ClearPath, UCSD, Unisys ClearPath, Classic Mac OS, UCSD, Native Oberon, Mesa/Cedar, Windows (plenty of stuff is .NET/COM/UWP nowadays), Android, ChromeOS, Garmin OS, and the Web.

So no, it isn't the browser C FFI, all major ones aren't even written in C for the past 20 years.

Re:Writing Python inside Rust by akiselev on Saturday April 18, 2020 @06:11AM (#22906653)
You have repeatedly missed the point of the discussion because you are hyper-focused on the implementation details that are irrelevant to the end user. I honestly don't know how you jumped from the JVM and CLR to Unisys Clearpath (twice) and Mesa/Cedar except as a red herring. The topic of discussion is Web Assembly which implies a modern browser.

The majority of browsers now support Web Assembly and about half the global population has a web browser and access to the internet - and now, access to an actual universal bytecode based execution runtime by nature of being part of the web browser standards instead of an OS feature or framework installation or (god forbid) Oracle TOS.

The C FFI part was an analogy. The whole point of Web Assembly is that it can't call out to just any library on the OS.

Re:Writing Python inside Rust by pjmlp on Saturday April 18, 2020 @10:16AM (#22907887)
Except it can, because WebAssembly has long stop being a browser only story.

By the way, JVM on the browser, Flash CrossBridge and PNaCL were there first in what concerns "universal bytecode based execution runtime by nature of being part of the web browser".

Re:Writing Python inside Rust by littlestymaar on Saturday April 18, 2020 @06:54AM (#22906825)
I know I haven't worked with Java for the past 6 years (time flies!), but back then none of the 2 companies I worked for used anything else than Java on the JVM. In fact, until Kotlin came I only met one guy working with Scala, and nobody for the other languages. It was in France though,not in the US.

But I think your argument holds for CLR, were I've seen the 4 languages you mention being used altogether in the same code base.

Re:Writing Python inside Rust by tasogare on Saturday April 18, 2020 @04:56AM (#22906302)
I know you know this, but I’ll write it for other readers: there is even more languages on CLR if we count the one not supported by MS. Also, C native libraries and thus any language that can target it, can by used as well on Windows, Mac OS and Linux with PInvoke.
Re:Writing Python inside Rust by pjmlp on Saturday April 18, 2020 @05:35AM (#22906472)
Hence why I posted a link to the language list on my first comment. :)
Re:Writing Python inside Rust by alfalfasprout on Saturday April 18, 2020 @03:38AM (#22906013)
The problem is that inherently a lot of the times when you want to drop down to C/C++, you're doing numerical code that would really benefit from SIMD operations and many of those tend to not be portable (as far as I'm aware, basic SIMD is just in the proposal stage for WASM).
Re:Writing Python inside Rust by unrealhoang on Saturday April 18, 2020 @04:19AM (#22906171)
Controlling memory layout of your data structures really goes a long way for tight loop performance. SIMD might be just the icing on top of the cake.
Re:Writing Python inside Rust by Kinrany on Saturday April 18, 2020 @08:15AM (#22907189)
I wonder if we'll ever get to a future where all code is write-only, immutable, and thrown away after compilation.

The choice of the language would become a matter of presenting the compiled code and writing replacements for new code.

The runtime and the type system can't be replaced this way though.

Re:Writing Python inside Rust by 1f60c on Saturday April 18, 2020 @09:08AM (#22907447)
I can't tell if you're joking or not. Why would I delete the source code of every program after writing it?
Re:Writing Python inside Rust by Kinrany on Saturday April 18, 2020 @10:45AM (#22908098)
I mean, delete the source, but store an intermediate representation that can be decompiled into any other language for reading.

Languages with good type systems and tooling support a workflow where you mostly rely on Intellisense hints and docs, and never read the code itself.

That, but taken to its logical conclusion: if you never read the source code, you don't need to store the source code.

The missing part is the ability to define algorithms as modifications of existing algorithms.