

Ditching 200K of C++ for 30K of Scheme - swannodette
http://blog.racket-lang.org/2010/12/racket-version-5.html

======
futuremint
I 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
For other readers: PLT Scheme has become Racket (ship of theseus problem)

~~~
futuremint
Yeah, 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
I 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.

------
jerf
"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
It 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>

I've used this successfully.

------
TwoBit
"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
Right, they could probably have gotten the same effect by staying with C++ and
switching to Qt.

~~~
jfoutz
but 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.

------
DTrejo
"Racket, not Scheme! 30k of Scheme wouldn't have been nearly as useful." —
Shriram Krishnamurthi

------
dangero
While 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
Especially when you throw in going from Xt (!) to Cairo/GTK - you could
probably save 50% of the line count right there.

------
zandorg
I 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.

------
malkia
There 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
Please report bugs here: <http://bugs.racket-lang.org/> Which version are you
using?

~~~
malkia
The one from the website - [http://pre.racket-
lang.org/installers/full-5.0.99.4-bin-i386...](http://pre.racket-
lang.org/installers/full-5.0.99.4-bin-i386-win32.exe)

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
There is a new build at: <http://pre.racket-lang.org/installers>

------
makmanalp
Gah, finally. People would judge racket because of how DrRacket looked. Not
anymore.

~~~
morphir
does it look any different?

~~~
makmanalp
It morphs into the local GUI appearance.

~~~
morphir
a before and after picture comparison would go a far way, since I'm on osx, I
cant see much difference.

------
brendano
Isn't this more about how good Cairo and Pango are, rather than C++ vs.
Scheme?

------
agentultra
What 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.
:)

------
morphir
this is THE lisp I recommend to people that are curious about lisp

------
steve918
High 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
Define "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.

~~~
mynameishere
_Define "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?_

No...? Is there another acceptable answer for this? In which cases is such an
"upgrade" slowdown acceptable to the customer?

~~~
saikat
In the case that your app isn't CPU-bound, which is many cases.

[EDIT: Changed most to many. But I think arguments about whether or not speed
matters are silly in the general case. Arguments about tradeoffs are always
going to be so specific to your app that a general argument is fairly
meaningless.]

~~~
KaeseEs
Most cases for whom? There are plenty of fields in which being cpu-bound is
the norm rather than the exception. There are a whole load of assumptions that
go into any general advice like this, consider making fewer of them today!

~~~
chc
That's like objecting to the statement "Most people have two arms, two legs
and one head" by replying "For whom? There are plenty of demographics, such as
amputees, where having a different number of arms or legs is the norm!" The
fact that unusual things are normal for some subset defined by those
characteristics is tautological. It doesn't make the general statement false.

