16 ms·
Bflat: C# as you know it but with Go-like tooling
- jonnycomputer 5y agoClever name.
- quaffapint 5y agoI was hoping to see in the readme how this is different than what they offer in core today? You can build self-contained exes (and they're getting better with each release). Is this the same only different or an improvement on that?
- np_tedious 5y agoIt's been a few years, but I worked on a dotnet core C# project once. Prod was Linux and dev usually OSX. I remember running a dotnet build to generate some kind of artifact (dll maybe) that still needed the SDK to run. Is there some other way to do it that made a self contained executable?
- atraac 5y agoYes, since I believe 2.1 you can make a self contained executable with sdk included using dotnet publish. You can read more about it here: https://docs.microsoft.com/en-us/dotnet/core/deploying/#publish-self-contained https://docs.microsoft.com/en-us/dotnet/core/deploying/#publ...
- quaffapint 5y agoThe nice thing they also added was the ability to trim the self-contained app, so it doesn't include a lot of unnecessary assemblies. https://docs.microsoft.com/en-us/dotnet/core/deploying/trim-self-contained https://docs.microsoft.com/en-us/dotnet/core/deploying/trim-...
- gregmac 5y agoYep. One of the things I've been doing lately with some internal utility apps is building a small Windows exe (for Workstations where almost always the dotnet runtime is already installed), and a larger but self-contained binary for linux. dotnet publish -r win-x64 -p:PublishSingleFile=true ---self-contained=false dotnet publish -r linux-x64 -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained=true To give an example of this for a reasonably complex test tool I have on .NET core 3.1, the Windows exe is 3.7MB and the linux binary is 38MB. I'm guessing there's some room for optimization in the process though, as the linux binary is compressed (tgz) to 13.37MB.
- andrewmd5 5y agoThe binary is that big on Linux because the debug symbols are embedded in the executable. You need to strip them.
- GordonS 5y agoHuh, the debug symbols are in separate .pdb files, aren't they? 38MB is a pretty typical size for a real-world, self-contained, assembly-trimmed package, and the size comes from the runtime itself, plus the core assemblies that weren't trimmed out.
- rcarmo 5y agoActually, in my tests with the AoT compiler I had to strip the binary to get a significantly smaller one despite there being a .pdb file. Your mileage may vary as the build flags can be a bit fiddly.
- gregmac 5y agoIn the interest of keeping the comment small, I omitted a couple things: -p:Configuration=Release -p:DebuggerSupport=false FWIW, I did also try the following, but found they had basically no impact on output size: -p:TrimMode=link -p:EnableUnsafeBinaryFormatterSerialization=false -p:EnableUnsafeUTF7Encoding=false -p:EventSourceSupport=false -p:HttpActivityPropagationSupport=false (Tested on .NET Core 3.1.5)
- mdasen 5y agoYes, .NET Core can now create self-contained executables. Microsoft and others have been enhancing this since it was introduced in .NET Core 2.1. I've been enjoying the way that .NET has been evolving in pragmatic ways. The initial implementation basically created a self-extracting zip that would include the runtime. That had its drawbacks, but it was a way for them to get self-contained deployable out the door with minimal hassle. Sure, it meant taking up a bit more space, but it worked and solved what most people cared about: having a single file that they could run without needing to install things in the OS. Likewise, they came up with ReadyToRun. Basically, they'd AOT-compile stuff for fast startup times, but include the byte code so that things could be JIT-compiled during runtime. This meant that the AOT-compiler didn't need to be perfect and that they didn't need to worry too much about things like the performance of reflection code. That code would end up JIT-compiled in long-running programs. Again, a pragmatic approach that does have some drawbacks (like large deployable artifacts), but they got it out the door and have been improving it as time goes forward. A more pure approach might be to wait until one can produce a really top-notch AOT compiler, wait until one can replace certain reflection-heavy code, wait until one can optimize libraries, wait until one can do lots of testing to make sure you don't have regressions, etc. But that requires a lot of time while what a lot of people might want isn't a pure solution, but just something that allows them to speed up start times. Likewise, zipping up the runtime with your code into a self-extracting and self-running file isn't the most pure approach, but it meant that you could get a single file to scp and just do `./myprogram` on.
- MarkSweep 5y agoThe self extracting is gone for Linux in .NET 5 and gone for Windows in the upcoming .NET 6. If any copying still happens, it just within the memory space of the process. If you include extra DLL or .so files, those still have to be extracted so that the operating system dynamic linker can load them.
- mdasen 5y agoYep! It's one of the things that's nice about the .NET ecosystem. We didn't have to wait for self-contained executables and got them back in 2018 (even if it wasn't perfect, it worked well enough) and they refined it as time went along in a way that didn't require me to do things. Microsoft could have waited until .NET 5/6 to offer self-contained executables "the right way", but they were able to create something that offered 90% of people what they wanted a few years earlier.
- cheschire 5y agoself contained executables simply bundles the libraries, but still requires a JIT compilation to execute. The description of bflat is what you are looking for, and it's the second section of the readme. bflat implements a form of ahead-of-time compilation. This is closer to .net native conceptually, but that was only a UWP abomination. edit: replies have pointed out this is actually closer to ReadyToRun, a neat feature I was not aware of.
- trynumber9 5y agoWhat about with ReadyToRun and single file?
- vexna 5y agoreplied with this on another post, but you can add `-p:PublishReadyToRun=true` to your `dotnet publish` command to do AOT. it blows up your binary in size, but pretty much gives your warmed up code from the start.
- Shadonototro 5y agoit doesn't fully AOT your app and worse it doesn't produce a native static executable it runs few tier for JIT, it still ship with IL and the JIT don't advertise ReadyToRun as "hey we got AOT at home, says Microsoft salesman" because all it does is makes me want to use Go instead, it feels and sounds bloaty
- loic-sharma 5y agoThose self-contained exes need a .NET runtime to be just-in-time (JIT) compiled to code your CPU can actually run. This JIT compilation happens as your app runs, so your startup performance suffers as a result. On the other hand, bflat compiles your project ahead of time into native code your CPU understands. Also, to build that exe you have to use the .NET SDK which pulls in lots of tooling: MSBuild, NuGet, etc... It looks like bflat ditches all of that.
- vexna 5y agoYou can actually add `-p:PublishReadyToRun=true` to your `dotnet publish` command and it will do AOT compilation for you. It blows up your executable a bit, but it does pretty much give you warmed up code at the get go.
- manigandham 5y agoThat's only partial compilation and not the full AOT available with something like CoreRT.
- mdasen 5y agoIt is different. .NET Core will create a self-contained executable which can have AOT compilation (or not), but which will include the byte code so that it can be JIT-optimized at runtime. This is about creating a binary that is small and uses some of the upcoming experimental stuff like Crossgen 2 and NativeAOT. Some of the Crossgen 2 stuff will land with .NET 6 this fall. As the project says, it's about bringing together two components that are being actively worked on in the .NET ecosystem to create a compiler and runtime for small binaries. For most people, you'll want the normal .NET self-contained Ready2Run binaries. They're compatible with everything and rock-solid. But sometimes you want to play around with something - like creating C# programs that are going to be tiny. Microsoft and others in the .NET ecosystem are improving C#/.NET at a rapid pace and it's great. bflat is, as it notes, using what is being created in that ecosystem. I mean, bflat literally labels itself "Initial proof-of-concept release" at this point. The guy writing it is on the .NET Runtime team at Microsoft and is really interested in these types of things. I think we can all imagine ourselves creating a project that does things a bit differently to figure out what is possible, figure out possible future directions we could take our work, etc. So, it is different from what is available in .NET today. It's written by one of the people on the .NET Runtime team who is interested in this stuff. Some of the concepts might show up in .NET 7/8/9. Heck, Crossgen 2 should be showing up in .NET 6. It's a cool proof of concept of slimming down C# binaries and even the readme shows how things like stack trace information takes up space.
- xaduha 5y agoBrilliant name.
- lelanthran 5y ago> Brilliant name. The name is a bit of a blunder: 1. Because of the placement of the ♭ in ♭Flat, that's actually read as "FlatFlat". 2. The note D♭ is the same as the note C♯.
- dkdbejwi383 5y agoIt would be better as Bx (B double-sharp), which is enharmonic with C#
- jefurii 5y agoJust fork C, name it B#, and you're done.
- lamby 5y ago> 2. The note D♭ is the same as the note C♯. Well, actually...
- mrits 5y agoI haven't played guitar in 20 years but I think D flat would have been a much better name
- ducaale 5y agoThis is nice, I have two questions if you don't mind: - Can bflat be used to compile F# code? - How do you build multiple files?
- loic-sharma 5y agoNot the author, but I would assume bflat cannot compile F# as this project uses the Roslyn compiler, which supports C# but not F#.
- MStrehovsky 5y agoPass the multiple files to `bflat build`. Or if you run `bflat build` without arguments, it will compile all *.cs files in the current directory. Not great, but works for now.
- tester756 5y ago>The source code is in the respective Roslyn/NativeAOT repositories. I'm not ready for people to see (or to accept pull requests) things that are specific to bflat. hmm? edit: nvm, it seems he's MS employee, so it's I guess it's legit.
- canadianfella 5y agoLegit isn’t the right word.
- jrochkind1 5y agoHe's asking for patreon donations though, in that same sentence?
- chii 5y ago> it seems he's MS employee, so it's I guess it's legit. don't care about pedigree - no source, no trust for a compiler...
- dasb 5y agoShouldn't it be D flat instead?
- ska 5y agoProbably not? I think they are intentionally calling it the relative minor, not same note, which makes a kind of sense in the usual way punny names do (i.e. a bit of a stretch, but not ridiculous).
- OscarCunningham 5y ago> We need a name that's witty at first but seems less funny each time you hear it.
- Jap2-0 5y agoB♭ isn't the relative minor of C♯? I think that'd be A♯ minor. Edit: Actually B♭ minor is the enharmonic equivalent of A♯ minor. IE another case of things in music that are the same but aren't.
- ska 5y agoI thought of adding the comment about enharmonics but it decided it would muddy the water further and edited it out. Should have left it in.
- jcpst 5y agoEnharmonic in the context of 12-tone equal temperament! slowly backs away
- Jap2-0 5y agoOh no you don't And now I'm down the rabbit hole of reading about tuning systems again.
- xaduha 5y agoNo, because then "be flat" part would be lost.
- tmccrary55 5y agoIt's like Go but old!
- LandR 5y agoTo me, Go feels like the antiquated language.
- haolez 5y agoA little off topic, but what's so good about C# nowadays? All developers that touch it start preaching it around as the best programming environment that they've ever used, but I haven't seen that many projects written in C# that really impress me (like Java or Go excel at). Also, and maybe this is unfair, but Microsoft's software is known for being buggier than one would expect and I imagine that C# is used a lot there. Please, help me correct my prejudices :)
- jpeter 5y agoBitwarden is written in C# (https://github.com/bitwarden/server https://github.com/bitwarden/server). If you want a project that impresses you, look at Ryujinx (https://github.com/Ryujinx/Ryujinx https://github.com/Ryujinx/Ryujinx)
- 369548684892826 5y agoAlso jellyfin, and I guess Emby which it was forked from https://github.com/jellyfin/jellyfin https://github.com/jellyfin/jellyfin
- deleted 5y ago[deleted]
- vorpalhex 5y agoC# is a general language, not strictly tied to Microsoft (only dotnet was, but dotnet core fixed that generally). C# is a heavily OO language with powerful semantics. If you like Java but hate the JVM, C# is your friend. C# has traditionally had much better developer aesthetics than Java but that gap has closed some. Also worth noting the Java licensing has gone batshit insane in the last version or two.
- vips7L 5y agoOpenJdk Is GPLv2 with class path exception. I don't know how that is batshit insane.
- MarkSweep 5y agoThe author’s ZeroSharp project is also interesting. It shows how you can compile C# without any runtime. No garbage collection, no exceptions. You can perform stunts like make a 5KB Hello World or a EFI application that runs with no operating system: https://github.com/MichalStrehovsky/zerosharp https://github.com/MichalStrehovsky/zerosharp I did a survey recently of binary sizes for .NET apps and comparisons to other languages. Things like NativeAOT (on which Bflat is built) and Graal Native Image let these languages get down to a binary size , startup speed, and deployment model similar that enjoyed by Go and Rust developers. https://github.com/AustinWise/SmallestDotnetHelloWorlds https://github.com/AustinWise/SmallestDotnetHelloWorlds
- throwaway894345 5y ago> You can perform stunts like make a 5KB Hello World Which, according to HN/proggit, is the only valid measure of a programming language. :)
- Gibbon1 5y agoIf one could cross compile to something like an ARM-Cortex, 5k hello world with no GC would be very interesting.
- hughrr 5y agoI’m not sure it would because a C one is measured in bytes and does the same thing.
- MarkSweep 5y agoI assume you mean an ARM microcontroller? I think it may be possible. .NET has a code generator for ARM32, which I think generates Thumb-2 instructions. The trouble I had last time I tried (.NET Core 3.1 I think) is you needed a cross compiling versio of RyuJIT that has the same bitness of your target. That is , you needed one that ran on linux x86 targeting linux arm32. And that was not easy to find. Maybe if I try compiling from a Arm32 host it will be easier.
- 5y ago
- irikeyu 5y agoSo is this a step down from c#?
- tk75x 5y agoA step and a half actually
- gavinray 5y agoI've been using C# with recent features like Function Pointers, [UnmanagedCallersOnly], Dotnet Native Exports, etc Have been writing C# to interact with C/C++ and publishing C ABIs as static/shared libs that are natively compiled My mind has been absolutely blown with what modern .NET and C# are capable of doing in terms of low level/systems program and interop with C/C++/Rust etc. The performance and object sizes are killer too. I think most people don't know or think C#/.NET are capable of this Can envision a not so distant future where C# is a common choice for places when you'd typically reach for C++ Also, the folks on the .NET Interop team are all super friendly and willing to have a conversation with you or answer questions. My experiences with the whole .NET organization at MS as a random person has been nothing short of shockingly pleasant.
- attractivechaos 5y agoI really like C# as a language, but as a Linux programmer, I found it difficult to install the dotnet sdk without the root permission. With that barrier, I can't recommend C# over Java, D or Go which are much easier to install.
- cebert 5y agoYou don’t need to install the SDK to run a dotnet core app. They can ship what’s required to run and there’s even single executable options now as well.
- spaetzleesser 5y agoOne caveat: If you ship a self contained app you often end up with 200MB of assemblies to ship. and the single file executables tend to load very slowly. It's basically an archive that first gets extracted and then executed. I had to give that up with a recent app because it was just too slow.
- kqr 5y agoYes, this deployment option makes tradeoffs that are clearly more in line with the use case of pushing out long-running server applications to machines with minimal configuration, rather than for desktop user applications.
- andrewzah 5y agoWhy would I use tooling that isn't open source?
- mdasen 5y agoI think if the author of it were here, he'd say that this is a proof-of-concept that he was working on to play around with NativeAOT and Crossgen 2 so that he could see what could be achieved with them. Sometimes things get posted to HN as if they were "you should use this because it's the future" rather than "this is a cool thing I made to show what could be possible". In the author's own words: "I'm Michal, I live in Slovakia, and I work remotely at the .NET Runtime team at Microsoft. In my spare time I work on C#-related side projects that I find fun but don't particularly overlap with my day job. You might know me from my greatest hits such as "Let's make C# run on Windows 3.11!", "How about a snake game in C# running on DOS?". I also write articles such as the one on how I built a fully self-contained game in C# in 8 kilobytes."
- MStrehovsky 5y ago(Author here, I hang out on HN.) Yup. There's really not much extra code in bflat compared to what's in the dotnet/runtimelab repo (in the NativeAOT branch). This just packages things differently so that one doesn't need the .NET SDK (plus Windows SDK if targeting Windows). The 100 MB bflat ZIP is all that's needed to target Windows or Linux.
- Arnavion 5y agoI think if a compiler gets posted to HN as if it's being provided for general use, asking for its source code is reasonable. The author is perfectly within their rights to keep it private, and we are perfectly within ours to call it out.
- arthurcolle 5y agoCan you do .NET development on a Mac these days? I vaguely remember a thing called Mono that was in vogue for a while before .NET Core became open source. Anyone have time to do a quick recap of capabilities on non Windows or Windows Server systems?
- elisaado 5y agoYes! The thing you're looking for is .NET Core.
- manigandham 5y agoThe latest release is just called .NET 5 .NET Core was the name for the cross-platform version, but that's the default now and will be the future. No need to differentiate from the older Full Framework anymore.
- pjc50 5y agoMicrosoft naming strikes again. I suspect they're only dropping the "core" now because they can - below 4 there's a need to disambiguate versus .net Framework versions.
- mattmanser 5y agoAnd the road between .net core 1 > .net core 2 > .net core 3 was extremely bumpy.
- Shadonototro 5y agoThis kind of project is what could make me use C# instead of Go for my server needs Microsoft is sitting on a gold mine and they don't know it!! yet!
- bob1029 5y agoI have a feeling that Microsoft is abundantly aware of the value proposition of the new .NET ecosystem. C# has always been a good systems programming language. NET Core/5/6+ have just taken that to a new dimension with x-platform and better tooling. The best thing about the MS stack is that it is built for the 8000lb gorilla projects (I.e. their own internal stuff). If you have a unicorn solution that has 2000 projects and requires 36 hours to build, visual studio, msbuild (dotnet build) are the things you want to be relying on to get you through the day.
- pjc50 5y agoMsbuild will definitely cope with that. Visual Studio, for all that it's a great IDE, gets creaky around 50 projects, I cannot imagine how long it takes to load 2000 of the things.
- eyegor 5y agoVS2015 was the last sturdy release. With VS2017 I had occasional hangs and crashes, but VS2019 either crashes or needs to be rebooted a couple times per day just to function. Intellicode is constantly breaking, test explorer only works reliability once a month, and it corrupts itself badly enough to need manual obj/ deletion at least once every few weeks. In their infinite wisdom, msbuild devs decided not to always clean the obj/ directory in the clean target by default. This is my experience on solutions with around a dozen projects, maybe 500k-1m loc across the solution. And it still barely understands how to use ram. Even if you let it see 64+gb, it will swap to disk.
- Shadonototro 5y agovisual studio became slow and laggy (interface) the day they ported their UI to C#, then it went downhill and i moved to sublime text, i still have to use VS, only for the debugger
- snarfy 5y agoNo source code. > I'm not ready for people to see (or to accept pull requests) things that are specific to bflat. If you think bflat is useful, you can leave me a tip in my tip jar and include your GitHub user name in a note so that I can give you access to a private repo when I'm ready. It's not hard to use CoreRT directly. [1] [1] - https://github.com/dotnet/corert/tree/master/samples/HelloWorld https://github.com/dotnet/corert/tree/master/samples/HelloWo...
- alpb 5y agoThere's zero chance anyone will seriously consider using this without the source code being available. :) So I am not too worried. The author would be ending up shooting themselves in the foot if they keep it that way for long.
- jozen 5y agoB flat as a replacement to C# huh? That name is a bit too clever.
- nhoughto 5y agoCool, so like Graal for Java. 2-3mb min file size is quite a bit smaller than the smallest Graal native images tho, I wonder what the difference is.
- bobowzki 5y agoI feel Dflat would have been a better name.
- bobcallme 5y agoThe name Dflat name is already taken by a GUI system for MS-DOS apps. See the FreeDOS EDIT.COM replacement or early 90s Dr.Dobbs Journal articles about it. https://github.com/alexfru/dflat20 https://github.com/alexfru/dflat20
- bodhi_mind 5y agoWas about to comment the same thing.
- sceptically 5y agoJokes aside... Without C#, life would ♭flat
- deleted 5y ago[deleted]
- galangalalgol 5y agoWouldn't bflat be the same note as a sharp, not c sharp? I'm not musically educated, but I don't get the name.
- jimkleiber 5y agoYea, I'm about 20 years rusty on the scales but I thought d-flat was the same as c#, not b-flat...
- elihu 5y agoDb and C# are "enharmonic equivalents". In 12-tone equal temperament, they're the same pitch, but in other tuning systems like just intonation they might be almost but not exactly the same pitch. https://en.wikipedia.org/wiki/Enharmonic https://en.wikipedia.org/wiki/Enharmonic
- loeg 5y ago12-tone equal temperament being what virtually all modern western music is transcribed in and what GP probably learned.
- jimkleiber 5y agoYup, most likely what I learned and yet I'm still fascinated to learn more. Thank you both!
- barosl 5y agoThis is very interesting. I like C# as a language, and I like Go by its tooling. If this project goes well, it would be the best of both worlds. The official `dotnet` command is not to my taste for a few reasons. It uses XML, and it is quite slow, e.g. a simple "Hello, world" project takes 2 seconds to launch every time. I mean, it always takes 2 seconds even after compiling everything prior to that. It might be acceptable for an interactive development environment that employes an auto-compiling workflow, but for a CLI tool, it is too much of a burden. I know Microsoft are trying to improve it, but at least up until now it hasn't been very successful.[1] [1] https://github.com/dotnet/sdk/issues/8697 https://github.com/dotnet/sdk/issues/8697
- pjc50 5y agoThe discussion linked hits all the points; dotnet run is build+run, ie do a dependency scan. It even lists the faster alternatives. On the other hand you have a point that "dotnet" is trying a bit too hard to be a magic swiss army knife.
- barosl 5y ago`go run` is also build+run, with a dependency scan. But it executes instantaneously. So there is already an evidence that the status quo can be improved. Even Rust's `cargo run` is much faster than `dotnet run`.
- zoom6628 5y agoThis is exciting. Given the tiny size of the executable i would love to see this hooked up with Blazor for web applications. It also is very appealing for tooling.
- deleted 5y ago[deleted]
- aidenn0 5y agoShouldn't it be Dflat?
- charles_f 5y agoThe only suggestion I'd have is renaming it Dflat, especially fitting with the spiel around it being the same but different