
Ooc – a small programming language that compiles to C99 - networked
https://ooc-lang.org/
======
chc4
I'm always slightly confused when languages target C instead of compiling
themselves. Nim, for example. Is it really that much easier to deal with all
the idiosyncrasies of C for a backend, and have to hope that the compiler will
cleanup the mass of basic code blocks you emit, than emit LLVM bytecode or
assembly? Not even having to use the LLVM C bindings, you can just emit the
bytecode directives to a file and call the toolchain itself.

Is the idea that you can compile you base code once, and then work on the
emitted C to extend the project?

~~~
camgunz
I've heard portability arguments; C is far more portable than LLVM. But I'm
guessing more people know C than LLVM IR or 4 assembly languages, so C is an
easier target.

EDIT: oh, also wildly easy interoperability with existing C/C++ code (so long
as the C++ code provides a C interface).

~~~
dom96
Compiling down to C also makes wrapping C++ libraries much easier. Because
when you compile down to C, it's not that much of a stretch to also allow
compilation to C++. You can then make wrapping C++ code much easier in the
language.

Nim is one language that I know of which takes advantage of that. Here is one
example of a pretty large wrapper around a C++ library
[https://github.com/3dicc/Urhonimo](https://github.com/3dicc/Urhonimo), and
here is the documentation for this feature [http://nim-
lang.org/docs/manual.html#implementation-specific...](http://nim-
lang.org/docs/manual.html#implementation-specific-pragmas-importcpp-pragma)

------
zaius
This is a really interesting idea. I'm surprised this is the first language
I've heard of that targets C. C's major strength is portability, but that
means change is slow. When browsers stagnated, coffeescript filled the void,
which in turn influenced new versions of javascript.

A certain subset of C++ seems to solve a lot of peoples' problems with C, but
it also seems there's no consensus on what that subset is. So people stick
with C because at least the rules are defined. Compile-to-C languages like
this could have all the benefit of switching to C++ without the downsides

~~~
jrapdx3
Not a new idea at all, many compilers for different languages output C as one
option anyway[0].

Among languages I've enjoyed using and achieving high productivity is CHICKEN
Scheme[1]. The compiler defaults to emitting C, though usually the C code is
immediately compiled into binary object or executable form. CHICKEN also
integrates very well with C as embedded in a C application, using C libraries
or writing C directly in "foreign-lambda*" expressions.

[0] [http://stackoverflow.com/questions/6498850/programming-
langu...](http://stackoverflow.com/questions/6498850/programming-languages-
that-compile-into-c-c-source) [1] [http://call-cc.org](http://call-cc.org)

~~~
agumonkey
Since you mention CHICKEN, the "Lisp in small pieces" book although describe
such a procedure.

------
DaGardner
Has anyone noticed this awesome tutorial on the site? Just plain awesome!

~~~
haylem
Thanks for pointing it out. When I reached the homepage late last night,
honestly I wasn't going to give it much thought.

The code snippet seemed uninteresting and to lack anything original, the pitch
wasn't really selling much, and to top it off there were some text blurbs that
seemed unfinished.

Then I saw your comment and read the tutorial. This was actually a pretty
interesting read, even without actually following along in a console.

I find it assumes a bit too much so I don't think a total beginner would like
it, but for someone used to toying around with new languages it's very well
presented I think.

------
tankfeeder
[http://nim-lang.org/](http://nim-lang.org/)

------
jernfrost
How good does the produced C code look though? I mean if you were on a project
which required C code and you used Ooc would your co-workers immediately barf
if they saw the C code you committed to the repository?

I think these sort of tools are interesting because many companies are stuck
with some ancient language hurting productivity, but being able to use tools
like this one can circumvent some of the problems, if only for new code as
existing code will have to be maintained in C.

~~~
loup-vaillant
> _if you were on a project which required C code and you used Ooc would your
> co-workers immediately barf if they saw the C code you committed to the
> repository?_

Commiting generated code, are you crazy? I don't care how pretty it looks, if
it's not source code, it doesn't belong to source control.

If you still want to put generated C dode in the repository, you can, but the
second you type `push` command is the second your C code becomes _source_
code. Treat it as such.

Or, just put Ooc code into the repository. _That_ is the source code after
all.

~~~
chei0aiV
Web developers appear to disagree with you, there is Grunt-generated JS and
minified JS committed to repositories all over github.

~~~
loup-vaillant
Seriously what's the point? Hopefully their repositories also have the genuine
source code? I'm not interested in reverse engineering.

~~~
chei0aiV
I haven't tried to find out why people do that and find it baffling, but I
guess they don't trust Grunt or their minifiers and want to compare the output
of different versions. The repos I have seen also have the genuine source
code.

------
akkartik
Previously:
[https://news.ycombinator.com/item?id=882864](https://news.ycombinator.com/item?id=882864)
[https://news.ycombinator.com/item?id=1508943](https://news.ycombinator.com/item?id=1508943)

