27 ms·
Wow. Preemptive multitasking, graphical window management, POSIX-like, in a programming language that to my knowledge it hasn't yet been done in... and in just
by jchw 7y ago
Wow. Preemptive multitasking, graphical window management, POSIX-like, in a programming language that to my knowledge it hasn't yet been done in... and in just several months of work.
There's no smoke and mirrors as far as I can tell. I dug back to the initial commit: https://github.com/ffwff/lilith/commit/c9fa1053dc6a22d630ee62163d3504f4c003cea8 https://github.com/ffwff/lilith/commit/c9fa1053dc6a22d630ee6... - and it's just bootstrapping to VGA.
Very well done, and inspiring. Makes me want to try OS dev again.
- mberning 7y agoAgreed. Super impressive. I really like Crystal and hope it continues to get traction.
- onlyrealcuzzo 7y agoMaybe it's just because I come from Ruby, but Crystal seems like an amazing language. I'm interested why it seems to be getting little attention compared to Go, Rust, & Julia. It seems in the same league to me. Kotlin and Swift have more obvious reasons for their adoption.
- lmm 7y agoWhat's Crystal's unique selling point? It's older than Rust, Kotlin, Swift, Nim, or even OCaml, and doesn't really offer anything they don't. More Ruby-like syntax? Fine, but most people don't particularly like Ruby syntax.
- tbrock 7y agoWell unlike the rust circlejerk apparently people are using it to build operating systems instead of just talking about how one day they might.
- klyrs 7y agoI'm not smitten with the rust fandom either, but at least do your homework https://www.redox-os.org/ https://www.redox-os.org/
- deleted 7y ago[deleted]
- shakna 7y ago> It's older than Rust, Kotlin, Swift, Nim, or even OCaml, and doesn't really offer anything they don't. Crystal is only five years old. Nim is 11, Rust is 9, Kotlin is 8, OCaml is 23 and Swift is 5. Basically, Crystal is tied with Swift as the youngest. What it offers right now is a simple porting process for those with Ruby codebases.
- k__ 7y agoI think they meant younger. But, yeah, besides the syntax familiarity for Ruby programmers it doesn't seem offer much that the others do.
- nine_k 7y agoOkay, port your existing Ruby code to a compiled language, giving it multiple times the speed? Maybe three is a slight business opportunity here. Also, give your developers a more productive language that can go where Ruby can't (like OS development), which is 90% instantly recognizable — may also be worth something?
- lmm 7y agoIs it really so hard to port Ruby code to any of the languages I mentioned? Even with Crystal you will still have to make changes to your code, is having to use a slightly different syntax such a big difference? If you've got Ruby code and you haven't already ported it, how badly do you need the speed?
- rvz 7y agoWell it seems most developers here would rather use Ruby + several memory-optimised VM clusters to make their services go faster and destroy their balance sheet than to use a faster language that is efficient in memory and is also blazing fast. A rewrite in (other fast language) from Ruby sounds ridiculous as soon as you include writing a extra FFI wrapper around this you have to maintain so that would be out of the picture and that sounds a lot harder than a semi 1:1 port of the source code. The trouble is Ruby itself is starting to become a sunken cost as a language but is survived because of Rails, thus also explains the countless memory issues that happen when developers use it. So for a stopgap to something sort of better, I would rather port to Crystal or Elixir so I can run on those low-cost VMs and save cash.
- nlh 7y agoC bindings, strongly-typed, a great concurrency model, very fast, and Ruby-like syntax. That makes it a very unique and appealing language to me (and others). If you / most people don’t particularly like the Ruby-like syntax, then Crystal might not appeal to you. But I can assure you to those of us who like the syntax, the language is wonderful and super fun to work with.
- lmm 7y ago> C bindings, strongly-typed, a great concurrency model, very fast My point is that all this is normal, and all the languages I list have offered it for longer than Crystal.
- jbverschoor 7y agoLLVM based, and in terms of performance, it's one of the fastests
- dragonwriter 7y ago> C bindings, strongly-typed, a great concurrency model, very fast, and Ruby-like syntax. Ruby’s syntax is a great fit for Ruby’s semantics but—and Ruby is my personal favorite language—I don't see much point for it divorced from that. It's the one thing I like least about Elixir. OTOH, Crystal looks like it may be close enough to Ruby semantics that Rubyish syntax is a plus rather than a misdirection and distraction.
- cosarara 7y agoIn what way is Elixir's syntax like Ruby's? It has "end" on blocks and string interpolation with "#{whatever}", but everything else is different. It's about as close to Ruby as Ruby is to Python (which is to say, not much).
- onlyrealcuzzo 7y agoI think it really helps that you can write mostly functional code in Ruby by just chaining higher-order array functions, and you can use Pipes in Elixir to do this almost identically -- when you consider the fact that all the higher-order array functions have identical or very similar names and parameters in the two languages. My Ruby code is like 95% chained higher-order array functions. My classes almost never have state. I'm basically writing functional code, and it seems like this is a pretty common paradigm in Ruby. I will say this was HEAVILY influenced by learning Elixir. When not taking external libraries into account, my Elixir code (at least to me) seems almost identical to my Ruby code. I think Python and Ruby are very close. But I personally think list comprehensions are un-intuitive and you can't easily chain higher-order array functions in Python. So although I feel the spirit of my Ruby and Python code is identical, in no way do they look and feel identical. In the same way, I think my Elixir and Python are quite different. Sample size of 1. I know. Just thought I'd share.
- loktarogar 7y agoRuby's syntax is a huge draw for many people.
- disc 7y agoIt's possible that some (many?) programmers enjoy a Ruby-like syntax?
- viraptor 7y agoKotlin - it's on JVM which is a good thing for some and a bad thing for others. It's easier to distribute standalone crystal binary for example. Swift - crystal throws exceptions, swift explodes... Ocaml - the functional approach is not for everyone. Rust - I like rust a lot. But sometimes I want to write something quick and I'm happy to sacrifice some memory and speed to not have to deal with the ownership issues. Nim - the most comparable, I guess it's syntax preference at that point
- imhoguy 7y agoYou can use Kotlin/Native [0] or just plain Kotlin over Java with GraalVM which produces compact binaries. [0] https://kotlinlang.org/docs/reference/native-overview.html https://kotlinlang.org/docs/reference/native-overview.html
- vips7L 7y agoKotlin/native's stdlib isn't feature complete. You have to use raw syscalls to do anything.
- ernst_klim 7y ago> Ocaml - the functional approach is not for everyone. OCaml is pretty general purpose though, it has loops, objects, mutable state. libguestfs [1] and some other codebases (the compiler itself, btw) are written in a pretty imperative OCaml. [1] https://github.com/libguestfs/libguestfs https://github.com/libguestfs/libguestfs
- Jenz 7y agoOCaml somewhat tries to be familiar for OOPs, but it _is_ first and foremost a functional language. Personally, I am learning it now, and I think rather than it being a stepping stone between OOP and FP, it might as well be its own separate and hybrid paragdim; I find purer FP languages like Haskell much more intuitive than the mix of modules, objects, types and classes of OCaml. Though do not get me wrong, OCaml is an amazing language. It just stands rather by itself. Pardon my terrible english.
- unixhero 7y agoIt's for Ruby's developer friendly syntax. That's a huge selling point!
- PixyMisa 7y agoUnique? There are a hell of a lot of computer languages out there. The only unique ones are those that are so bad that no-one ever did that again. The selling point for Crystal is that it has a clean syntax that's easy for Ruby or Python developers to pick up (almost the same as Ruby), but compiles to standalone binaries that run really, really fast. I mostly work in Python because the libraries are a lot more mature, but I use Crystal when I need to produce a standalone binary.
- dom96 7y agoHave you given Nim a try, as a Python developer it seems like it would be right up your alley.
- Shorel 7y ago> but compiles to standalone binaries that run really, really fast. In a world with Go, Rust, D, C++ and C, this part requires comparison with these other languages. Faster than Ruby and faster than Python doesn't cut it.
- Symmetry 7y agoI'm not familiar with all those langauges but I found the inference of union types pretty impressive. foo = ENV["FOO"]? || 10
- RX14 7y agoIt's unique selling point is union types as a part of the type system, with whole-program type inference and flow typing. This has never been done before (as far as I am aware), and it is incredibly powerful and interesting. It's compile-time duck typing.
- mapcars 7y ago>whole-program type inference and flow typing What do these mean?
- c-cube 7y agoIt's very expressive and pleasant (and I never used ruby), while being fast and statically typed. That's a great combination of features. If it were stable, it'd be a serious contender to Go imho.
- nlh 7y agoI found Crystal about a year ago and absolutely fell in love with it. It just “clicks” for me. My sense from reading most peanut-gallery commentary that the biggest reasons it hasn’t taken off more (yet) are: 1. Real multi-threading (it’s now in alpha - but previously just had single-threaded concurrency - and sorry I might be getting that terminology wrong). 2. Windows support (I personally don’t care but I haven’t found a single thread talking about Crystal where someone doesn’t chime in and complain about this) I have a feeling once it reaches 1.0 and those issues are addressed it’ll get a bit more attention. It deserves it!
- dleslie 7y agoIt lacks first-class Windows support. That's it. That's why it fails to gain the traction it deserves.
- giancarlostoro 7y agoThat never stopped the Go community from porting Go to Windows. It was never ported by core maintainers, but by Go developers themselves.
- dleslie 7y agoAnd yet it was ported, and has OK support. Crystal on Windows is a non-starter right now.
- giancarlostoro 7y ago> OK support I havent had issues with Go on Windows or any OS, is there something broken about Go in Windows?
- pjmlp 7y agoGo still lacks Windows support for certain features, e.g. plugins. And wanting to be part of Google team helped many community contributions. Easy to compare with how much community contributions were made to Inferno and Limbo.
- giancarlostoro 7y agoFair, I had forgotten about plugins. On the other hand plugins has other nuances[0]. Plugins don't seem like a properly release feature due to its constraints. [0]: https://www.reddit.com/r/golang/comments/b6h8qq/is_anyone_actually_using_go_plugins/ejkxd2k/ https://www.reddit.com/r/golang/comments/b6h8qq/is_anyone_ac...
- craftinator 7y agoBut then, developing an OS in Windows is akin to racing a Ford on a formula one track. Just why bother? Why not use an OS that doesn't need a whole weeks worth of reboots and regedits to set up the Dev environment correctly?
- burlesona 7y agoI wouldn't say it's getting "little attention," rather it's relatively new (for a language) and not backed by a major player who can instantly give it a huge spotlight / platform. For being a 5-year old indie language out of South America, I think it's doing quite well, and projects like this are good evidence of why. Ruby is an outstandingly productive language. Copying the expressive syntax and ergonomics of Ruby into a fast, statically typed, compiled language with excellent C bindings is a very compelling idea.
- auvi 7y agoTwo other languages that I can think of that have their roots in South America are Lua and Elixir.
- holtalanm 7y agoi've been a huge fan of elixir ever since i found it a few years ago. The main web framework (phoenix) is doing some really cool stuff right now with live-view, too, and I'm pretty darn excited about it. I've always thought that the best system for a web server would be erlang OTP, because of the design based around uptime and system recovery. It has been proven in production by a few companies now in web dev, and erlang has been used for years by telecom companies for their own infrastructure. elixir, imo, is awesome because of the ruby-like syntax, but I would probably be using erlang for my personal projects regardless because of what I mentioned earlier.
- haliax 7y agoIsn't elixir just syntactic sugar on top of Erlang semantics?
- dnautics 7y ago1) Yes. 2) No. It's sugar + opinions. Elixir gives you a lot of 21st century development tools: Async Tasks, Compilation environment (dev vs prod vs test out of the box), first class documentation and first class test suite. Sure you could implement these in erlang, but in Elixir, it's opinionated and everyone is basically on board with the same set of tools. Some of these tools are making their way back to erlang, like telemetry, and some aspects of docgen. There are also some under the hood features, too. I can run async tests where the test is given an id, the database gets a sandbox with that id, I can escape the vm (via chromedriver, eg) passing the id, and when the request hits the http server component, it and all child tasks is aware of the test that it's in, so all of the database calls are routed to the correct sandbox, resulting in concurrent and idempotent end-to-end tests. Again, you could do this from top to bottom in erlang, but elixir has support for this out of the box, and the good anointed and 3rd party libraries (Mox, ecto, hound) use these elixir features. It's pretty nice to be able to run a full suite of unit and E2E tests in about 10 seconds.
- mintplant 7y agoDidn't Crystal run into a major development roadblock a couple(?) years ago? Something about a fatal design flaw in the type system which led to exponential blowup in larger programs. I haven't been able to surface the relevant GitHub threads again, but whatever it was, I guess they worked past it eventually.
- orthoxerox 7y agoYew, they tried to do whole-program type inference a la ML. That was a long time ago, modern Crystal has you indicate parameter and return types.
- asymmetric 7y agoDo you have a link?
- ezrast 7y agoAll that stuff is still optional. I don't think there are any cases where removing type annotations from a working Crystal program will change behavior.
- ezrast 7y agoYou're probably describing this or a related issue: https://github.com/crystal-lang/crystal/pull/6351 https://github.com/crystal-lang/crystal/pull/6351 I don't think it was ever a major roadblock. The fix isn't pretty but it doesn't come up that often in practice.
- wilandbo 7y agoHave been playing with Crystal for several months and still find it amazing what this language can deliver given that it's still relatively new. Asked my friends to try it out and they love it too. Hopefully we can grow a bigger ecosystem for Crystal to make it a main stream programming language one day.
- jcadam 7y agoWell, I hadn't heard about Crystal until... just now. So projects like this are great marketing. I'm reading up on it and liking what I'm seeing so far. This could be a great Golang (which I detest) replacement for me when I need to write a small, native program. Also, the Ruby-esque syntax is a win. I've always thought Ruby was a nicer language than Python. Too bad Ruby never grew much of a dev community outside of Rails.
- fluffything 7y ago> I'm interested why it seems to be getting little attention compared to Go, Rust, & Julia. Rust essentially competes with C and C++ (and maybe D and Nim without their GCs), and the reason it gets hype is because it brings some unique features for that niche. Go brought some unique features as well (goroutines done right), and it is pushed by a major player. In Julia's niche, you only really have Julia and Fortran - sure there are many other languages used in that niche, but there are very very few languages exclusively designed for that niche. C#, Kotlin and Swift are the system API languages of major platforms (MS, Apple, Android). Javascript is the language for the web. What's Crystal for?
- gdxhyrd 7y ago> C#, Kotlin and Swift are the system API languages of major platforms (MS, Apple, Android). No, the system API of those systems is exposed in C, ObjC and C respectively. You may be thinking about the most common language in those platforms nowadays (and their respective APIs).
- fluffything 7y ago> No, the system API of those systems is exposed in C, ObjC and C respectively. This is incorrect. Microsoft doesn't have a C compiler, only a C++ compiler, so the lower level language on Windows is C++. Yet for application development, the application language is C#. On Apple, the lowest level language is ObjC, and the application language is Swift. And on Android, its C + Kotlin. Doing application development on, e.g., Android, using the C NDK, is pretty much unsupported, since the NDK is mostly undocumented, and changes often. The only stable API for application development is Java, or Kotlin.
- LessDmesg 7y agoIt's still C all the way down, even in 2019. Amazing how far crappy, badly thought out, ubiquitous, low entry barrier languages can go. More than 40 years of memory errors, out of bounds errors, broken metaprogramming, undefined behavior, lack of error handling, type safety, abstractions and intelligent design in general, all served under the clunky syntax sauce. And it still powers our world. Worse is better, indeed.
- coldtea 7y ago>I'm interested why it seems to be getting little attention compared to Go, Rust, & Julia As I see it, Go gets 70% of the attention, Rust 25% and Julia 5%. Crystal which doesn't have major backing (no Google, no Mozilla, and Julia has some MIT hackers behind it IIRC, plus the whole "data science" angle which is fashionable today), gets even less.
- todotask 7y ago>I'm interested why it seems to be getting little attention compared to Go, Rust, & Julia I've noticed the slogan was change to "A language for humans and computers", what it really mean? Related to machine learning? My impression that other than it was design to be as friendly as Ruby and fast as C. It's a lot helpful to have an FAQ if the Crystal team could provides.
- saagarjha 7y agoInteresting choice of syscalls: https://github.com/ffwff/lilith/blob/master/userspace/libraries/libc/src/functions/syscalls.cr https://github.com/ffwff/lilith/blob/master/userspace/librar.... No fork; instead it seems to implement spawnv.
- userbinator 7y agoAFAIK fork() is specific to UNIX and its descendants; DOS, Windows, and many(most?) other OSs don't have it either.
- yjftsjthsd-h 7y agoSure, but an OS that self-describes as "POSIX-like" would be expected to follow the UNIX approach to things.
- ffwff 7y agoPOSIX-like, not entirely POSIX! There are basic IO syscalls, and some process management calls, but overall I try to take unix as a guideline rather than trying to reimplement one entirely. I also try to take inspiration from other kernels (like fattr (which is equivalent to GetFileAttributes from WinNT), and spawnv from DOS/WinNT). I guess I should reword it :/
- tyingq 7y agoGoogle's Fuchsia has a similar approach to Posix (no fork, signals, etc). Maybe some of their wording would be of use? https://fuchsia.googlesource.com/docs/+/refs/changes/56/101356/4/libc.md https://fuchsia.googlesource.com/docs/+/refs/changes/56/1013...
- yjftsjthsd-h 7y agoThat's fair. And to be clear, reading "POSIX-like" makes me expect it to act like a unix, but that hardly means that you should be bound to follow that exactly:) If you wanted to set expectations a bit, maybe "partially POSIX-inspired, with other influences from $FOO and $BAR" would be clearer?
- ffwff 7y agoSorry for the late reply (being rate limited) Thanks! Originally it only started as an experiment to see how far I could go making an OS in a high-level (higher than C at least) language, I was only planning to build a monotasking DOS system. Around this time, Andreas Kling started to show us his SerenityOS, which was one of the factors propelling me to reach this point. So shout outs to AK! Yeah! It's pretty fun to develop an OS, albeit time consuming. You should check out the osdev wiki and the Intel/Seagate manuals, they should hopefully get you to the point where your OS can read/write/execute files, you should also take a look at how other kernels do things as a reference and actually implement them in your OS in a way that fits.
- z92 7y agoWhen does GC kick in during the boot sequence? And how are you managing memory? Is the whole OS mark and sweeped?
- ffwff 7y agoRight after the global descriptor table is setup and paging is enabled, the GC is then enabled. On every allocation, and whenever the os has no task available to switch to, a gc cycle is performed. Not really, the kernel and any process written in crystal has a garbage collector, any other userspace process can manage memory however they want to.
- crazypython 7y agoI wonder what a D OS would be like.