News for hackers. Stuff that matters.
Re:Microsoft rewrote Q# compiler in Rust by avestura on Wednesday June 21, 2023 @02:50PM (#36422681)
It was previously written in C# and F#: https://github.com/microsoft/qsharp-compiler
Re:Microsoft rewrote Q# compiler in Rust by systems on Wednesday June 21, 2023 @03:42PM (#36423330)
Well Rust was written OCaml on which F# was based So i think this was probably for performance, not for any expressive reasons

And personally i consider Rust to be from the OCaml/SML family of languages similar to F#, so i guess they moved within the family

Re:Microsoft rewrote Q# compiler in Rust by reocha on Wednesday June 21, 2023 @04:12PM (#36423725)
If it isn't clear from this comment rust is no longer written in OCaml and is fully self hosted (as far as I know).
Re:Microsoft rewrote Q# compiler in Rust by klabb3 on Wednesday June 21, 2023 @04:15PM (#36423768)
Correct. In this context it’s perhaps also worth mentioning that Rust depends on LLVM.
Re:Microsoft rewrote Q# compiler in Rust by tialaramex on Wednesday June 21, 2023 @05:03PM (#36424470)
Yes. Rust's compiler, rustc, is a bunch of Rust code that parses Rust syntax into an Abstract Syntax Tree to which it can apply macros, then this is lowered through two levels of intermediate representations, where more Rust code does the type inference and type checking and eventually borrow checking and various optimisations, until eventually it's lowered to LLVM Intermediate Representation LLVM IR, which LLVM will further optimise then produce machine code for the target architecture.
Re:Microsoft rewrote Q# compiler in Rust by reocha on Wednesday June 21, 2023 @05:09PM (#36424568)
Impressive knowledge o7
Re:Microsoft rewrote Q# compiler in Rust by Dudester230602 on Wednesday June 21, 2023 @06:17PM (#36425459)
What do Rust developers tend to do while the code is compiling? Vote 'Rust' in all the programming language surveys?
Re:Microsoft rewrote Q# compiler in Rust by xedrac on Wednesday June 21, 2023 @08:18PM (#36426571)
I know you're getting downvoted, but seriously, Rust compilation/linking does take a long time, especially if you enable fat LTO. The upside is it's doing a lot more for you than say the C or C++ compiler would. It's a very small price to pay for what you get.
Re:Microsoft rewrote Q# compiler in Rust by proc0 on Thursday June 22, 2023 @01:37AM (#36428357)
They play Rust.
Re:Microsoft rewrote Q# compiler in Rust by Measter on Thursday June 22, 2023 @12:31PM (#36434683)
Of course not, don't be daft! We go shopping for CPUs.
Re:Microsoft rewrote Q# compiler in Rust by Vecr on Wednesday June 21, 2023 @05:04PM (#36424479)
You can kind of compile (a version of) Rust into C and then compile that as well, but I assume miscompiles are common and there's very little checking done. It's used to bootstrap the compiler for Debian.
Re:Microsoft rewrote Q# compiler in Rust by nwah1 on Wednesday June 21, 2023 @03:41PM (#36423329)
Was there a write-up of what the goals of the rewrite were, and why they switched the language and made the new engineering decisions?
Re:Microsoft rewrote Q# compiler in Rust by bitwize on Wednesday June 21, 2023 @04:45PM (#36424181)
I don't think any language sparks joy the way Rust does -- not even Lisp and certainly not C# or F#. Rust gives the compiler lower memory overhead and attracts a broad base of developers.
Re:Microsoft rewrote Q# compiler in Rust by tmtvl on Wednesday June 21, 2023 @05:21PM (#36424751)
YMMV, of course, I have a hard enough time managing with one style of brackets, Rust has, what, five (round brackets, square brackets, curlies, angles, and vertical bars)? Never mind the fact that some operators are prefix:

  do_something(a_thing);
Others are infix:

  x = a + b * c;
And yet others are postfix:

  foo.frobnicate()?;
My sole braincell can't handle all that complexity, which is why I'll just stick with simple old Lisp.
Re:Microsoft rewrote Q# compiler in Rust by antonvs on Wednesday June 21, 2023 @05:06PM (#36424503)
> I don't think any language sparks joy...

Let the Marie Kondofication of programming languages begin.

But one of Kondo's points is that "Only you can know what kind of environment makes you happy," i.e. there are no universals.

Re:Microsoft rewrote Q# compiler in Rust by ohgodplsno on Wednesday June 21, 2023 @05:11PM (#36424591)
Begin?

The entire reason we have people trying to cram JavaScript everywhere is that, for some reason, it sparks joy for them.

Hell, even going back, K&R vs Allman brace style was about what sparked joy. Color themes? Spark joy. At this point, I am convinced that the way to get a software developer to do anything is to just play on that need for joy.

Re:Microsoft rewrote Q# compiler in Rust by insanitybit on Wednesday June 21, 2023 @05:20PM (#36424738)
> The entire reason we have people trying to cram JavaScript everywhere is that, for some reason, it sparks joy for them.

Wait really? I feel like it's just "you literally have no choice for frontend" and the various side effects of that.

Re:Microsoft rewrote Q# compiler in Rust by ohgodplsno on Wednesday June 21, 2023 @05:30PM (#36424884)
That would explain frontend, yes. But that would not explain NodeJS, JavaScript for embedded microcontrollers, and so many more.

Some might say it's Stockholm syndrome, but then there's the Python developers doing the same thing everywhere. And the LISP enthusiasts. So unless there's a lot of Stockholm syndrome (although it's not out of the question when it comes to LISP), a lot of it is easily explained by "me like language here, me go put language elsewhere to keep language"

Re:Microsoft rewrote Q# compiler in Rust by sudodude on Wednesday June 21, 2023 @07:30PM (#36426191)
I think that's just entrenchment at work. When the majority of your developers only know x languages, and one of them is always js, you tend to work by the lowest comments denominator and the tools that everyone can work with are the ones that stick.
Re:Microsoft rewrote Q# compiler in Rust by Turskarama on Wednesday June 21, 2023 @07:33PM (#36426218)
You're overthinking it. We have Javascript on the server because Javascript was a very commonly known language already (due to being the only choice for web) and the average programmer (one who doesn't post on these forums) is not going to bother to learn another language if they don't have to.

The easiest way to turn front end developers into full stack developers was to let them use the same language for everything, and it was easier to bring JavaScript to the server than to bring any other language to the web.

These days with WASM and JavaScript as compilation targets it might have been avoided, but it's already too late.

Anyway I rambled a bit but the point is "joy" has nothing to do with it.

Re:Microsoft rewrote Q# compiler in Rust by sudodude on Wednesday June 21, 2023 @10:40PM (#36427404)
I think that's just entrenchment at work. When the majority of your developers only know x languages, and one of them is always js, you tend to work by the lowest comments denominator and the tools that everyone can work with are the ones that stick.
Re:Microsoft rewrote Q# compiler in Rust by Turskarama on Wednesday June 21, 2023 @11:45PM (#36427795)
That's true, and I also think it's a mistake.

Any decent developer can become competent with a new language in a matter of weeks, whereas making a large application with the wrong choice of language and tooling can become a maintenance nightmare. Given how difficult it is to verify JavaScript programs as "correct", its use on the server has always riled me up.

Re:Microsoft rewrote Q# compiler in Rust by insanitybit on Thursday June 22, 2023 @09:17AM (#36431702)
> But that would not explain NodeJS, JavaScript for embedded microcontrollers, and so many more.

I'm only going to address NodeJS because I think that niche projects that target niche workloads are just unrelated.

I believe it does explain NodeJS. The idea is simple - your frontend engineers can own your edge services/ APIs. They're already heavily invested in JS and, at least at one point, there was a theory that unifying languages across frontend + edge made sense for other reasons.

Some people really just learn one language.

Re:Microsoft rewrote Q# compiler in Rust by jacobyoder on Thursday June 22, 2023 @10:21AM (#36432596)
> Some people really just learn one language.

I think that's a gross oversimplification. My colleagues know JavaScript, TypeScript and ECMAScript, as well as YAML, HTML and CSS.

Re:Microsoft rewrote Q# compiler in Rust by insanitybit on Thursday June 22, 2023 @12:28PM (#36434635)
I'm not trying to be mean but are you being sarcastic? I... can't tell...
Re:Microsoft rewrote Q# compiler in Rust by jacobyoder on Monday June 26, 2023 @08:52AM (#36479083)
At this point, I can't really tell either.
Re:Microsoft rewrote Q# compiler in Rust by comboy on Wednesday June 21, 2023 @05:32PM (#36424921)
> I am convinced that the way to get a software developer to do anything is to just play on that need for joy.

Works outside software development too.

Re:Microsoft rewrote Q# compiler in Rust by antonvs on Wednesday June 21, 2023 @07:54PM (#36426416)
I think the Javascript example is more about what people are already familiar with. Same goes for languages like Python. Other languages can't "spark joy" if you're not familiar or comfortable with them.
Re:Microsoft rewrote Q# compiler in Rust by rmwaite on Thursday June 22, 2023 @10:21PM (#36442049)
I agree with this. I use Fantasque Sans Mono for the same reason - k with a loop makes me feel warm and fuzzy for some reason.
Re:Microsoft rewrote Q# compiler in Rust by lionkor on Wednesday June 21, 2023 @04:55PM (#36424322)
Whichever language one prefers sparks joy like Rust does for you
Re:Microsoft rewrote Q# compiler in Rust by miohtama on Wednesday June 21, 2023 @05:02PM (#36424452)
While this is true on individual level, Rust has been ranked most liked programming language in many surveys and sparks joy to most of people more than other languages

https://survey.stackoverflow.co/2023/#section-admired-and-de...

Re:Microsoft rewrote Q# compiler in Rust by antonvs on Wednesday June 21, 2023 @05:07PM (#36424532)
What's missing from a survey like that is correlation with prior experience and education. Python was a previous winner on those kind of surveys, and it's a terrible language in many ways.
Re:Microsoft rewrote Q# compiler in Rust by miohtama on Wednesday June 21, 2023 @05:23PM (#36424795)
Where you are failing here is likely empathy, or understanding how other people work or think. This might be because lack of experience in programming, or just because of reflexive negativity. Even if you think Python is a terrible language, for many people it’s the best language for the job. This also includes must PhDs, because Python is the most used languge in science and academia.

When doing critical thinking, please set asides your own biases and try to understand that your own viewpoint is not always the correct one.

Re:Microsoft rewrote Q# compiler in Rust by brokenkebaby on Wednesday June 21, 2023 @07:41PM (#36426293)
This answer looks unjustifiably overheated for a statement that says X is "terrible in many ways". It can be the best tool for someone, and still be terrible in many ways, no contradiction here.
Re:Microsoft rewrote Q# compiler in Rust by antonvs on Wednesday June 21, 2023 @07:50PM (#36426381)
I understand why people use Python. However, I'm just assessing it from a technical perspective, not an emotional one.
Re:Microsoft rewrote Q# compiler in Rust by patrec on Wednesday June 21, 2023 @05:30PM (#36424894)
I think you are a bit detached from reality if you think controlling for experience and education would massively change the picture for python, which evidently enjoys above average popularity with anyone from junior devs to elite programmers (such as Google's Director of Research, geohot etc.).
Re:Microsoft rewrote Q# compiler in Rust by antonvs on Wednesday June 21, 2023 @07:34PM (#36426230)
The issue is what they're educated in. It's not generally programming languages.
Re:Microsoft rewrote Q# compiler in Rust by patrec on Wednesday June 21, 2023 @08:33PM (#36426658)
What makes you think so? If you've got a background in programming languages, maybe you'll roll your eyes at Guido not getting reduce or tail recursion, or CPython's unsophisticated runtime and under-specified/messy semantics, or whatever, but I'm kind of struggling to see why you'd be particularly down on python compared to other languages that (in the average case) have non-negative utility for software development.
Re:Microsoft rewrote Q# compiler in Rust by antonvs on Wednesday June 21, 2023 @08:48PM (#36426763)
I mentioned Python simply because it was ranked highly in some of these kinds of surveys, even though it has quite a few well-known problems as a language. It demonstrates that ranking in such surveys is not necessarily correlated with the capabilities or fitness for purpose of the language.

In some ways, Python is in fact worse than many of the mainstream alternatives - for example, it's not unusual for people to look to rewrite Python systems in some other language because of performance issues at scale. Same (if not worse) goes for Ruby.

Re:Microsoft rewrote Q# compiler in Rust by brokenkebaby on Wednesday June 21, 2023 @08:01PM (#36426457)
I cannot help but notice that Perl used to be very popular in early web development, sys administration, and in a a row of scientific fields. And lots of people were enthusiastic about it (as witnessed by CPAN content). Then it was declared unsuitable for teaching (many ways to do everything), and the next gen who started with Python usually claim that Perl is bad, while among older generation who matured cooking Perl scripts you still can hear that Python is nothing more than a less flexible, less expressive Perl's bastard child. So yes, I think, education (and the first usable programming language learned in particular) influence popularity very much.
Re:Microsoft rewrote Q# compiler in Rust by IshKebab on Wednesday June 21, 2023 @05:22PM (#36424777)
Yeah someone needs to do a ranked preference test. Rank all the languages you are familiar with...
Re:Microsoft rewrote Q# compiler in Rust by tmtvl on Wednesday June 21, 2023 @06:42PM (#36425691)
Funnily enough I'm not very familiar with languages I don't like, probably because I elect not to use them.
Re:Microsoft rewrote Q# compiler in Rust by antonvs on Wednesday June 21, 2023 @07:49PM (#36426374)
Limiting to relatively well-known general-purpose languages I've used in commercial system development:

Haskell, Scheme, OCaml, SML, Rust, Typescript, Smalltalk, Java, Scala, Common Lisp, Kotlin, C, C++, C#, Javascript, Forth, Delphi/Object Pascal, Turbo Pascal, Python, BASIC (various flavors), Fortran.

How about you?

Re:Microsoft rewrote Q# compiler in Rust by nequo on Wednesday June 21, 2023 @08:43PM (#36426725)
What was your commercial application for SML?
Re:Microsoft rewrote Q# compiler in Rust by antonvs on Wednesday June 21, 2023 @09:02PM (#36426849)
We developed the definitional model of a financial instrument modeling and simulation system in SML. The system included a DSL for specifying instrument models, so part of what the SML implementation did was act as a denotational semantics for that language.

The intent was never to deploy it using SML, it was to flesh out and formalize the design, and act as a specification for development of the full system.

The system was designed to run on a cluster long before the Kubernetes days, and so had to deal with many of the distribution, scaling, and concurrency issues itself, in addition to its business logic.

One of the experiences I had while working on that system was that at the time, I was reading "Monad Transformers and Modular Interpreters" - a seminal paper by Liang, Hudak, and Jones - and I thought I could probably quite easily implement the paper's approach using ML parameterized modules, instead of the Haskell typeclasses used in the paper. I tried it, and was soon disabused of that notion. Partly as a result of that, we wrote the distributed simulation engine for a later version of the system in Haskell.

Re:Microsoft rewrote Q# compiler in Rust by IshKebab on Thursday June 22, 2023 @09:02AM (#36431507)
I'd probably go

Rust, Typescript, C++, Go, Java, OCaml, Python, Javascript, Matlab, PHP, SystemVerilog, CMake, C, Bash

Ok I will make this site. :)

Re:Microsoft rewrote Q# compiler in Rust by antonvs on Thursday June 22, 2023 @09:41AM (#36432021)
Oh I left PHP and Go out of my list, my subconscious blocked them out of existence. They'd be near the bottom anyway. I suppose Go with polymorphic types might be worth another look, but before that it was dead to me.
Re:Microsoft rewrote Q# compiler in Rust by IshKebab on Thursday June 22, 2023 @04:08PM (#36438113)
I feel like Go is a so-so language with amazing infrastructure. How many other languages come with built in easy cross compilation, fuzzing, PGO, etc?

It is really unsurpassed in that regard, which is probably partly why it is so popular in DevOps. If only the language was a bit better...

It's definitely not a bad language like PHP though.

Re:Microsoft rewrote Q# compiler in Rust by Patrickmi on Sunday June 25, 2023 @05:01AM (#36466226)
A Subconscious that doesn’t want to admit it, not every “good language” makes it to the next round
Re:Microsoft rewrote Q# compiler in Rust by Dudester230602 on Wednesday June 21, 2023 @06:14PM (#36425421)
While I admire it I most certainly do not desire it - like Haskell. I need to ship things, not figure out some borrow of a monad.
Re:Microsoft rewrote Q# compiler in Rust by bitwize on Wednesday June 21, 2023 @07:45PM (#36426332)
Languages with built-in checks for correctness, like type checking and borrow checking, help you ship software faster in the long run, cheaper, and with fewer bugs.
Re:Microsoft rewrote Q# compiler in Rust by HumblyTossed on Wednesday June 21, 2023 @05:35PM (#36424971)
I actually don't like Rust. It just doesn't fit me.

To each their own, I suppose.

Re:Microsoft rewrote Q# compiler in Rust by pjmlp on Wednesday June 21, 2023 @04:06PM (#36423649)
I guess yet another minus for F# at Microsoft. Really funny how they manage it.
Re:Microsoft rewrote Q# compiler in Rust by progmetaldev on Wednesday June 21, 2023 @04:22PM (#36423839)
Really puts me off learning it, other than dipping my toes in functional programming and being experienced in C# and the .NET Core/Framework libraries. I thought it may be easier to start with F# before moving to another functional language.
Re:Microsoft rewrote Q# compiler in Rust by Jenk on Wednesday June 21, 2023 @05:23PM (#36424792)
The tooling (Visual Studio, LSPs, etc.) around F# is very lacklustre, I wish it had better support from MS. At the moment F# just seems to be a playground for experimenting with FP ideas that then get ported to C#.

As for learning a functional language, I recommend this Haskell tutorial[0], and accompanying video series of an experienced haskeller (Brian McKenna) running through it[1]. I've read countless texts and tutorials explaining Haskell and FP to me but it didn't fully click until I saw someone with experience using the language and tooling effectively.

[0]: https://github.com/system-f/fp-course [1]: https://www.youtube.com/playlist?list=PLly9WMAVMrayYo2c-1E_r...

There are a few other video series from other experienced haskellers available that may be better, too, I just haven't watched them so I cannot comment.

Re:Microsoft rewrote Q# compiler in Rust by progmetaldev on Thursday June 22, 2023 @05:58PM (#36439657)
I appreciate the response. As someone that struggles with higher-level math, am I going to get a benefit out of starting with Haskell? I have built financial systems in various languages, so my issue isn't necessarily how to code math functionality. It's more of the abstract concepts that get me.
Re:Microsoft rewrote Q# compiler in Rust by Jenk on Thursday June 22, 2023 @06:37PM (#36440143)
I believe you will, yes. You may not be able to jump right in to some of the deep discussions about type categories, I certainly can't, but I still have learned a lot from Haskell and both continue to use Haskell itself and use what it has taught me in other languages to my betterment.
Re:Microsoft rewrote Q# compiler in Rust by progmetaldev on Thursday June 22, 2023 @07:10PM (#36440489)
Thank you for the explanation and suggestion. Sounds like it will be worth my effort to at least learn, just for new ways of developing, and how that affects any other language I touch.
Re:Microsoft rewrote Q# compiler in Rust by Jenk on Friday June 23, 2023 @11:32AM (#36448276)
As a quick example, a lot of what @Iceland_jack has mentioned I can make sense of, but I wouldn't have been able to contribute to that. I guess it is a bit like learning a foreign language and I am at the point of being able to understand what a native speaker is saying to me, but my responses are probably garbled nonsense. :) However I am still confident that what I have learnt has empowered me to be a better developer.
Re:Microsoft rewrote Q# compiler in Rust by Iceland_jack on Thursday June 22, 2023 @11:37PM (#36442492)
The abstract concepts give you the tools to quickly classify a datatype. They are not limited to Haskell and let you ask the right questions of datatypes in any language.

The foundational concept is functoriality, i.e. mapping over the argument of a type. Whether a datatype has an instance of

1. (covariant) Functor

2. Contravariant functor

3. Functor+Contravariant (phantom argument), or

4. neither

says a lot about its structure and tells me what further questions I can ask (what hierarchies I can expect): A datatype can only be a Monad if is covariant. It can only be Divisible and Decidable if it is contravariant. If it is both (3.) then its argument is not used (phantom) and can be mapped to any type. If it is neither (4.) it can be invariant (where the argument appears in both positive and negative position: like the Endo datatype) or a more complicated datatype like GADT, which would require a more complicated functor.

Re:Microsoft rewrote Q# compiler in Rust by Dudester230602 on Wednesday June 21, 2023 @06:18PM (#36425465)
I am ready to treat Q# same way as Microsoft is treating F#.