8 ms·
Ditching 200K of C++ for 30K of Scheme
- jerf 16y ago"Finally, many Racket tools depend Racket’s “eventspaces,” which are multiple process-like entities in the same virtual machine, each with its own GUI event loop. Implementing eventspaces on top of modern GUI toolkits turns out to be tricky, because the toolkits insist on a single event-loop per process and they cannot tolerate event-loop actions during certain callbacks." I can not wait until this is fixed. I can't hardly use toolkits anymore because I keep insisting on programming in languages with sane concurrency stories and that drives the toolkits insane. (I fully acknowledge the scope of my request and further fully acknowledge that this will almost certainly require something written from scratch. And that writing a toolkit from scratch is a tall order. And that now's a bad time to start trying because the alternate concurrency stories are in flux and it's not really a great plan to write something that works in Haskell but can't work in Erlang or Racket. And also now's not the best time because the very graphical underpinnings in Unix are now being called into question and, given that this is a multiyear project, it could build on X only for X to be on its way out. But still, I can't wait.)
- joe_the_user 16y agoIt is fixed in QT. "Each QThread can have its own event loop. You can start the event loop by calling exec(); you can stop it by calling exit() or quit()." http://doc.qt.nokia.com/stable/qthread.html http://doc.qt.nokia.com/stable/qthread.html I've used this successfully.
- carterschonwald 16y agoit sounds like if you use the racket 5.1, it is fixed! (in that you don't need to deal with that restriction). That being said, that certainly is still an obstacle if you're preferred lang isn't scheme/racket. Perhaps their wrapper code could be factored out as a new abstraction layer for these gui tool kits?
- deleted 16y ago[deleted]
- futuremint 16y agoI wrote a small GUI based HTML scraping client about 5 years ago with PLT Scheme. It was a wonderful experience and building a basic cross-platform GUI was pretty easy given the great documentation those guys write along with the language. The executable was small, and it was easy for the users to pass around a little 1MB .exe file on windows (also had a separate compiled version for OS X) and they used it for years after I left until the web pages it targeted changed (and I don't work there anymore). If somebody is open to learning Scheme, you can't go wrong building something in Racket, I was pretty surprised what I accomplished in a month.
- aaronblohowiak 16y agoFor other readers: PLT Scheme has become Racket (ship of theseus problem)
- futuremint 16y agoYeah, sorry I didn't make that clear :) PLT Scheme has become Racket... even though its still Scheme. It looks to me like a lot of the core PLT guys were involved in the R6RS debacle, and didn't like what came out of the process so decided maybe they aren't quite an official "Scheme" anymore per R6RS. Oh the drama...
- spdegabrielle 16y agoI don't think so. PLT Scheme was already moving away from R5RS. I think the renaming was to acknowledge that Racket isn't scheme. That said, I believe the have implemented scheme in Racket. I think PG implemented Arc in it too. It also comes with Algol-68 I think.
- megrimlock 16y agoAccording to Wikipedia, the Ship of Theseus problem questions whether an object that has had all of its components replaced is still fundamentally the same object. <pedantry> If each part is replaced in series, and the identity of the object remains the same after each step, then clearly the object remains the same. For humans identity is thus based on recognizing what you have seen before; it acknowledges mutable state. In this case, if you consider the brand as a mutable property of the object, then yes, the identity of PLT-Scheme and Racket are the same. </pedantry>
- TwoBit 16y ago"We've reimplemented the GUI layer, which meant throwing out about 200,000 lines of C++ code that built on Xt, Win32, and Carbon. We've replaced that C++ code with about 30,000 lines of Racket code that builds on Gtk, Win32, Cocoa, Cairo, and Pango." That's not the same thing as saying 200K of C++ equals 30K of Scheme.
- jmaygarden 16y agoRight, they could probably have gotten the same effect by staying with C++ and switching to Qt.
- jfoutz 16y agobut then they'd have 80,000 lines of code of non-racket between the language and the OS's GUI. And they'd still have to build a compatibility layer between existing GUI stuff FFI out to QT. Seems like this way they suffer through the platform specific pain themselves, but the bugs are all in a language they want to program in.
- deleted 16y ago[deleted]
- chc 16y agoOf course not. The languages are unrelated, so no precise number of lines in one is equal to any precise number of lines in the other. It is a pretty impressive space savings nonetheless.
- steve918 16y agoHigh level languages require less boiler plate, news at 11. You could probably replace it with 10k lines or Python or Ruby too, but it would run like shit compared to the C/C++ version, but because this is HN and they are using lisp, this is news.
- mahmud 16y agoDefine "run like shit". Would 1.5x - 3x the C++ speed be acceptable if your code was 70% more compact and proven secure, not to mention a joy to write? Not everyone trades efficiency for reliability and comfort. Some people really get to have their cake and eat it too.
- btmorex 16y agoLet's be realistic here: http://shootout.alioth.debian.org/u64/benchmark.php?test=all&lang=racket&lang2=gpp http://shootout.alioth.debian.org/u64/benchmark.php?test=all... I would characterize the differences vs. C++: 1.) substantially slower in all but one case 2.) almost always uses more memory, sometimes drastically more 3.) marginally more compact
- m0th87 16y agoI don't have any experience with Scheme, but the argument was on whether a GUI written in Scheme would be unacceptably slow. A synthetic benchmark measuring AFAIK mostly number crunching suggests nothing about GUI performance.
- chc 16y agoYou linked to the Alioth Programming Language Game — even they admit it's very flawed for determining much beyond how certain programs implementing certain algorithms perform. The game's highly contrived circumstances are considerably less realistic than the parent's anecdotes or the OP's report of huge space savings with little slowdown. In particular, many of Lisp's code size benefits lie in scaling better than other languages. The Alioth game is possibly a pathological case for the things being measured here.
- agentultra 16y agoWhat I wouldn't give to trade the thousands of lines of C++ code in this legacy app I have to maintain for Racket... can't wait to try the new release. :)
- zandorg 16y agoI replaced about 25,000 lines of C++ into about 9000 lines of Common Lisp. Runs almost as fast, and is incredibly easy to understand and modify.
- DTrejo 16y ago"Racket, not Scheme! 30k of Scheme wouldn't have been nearly as useful." — Shriram Krishnamurthi
- dangero 16y agoWhile I don't doubt racket means less lines of code, if I rewrote one of my older c++ projects in c++, I think I could cut down at least half of the code. Maybe more depending on the project. Rewrites have hindsight that you didn't have the first time.
- randombit 16y agoEspecially when you throw in going from Xt (!) to Cairo/GTK - you could probably save 50% of the line count right there.
- makmanalp 16y agoGah, finally. People would judge racket because of how DrRacket looked. Not anymore.
- brendano 16y agoIsn't this more about how good Cairo and Pango are, rather than C++ vs. Scheme?
- malkia 16y agoThere is problem on Windows Vista x64 Professional: ffi-obj: couldn't get "GetWindowLongPtrW" from "user32.dll" (The specified proce dure could not be found.; errno=127) === context === D:\p\racket\collects\ffi\unsafe.rkt:176:2: get-ffi-obj* D:\p\racket\collects\mred\private\wx\win32\utils.rkt: [running body] D:\p\racket\collects\mred\private\wx\win32\sound.rkt: [traversing imports] D:\p\racket\collects\mred\private\wx\win32\procs.rkt: [traversing imports] D:\p\racket\collects\mred\private\wx\common\cursor.rkt: [traversing imports] D:\p\racket\collects\mred\private\kernel.rkt: [traversing imports] D:\p\racket\collects\mred\private\check.rkt: [traversing imports] D:\p\racket\collects\mred\mred.rkt: [traversing imports] D:\p\racket\collects\mred\main.rkt: [traversing imports] D:\p\racket\collects\racket\gui\base.rkt: [traversing imports] D:\p\racket\collects\drracket\drracket.rkt: [traversing imports] [Exited. Close box or Ctrl-C closes the console.]
- soegaard 16y agoPlease report bugs here: http://bugs.racket-lang.org/ http://bugs.racket-lang.org/ Which version are you using?
- malkia 16y agoThe one from the website - http://pre.racket-lang.org/installers/full-5.0.99.4-bin-i386-win32.exe http://pre.racket-lang.org/installers/full-5.0.99.4-bin-i386... I've got it almost working by replacing GetWindowLongPtrW to GetWindowLongW and SetWindowLongPtrW to SetWindowLongW - you have to search in all .rkt files. I also deleted the precompiled .zo/*.dep files (wasn't really sure whether I needed it).
- soegaard 16y agoThere is a new build at: http://pre.racket-lang.org/installers http://pre.racket-lang.org/installers
- morphir 16y agothis is THE lisp I recommend to people that are curious about lisp