TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Cello: Higher level programming in C

535 点作者 mntmn将近 12 年前

36 条评论

breckinloggins将近 12 年前
I want to make a few observations about this, and why I found it seemingly less &quot;hacky&quot; than other such attempts:<p>- As I said in an earlier comment, &quot;var&quot; is just a typedef&#x27;d &quot;void *&quot;. The downside is that libCello code is essentially untyped, but the upsides are that the C preprocessor is now enough to do the processing needed for the rest of the macros in the language, and that you can still mix regular typed C with libCello code for a &quot;best of both worlds&quot; mix.<p>- Looks pretty, right? What you&#x27;re responding to is not just the nice non-capitalized macros and the $ keyword, but the syntax highlighting in his examples. Fire up a text editor and write you some libCello code without this highlighting and it probably won&#x27;t feel as nice.<p>I&#x27;m extremely interested in the idea of taking the syntax highlighting, formatting, and code completion OUT of these specialized IDEs and plugins and into some kind of standard &quot;bidirectional channel&quot; between a language processor or compiler, its macro system, and the user&#x27;s editor of choice.<p>We should be able to make entire DSLs and specialized syntaxes that not only compile, but are able to provide rich information to the surrounding development environment in a standardized way. I&#x27;m not alone on this. F#&#x27;s Type Providers do exactly that. But imagine being able to control not only the &quot;intellisense&quot;, but also the syntax highlighting, argument&#x2F;return tooltips, documentation, preferred formatting, snippets, etc.<p>And by &quot;surrounding development environment&quot; I mean everything from the command line to vim and emacs all the way to Sublime Text, Eclipse, and Visual Studio. Even github! Why do you have to register a new syntax highlighter on github for a language and hope they turn it on?
评论 #6048037 未加载
评论 #6048484 未加载
评论 #6048682 未加载
评论 #6049126 未加载
评论 #6050028 未加载
jacquesm将近 12 年前
Super stuff this, that&#x27;s a very interesting approach.<p>I spent the better part of the last two years writing a (closed source, sorry) library that does some of this, and some other stuff besides (state machines, events, &#x27;proper&#x27; strings with automatic garbage collection and allocation, message passing).<p>Maintaining static typing was a big pre-requisite for that library, without it too much of value would be lost to offset the gains. It was a very educational project for me, it definitely re-inforced the &#x27;half of common lisp&#x27; meme.<p>To program a piece of software using that library no longer felt like programming in C, every now and then you&#x27;d see a bit of C shine through in the lower level code. The whole thing relied to a ridiculous degree on macro cleverness (something to be avoided, for sure) and other deep knowledge of how C works under the hood to get certain effects, and I found this part of it less than elegant (even if the results were quite a big step up from programming in C).<p>The main justification for doing all this was to straighten out a project that had become bogged down under increasing complexity and a failure to abstract out the common elements. Choosing C for this project was a poor decision but since there was not going to be any budging on that front I tried to make the job work out as good as possible.<p>It&#x27;s quite interesting to see how far you can push C but at the same time you really have to ask yourself if you are on the right road if you find yourself doing things in such a manner.<p>Like Cello, the lib I wrote is a way to force the language to become another language, which always has drawbacks in terms of unintended side effects and long term support.<p>Probably better to switch to a platform that is closer to your problem domain (in this case, such as erlang, clojure or even go), as much as I liked tinkering with C it felt like we were making life harder than it needed to be.
makmanalp将近 12 年前
Slightly related tangent:<p>I&#x27;m looking for standards &#x2F; set of libraries &#x2F; best practices for &quot;modern&quot; C development, but I&#x27;ve yet to find a comprehensive resource.<p>Stuff like typedefing a manual fixed sized int type to be cross-platform compatible, that books don&#x27;t really tell you to do but are important and come up often.<p>I&#x27;d be okay with a small, well written example library too. Does anyone happen to know something like this?<p>edit: Ah, sorry if I misled you, that was just an example of the <i>kind</i> of tips and pointers I was looking for. Or weird bits like the linux kernel list_head. <a href="http://kernelnewbies.org/FAQ/LinkedLists" rel="nofollow">http:&#x2F;&#x2F;kernelnewbies.org&#x2F;FAQ&#x2F;LinkedLists</a> Or common libraries like bstring that make life easy. Or even a single, comprehensive implementation of good data structures, since everyone seems to have their own vector.h and&#x2F;or hash.h that fails to cover much other than their own use case.
评论 #6048325 未加载
评论 #6050342 未加载
评论 #6050983 未加载
评论 #6048271 未加载
评论 #6048674 未加载
评论 #6048438 未加载
评论 #6050273 未加载
mjn将近 12 年前
Wow, this is an impressive amount of high-level feel for relatively little preprocessor code (and a fairly lightweight C library underneath that). Holds together pretty consistently, which is hard to do with syntax extensions built on top of the C preprocessor, vs in languages with more convenient syntax-extension or macro systems.
hugs将近 12 年前
I spent the last hour trying to get the example programs on the front page of the libCello site to compile on OS X (10.8.4). I discovered I was missing some include flags. This is what finally worked:<p>$ gcc -lCello -std=c99 -fnested-functions example.c -o example<p>Hope this helps someone!
breckinloggins将近 12 年前
Note that &quot;var&quot; is a typedef&#x27;d &quot;void *&quot;. This essentially bypasses C&#x27;s typechecker for libCello code. The author admits as such, and maybe that&#x27;s just fine for what you need to do, but you should be aware of it.
评论 #6047915 未加载
评论 #6049717 未加载
dcope将近 12 年前
After looking at the source, this appears to be a great beginners resource of how to build on top of C. The source is very concise and straightforward. I&#x27;m curious to see what will come from this.
评论 #6047905 未加载
评论 #6047853 未加载
评论 #6049130 未加载
ExpiredLink将近 12 年前
People interested in real-world high(er)-level C programming should take a look at this book, &quot;especially the class methodology in Chapter 4&quot;: <a href="http://www.duckware.com/bugfreec/index.html" rel="nofollow">http:&#x2F;&#x2F;www.duckware.com&#x2F;bugfreec&#x2F;index.html</a><p>Side note: this book would certainly be down-voted on r&#x2F;programming but I expect more grown-ups here.
评论 #6049323 未加载
评论 #6050611 未加载
JonFish85将近 12 年前
An interesting experiment, but even as the author states &quot;it&#x27;s a fun experiment&quot;. It makes things easier to read &amp; understand for beginners, maybe, but he even states that it&#x27;s not for beginners. If I have to be a C power user to use it, I imagine I&#x27;d feel more comfortable without it. Just my opinion though.
评论 #6048078 未加载
robododo将近 12 年前
It looks pretty, but I&#x27;m already having nightmares about stepping through this in a debugger.
JoachimSchipper将近 12 年前
Pretty cool, even if I don&#x27;t want to see the compiler warnings. ;-)<p>In the same vein, but more C-like: <a href="http://p99.gforge.inria.fr/p99-html/" rel="nofollow">http:&#x2F;&#x2F;p99.gforge.inria.fr&#x2F;p99-html&#x2F;</a>.
ambrop7将近 12 年前
What is this? It claims to be a (GNU99) C library, but I don&#x27;t see how this can be the case, considering all the non-C constructs in the sample code ($(), try&#x2F;catch, foreach). So it this just a language of its own that is compiled into C?
评论 #6047816 未加载
评论 #6047804 未加载
评论 #6047828 未加载
评论 #6047799 未加载
评论 #6047811 未加载
georgeg将近 12 年前
This is the kind of functionality that D language is really good at. If I were to go beyond the fun bit of this project, i would have a look at D language.
评论 #6048297 未加载
popee将近 12 年前
Chello is nice proof of concept, but personally i&#x27;d like to see only one or two changes to C standard:<p>1. sizeof(function) -&gt; would give user ability to copy functions around.<p>2. maybe new reserved keyword _Func -&gt; function tagged with _Func would indicate that function must be compiled as function object (defined sizeof) and compiler needs to address fact that function may be moved around and used (relative addressing and i guess bunch or others problems that would arise). Only code, nothing to do with ELF or other formats.<p>Another interesting thing to do would be to, somehow, eliminate function pointers with _Func.<p>In any case, user would be responsible for creating environment for that (lambda?) functions, like manually setting mprotect or setting up stack (prologue.h &amp; epilogue.h ???).<p>_Func int example_prototype(int i, int j) {<p><pre><code> return i + j; </code></pre> }<p>And then do something like:<p>example_prototype func0;<p>memcpy(&amp;func0, example_prototype, sizeof(example_prototype));<p>struct prologue_t *p_ptr = &amp;func0;<p>p_ptr-&gt;sp = 0xdeedbeef; &#x2F;&#x2F; Or some address that is used as stack<p>z = func0(5, 6)<p>So, what do you thing how hard would it be to implement something like that?
评论 #6057015 未加载
sovande将近 12 年前
Not thread safe. For instance the exception stack is global.
评论 #6048348 未加载
eonil将近 12 年前
Interesting at first, but lack of static type-check (or notation) voids everything.
Demiurge将近 12 年前
This looks nice. A lightweight macro for Class, that is just a struct with function pointers, and I will use it over c++ :)
sspiff将近 12 年前
The fact that this uses &quot;void *&quot; as a universal type makes me somewhat reluctant to try this out.
jnbiche将近 12 年前
This looks very nice indeed. The main thing that will interfere with usability for me as a non-C guru is the lack of thread support. But I am really grateful for the effort since my &quot;spiritual home&quot; among programming languages is definitely the dynamic languages, yet I appreciate the need and beauty of C in many instances when performance is necessary. libcello&#x27;s apparent optional static typing (the &quot;var&quot;) is really nice -- it&#x27;s one of the wonderful things about using Cython alongside Python.
评论 #6050974 未加载
dubcanada将近 12 年前
So, because I am a nub in this stuff... When it says C library, does that mean anything that works with C (say a gui library for example GTK) will work perfectly fine with this? I would just change the syntax as required and call it good?
评论 #6049219 未加载
评论 #6049006 未加载
guilloche将近 12 年前
It seems interesting but I did not get it. Does it try to add some c++ syntax sugar? Does it have performance advantage over c++ for similar functionality?<p>I am not a fan for C++ syntax, can I still get something from cello?
halayli将近 12 年前
Just use C++11.
dsego将近 12 年前
If there is already new syntax, why not just make a completely new language that compiles to C, like vala or something similar?
ilitirit将近 12 年前
Why would one choose this:<p><pre><code> var int_item = $(Int, 5); </code></pre> over this:<p><pre><code> int int_item = 5; </code></pre> What am I missing?
评论 #6052489 未加载
评论 #6052712 未加载
mogui将近 12 年前
loving it, definitely I was playing with these sort of things these months and eventually I was ending with something similar, but that is far away what I was doing. I think I will contribute to this lib if i can instead of continuing my shit :)
oscargrouch将近 12 年前
i hope this get more and more popular.. in a way that the next natural step would be implementing a special parser for it in GCC and Clang (as some sort of C subset)..<p>totally awesome!
akadien将近 12 年前
Harrumph. Our <a href="http://github.com/redjack/libcork.git" rel="nofollow">http:&#x2F;&#x2F;github.com&#x2F;redjack&#x2F;libcork.git</a> library is better.
评论 #6050496 未加载
评论 #6051385 未加载
评论 #6052008 未加载
deletes将近 12 年前
Does it have inheritance and polymorphism?
评论 #6048714 未加载
评论 #6049260 未加载
brambit将近 12 年前
Use macros?
smegel将近 12 年前
&quot;Constructors&#x2F;Destructors aid memory management&quot;<p>Does it do RAII? Really, calling destructors implicitly on auto variables on scope exit is the main thing missing in C here.
评论 #6052057 未加载
guard-of-terra将近 12 年前
They should neither use C++ keywords nor invent parallel terms (real vs float) in order this to fly.
jlebrech将近 12 年前
Someone build an nginx (openresty?) module with this.
mortdeus将近 12 年前
Eww
claudiug将近 12 年前
create a webframework now like rails&#x2F;django and you will have some marketing :P
cad将近 12 年前
Why, why, why didn&#x27;t I break his legs!
anuraj将近 12 年前
Well - this looks more PHP now - given that PHP interpreter is actually a shell on native C - I think it already achieves this.