23 ms·
Coding in C is like camping. It's fun for a while, but eventually you really miss things like flushing toilets and grocery stores. I like using C, but I get fru
by caseymarquis 7y ago
Coding in C is like camping. It's fun for a while, but eventually you really miss things like flushing toilets and grocery stores. I like using C, but I get frustrated every time I hit a wall trying to build features from other languages. C is a very WET language.
C is basically it for embedded development though. I've gotten so tired of recompiling and waiting to flash a chip with C, that I've started learning ANTLR and making my own language. The idea is to have a language which runs in a VM written in C, and allows you to easily access code which has to be in C. Sort of like uPython, except it can easily be used on any board with a C compiler with a small amount of setup, and C FFI is a first class citizen. Also coroutines masquerading as first class actors with message passing, since I always end up building that in C anyway.
- rumanator 7y ago> Coding in C is like camping. It's fun for a while, but eventually you really miss things like flushing toilets and grocery stores. The only issue I have with C is that there are no good reasons for some of those missing features to be missing. Take, for example, namespaces. Would it be a problem to implement them as, say, implicit prefixes?
- AllanHoustonSt 7y agoWould it be possible to do this without changing how name mangling works?
- frabert 7y agoThere's no name mangling in C, at least not in any ABI I know of.
- saagarjha 7y agoThere’s “mangling” where symbols have an underscore put in from of them. But I think the point is that namespaces functions would need to be mangled and thus be difficult to call.
- weberc2 7y agoAs far as I know, name mangling only exists because linkers don’t have a notion of namespaces. If you fix linkers, then there is no need to mangle.
- maxxk 7y agoAnd also because of function overloading in, say, C++. To link code two functions with the same identifier which differ only in signature (e.g. types of arguments), we need to pass them to linker as two different functions with different identifiers.
- rumanator 7y ago> But I think the point is that namespaces functions would need to be mangled Namespaces don't need to be mangled at all if they are interpreted as symbol prefixes. I'd prefer that, say, namespace foo::bar resolved into foo_bar for all symbols (even that meant risking namespace naming collisions) to not having any support for namespaces in C. In fact, this approach is already used to implement pseudo-namespaces, so that wouldn't be much of a stretch.
- john111 7y agoWhat's the point? How is typing foo::bar better than typing foo_bar? It seems like you want the language to be more complicated for no benefit. Why not use C++ at that point?
- rumanator 7y ago> What's the point? How is typing foo::bar better than typing foo_bar? You're missing the whole point of namespaces. The goal is not to replace foo_bar with foo::bar. The whole point is that within a scope you can type bar instead of foo::bar, or bar instead of foo::baz::qux::bar, because you might have multiple identifiers that might share a name albeit they are expected to be distinct symbols. https://en.wikipedia.org/wiki/Namespace https://en.wikipedia.org/wiki/Namespace
- 7y ago
- a1369209993 7y agoActually, yes: #include <string.h> __prefix__ str; /* in scope: "","str" */ strlen("Hi!"); /* try "strlen",done,ignore "strstrlen" */ len("Bye"); /* no "len",try "strlen",done */ __prefix__(foo_) { void bar(void); } /* "foo_bar" */
- MiroF 7y agoOr something like the std::vector would be nice.
- Impossible 7y agohttps://github.com/nothings/stb/blob/master/stretchy_buffer.h https://github.com/nothings/stb/blob/master/stretchy_buffer.... Although I get you want an official standard library version, or a built in language feature.
- Koshkin 7y agoI think GP’s point was that what you want is called “C++”.
- Gibbon1 7y agoThat's exactly my complaint. I think it's missing things because if you added them in a way compatible with the C way of doing things then you would permanently cleave C from C++. Since C++ is a runaway train at this point detaching is probably a good idea now. Me I want range types like Ada. Real array types. I think I want blocks/coroutines.
- agumonkey 7y ago> Me I want range types like Ada. Real array types. I think I want blocks/coroutines. aka CDC
- diego_moita 7y ago> I've started learning ANTLR and making my own language. > a language which runs in a VM written in C [...] easily be used on any board with a C compiler with a small amount of setup, and C FFI is a first class citizen. Also coroutines Use Lua. It has all of that already.
- greiskul 7y agoYup, the Lua interpreter is written entirely in pure ANSI C. Op should definitely see if solves his problem before implementing his own language. Unless of course he just wants to learn how to implement a language as a project by itself, in which case, have fun :).
- caseymarquis 7y agoI've looked at LUA, and it's possible I missed a flavor, but I have a long list of things I want: -Static types that match C for seamless interop. -No GC -First class actors -Ahead of time declaration/allocation of actors and messages, with automatic async-like passing on a coroutine/actor waiting for an allocation, and automatic disposal of the actor after prolonged allocation failure. -Hot swapping actors from a running system in the field -Over the wire debugging and inspection of a running system in the field AtomVM, an erlang VM for small devices is closer than LUA to what I'm looking for. However, I really want to create an environment made for embedded development, not try to tack a higher level runtime onto something like an ESP32 and have devices drop every 2 months from a memory leak.
- jacquesm 7y agoseamless
- Ericson2314 7y agoJust program an FPGA. You can get all those things with https://clash-lang.org/ https://clash-lang.org/ cause basically what you want is first order FRP and hardware does that natively. (Actor model is junk cause the interesting thing is the data/information flow not the "actors" themselves. FRP puts the focus back where it should be.) You can implement that for embedded systems too, but as there is no obvious best way to implement it (Von Neumann machine is so different) you'll constantly get annoyed if you are the type that likes to use the weakest hardware possible as different implementations have different costs and so you'll always be second-guessing the abstraction.
- gugagore 7y agoThat sounds cool. Does ANTLR help with anything besides parsing your new language? It seems like the substantial effort is making the VM/runtime that the language runs within.
- caseymarquis 7y agoHaven't finished the ANTLR book yet, but that was the goal. I'd much rather define a grammar than hand write a(nother) lexer/parser. It also has some useful tools for debugging and visualizing.
- weberc2 7y agoI love writing C when I haven’t written C in several years. It feels nostalgic and simple and elegant in my mind, and then I remember all of the issues I run into and how none of them have good, clear solutions. Things like writing cross platform code or string manipulation or how often things I swear I understand actually have bizarre edge cases, things I thought were well defined behavior are actually undefined, etc.
- jacquesm 7y agoThe one thing C will teach you quite quickly is that trying to be 'smart' gets punished, harshly.
- turk73 7y agoI don't know what you mean, exactly. I do recall that in 1991, I was the only student in my "Introduction to Programming Using C" 101 class (as a Freshman in college) who could understand pointer arithmetic. That class ended the careers of many aspiring Computer Science majors. I eagerly learned C++ a few years later. I did not understand at the time what shitpile OOP is. I was totally in OO because it was the "industry trend." Someday we'll fully recover from that entire folly.
- weberc2 7y agoI’m not talking about being clever, I’m talking about writing code that meets some baseline standard for security, correctness, and cross platform functionality. The issue with C is that standard, “unsurprising” code often behaves unexpectedly.
- takeda 7y agoI didn't get that impression when I used it, if it does that then most likey your code wasn't so standard or your understanding of the language was incorrect. I personally only got in trouble in C when trying to be too clever.
- 7y ago
- JackRabbitSlim 7y agoWhy not FORTH? It may not have some features out of the box (no type checking - which isn't as bad as it sounds with FORTH) but newer runtimes tend to put those things in and/or are fairly easily implemented yourself. https://en.wikipedia.org/wiki/Forth_(programming_language) https://en.wikipedia.org/wiki/Forth_(programming_language) also, system level REPL is some hardcore nerdity.
- caseymarquis 7y agoFORTH is neat, but I think you need to be too smart to use it. I made a list of other things I want under the peer post about LUA, some of that applies to FORTH.
- JadeNB 7y ago> I made a list of other things I want under the peer post about LUA, some of that applies to FORTH. Incidentally, while Forth comes from the era of ALLCAPS language names, even its creator Chuck Moore calls it Forth: https://web.archive.org/web/20040131054056/http://www.colorforth.com https://web.archive.org/web/20040131054056/http://www.colorf... ; and Lua never was spelled with all caps.
- CharlesW 7y ago> I've gotten so tired of recompiling and waiting to flash a chip with C, that I've started learning ANTLR and making my own language. The idea is to have a language which runs in a VM written in C, and allows you to easily access code which has to be in C. You may want to check out Moddable's XS runtime[1], which is exactly that. It's written in portable C, and "XS in C"[2] makes it easy to interoperate with C code you may write. And even if you decide to roll your own runtime, there's tons to learn from the source code. [1] https://www.moddable.com/faq.php#what-is-xs https://www.moddable.com/faq.php#what-is-xs [2] https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/xs/XS%20in%20C.md https://github.com/Moddable-OpenSource/moddable/blob/public/...
- caseymarquis 7y agoI will definitely check that out. Thanks! I haven't gotten to building the VM yet, and I'm hoping to just use someone else's and then contribute the tools I need to their ecosystem.
- Touche 7y ago> C is basically it for embedded development though. This is the entire reason for me. With the way IoT is blowing up C actually might be gaining market share. I've done my research and things like TinyGo exist, and you can sort-of compile Rust for microcontrollers if you use all of the right crates, but it feels pretty risky to do so.
- retrac 7y agoThere's an old quote, "Greenspun's tenth rule" https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule : "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp."
- turk73 7y agoUnlike LISP, C is still #2 on TIOBE vs. LISP which is #27, aka no place.
- Const-me 7y agoAn old quote indeed. In modern world, any sufficiently complicated C or C++ program embeds a runtime of some higher level language. More often than not, that language is formally specified, well-supported, and fast. Sometimes it’s indeed LISP like in AutoCAD, but more popular choices are JavaScript (all web browsers), LUA (many video games and much more, see Wireshark), Python, VBScript or VBA (older Windows software), .NET runtime (current Windows software and some cross-platform as well, like Unity3D game engine). These days, it’s rarely a custom language runtime, but it still happens, like Matlab.
- deleted 7y ago[deleted]
- d33 7y agoWhich of those is actually formally specified? Also, calling Python or JavaScript any effieicnt sounds a bit unwarranted. Consider any JavaScript desktop application, its power and memory usage... it's a mess.
- anchpop 7y ago> Consider any JavaScript desktop application, its power and memory usage... it's a mess. I'm running VSCode right now with many tabs open and extensions running, and it's using less than 100mb of memory. Doesn't seem so bad to me
- BubRoss 7y agoV looks like it fits this bill even better than lua. It looks like a very useful and well designed language, but it is in an extremely rough state so it might be more worth keeping an eye on.
- linuxlizard 7y ago> Coding in C is like camping. It's fun for a while, but eventually you really miss things like flushing toilets and grocery stores. Bookmarking that comment. Will totally quote that whenever the need arises.
- thoksink 7y agoI started learning C by writing a database, not a way to go. Since the information about database available online is rare.
- linuxlizard 7y agoPasted the quote into work chat and a waggish co-worker immediately came back with, "on the other hand, Python is like camping with a toilet, but that toilet may have a dangerous snake in it, but you won't know until you try it"
- 7thaccount 7y agoForth is tiny, anybody can write their own and it is pretty awesome and interactive.
- agumonkey 7y agoand can be made fortranish fast: http://soton.mpeforth.com/flag/jfar/vol5/no2/article1.pdf http://soton.mpeforth.com/flag/jfar/vol5/no2/article1.pdf (disclaimer, not a recent paper)
- spectramax 7y agoYou can fancy-up your sleeping bag + tent with a huge motorhome/caravan by using C++. Its like you have this house on wheels, but if you just want to take a sleeping bag + tent with you on a trip - you can. Take whatever you need.
- mcguire 7y agoBut then you have a hundred people following you around, yelling that you're doing C++ wrong.
- matheusmoreira 7y agoBesides embedded applications, C is important because it has a simple binary interface. Libraries written in C can be used in any other language. This is not true for higher level languages, whether compiled or virtualized.
- pjmlp 7y agoOnly on OSes written in C, because C ABI is the OS ABI. On Windows any language able to speak COM can use it, regardless what language was used to create the COM component. Same applies to mainframes and their language environments.
- tekknik 7y agoyou can actually call golang from C but you have to copy values over otherwise the go garbage collector will free it while the C side may still be using it.
- deleted 7y ago[deleted]
- MisterTea 7y ago> I like using C, but I get frustrated every time I hit a wall trying to build features from other languages. Well there's your problem. Instead of thinking about your problem and devising a C solution, you resort to pounding the square peg into the round hole. Your problem isn't C, it's your proficiency at it. What's worse, instead of correcting said ignorance your solution is to produce more code using a new language. This only adds to the gross pile of trash that is every language/framework that tries to solve programmer ignorance and laziness with what amounts to wishful thinking. This is why software really sucks nowadays. Everyone wants results without reading the manual or putting in real effort. They want languages with built in hand holding and magic inference. That's not how any of this works. I get it, programming and C sucks because it's so damn tedious. I suck at C too. But I actively study books and similar problems people already solved using the language. Programming is very hard. The best programmers I know are also very good with math and puzzles (e.g. Ken Thompson was a chess geek). They're puzzle solvers. They don't cheat and try to smash or duck tape the pieces together. They thrive on studying strategy meaning reading books, papers, and other people's code. Learn how to solve the puzzles strategically instead of fighting them.
- gugagore 7y ago> That's not how any of this works. That's actually how _all_ of this works. If we required everyone to handle the complexity of everything, we wouldn't be able to make technological progress. Yes, there's the tension (there's always a tension) between having a deep understanding of an underlying technology, and therefore be able to use it better, and trying to get to a point where you can get away with not understanding. But it's undeniably considered a success story in technology if the technology gets to a point where people can use it to basically its full potential, without needing to understand it.
- caseymarquis 7y agoI shouldn't bite... sigh. When writing interrupt service routines for serial communications on an obscure architecture with multiple heaps (one 16 bit addressable and one 32 bit addressable), I could have written 2000 lines of assembly. Instead, I used a system of assembly macros and wrote about 300 lines of that. When writing firmware in a C which lacked decent coroutines, I could have just made a giant while loop and put all of my logic in it. Instead, I wrote a quick implementation of coroutines, a scheduler, and a basic async/await implementation using the C preprocessor. This also saved thousands of lines of boilerplate code. The fact that C has no good method of implementing a generic hashmap has nothing to do with my proficiency in the language. My proficiency in C also has nothing to do with my love of sweet, glorious type inference, or my deep felt appreciation for the conveniences modern IDEs and languages provide. Writing software has never been better! Maybe I'm misinterpreting, but what I'm hearing is: "You don't need to use Vim to get more done, you just need to get better at typing. Not that I know anything about how fast you type." Or... you know, I could just use Vim.
- still_grokking 7y agoCoding in C is like constructing a bomb and and defusing it at the same time. It will explode and kill people eventually. That's a sure thing, no matter how good you are. The only relevant question than is: Have you been still around or did you manage to find some safer workplace far away?
- jacquesm 7y ago> It will explode and kill people eventually It will? Some of the stuff in this thread is really over the top.
- Rebelgecko 7y agoWhat does it mean for a language to be wet?
- milesvp 7y agoFYI, zig is the language that the most impressive embedded programmer I know is currently interested in to use for his embedded work (he does a lot of real time hard deadline things, like audio processing). I don’t know really anything about the language, but his interest in the language is enough to suggest other embedded programmers look into it.
- oscargrouch 7y agoFrom my subjective perspective, Zig, of all the languages, is what feels most the modern successor of C. I think, it even does a better job than C++ which share some of the C syntax. The problem i guess is complexity and productivity. Zig here is a hit while Rust is a miss as much as C++. The question Zig was trying to answer is: Can we have a simple, free and powerful language as C but with a more modern approch? While Rust in its cruzade to be seen as a C++ competitor were not aiming at simplicity and user ergonomics. So my feeling is, Zig is much more compeling as a C substitute than any other language out there, and probably thats the reason why your friend like it more than others.
- pron 7y agoThis is all very subjective but I, for one, agree with every word you wrote.