Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: =?UTF-8?B?Sm9zaHVhIENyYW5tZXIg8J+Qpw==?= Newsgroups: comp.lang.java.programmer Subject: Re: What's the best non-JVM native language to look at? Date: Fri, 17 Jan 2014 15:44:32 -0600 Organization: A noiseless patient Spider Lines: 97 Message-ID: References: <428f8206-d4f7-4fe6-b93c-8f881b498be6@googlegroups.com> <99qdnVXamdWBRErPnZ2dnUVZ8mOdnZ2d@bt.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 17 Jan 2014 21:44:35 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="8b6ddcc38ecbed2f71b30fabadb8aa0b"; logging-data="16471"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19SEz4LCiRx/AlzEPQwGtueEE29GvsTERI=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Thunderbird/27.0 In-Reply-To: Cancel-Lock: sha1:BlNdmhoueLBPTKrMQALMFY9kjjM= Xref: csiph.com comp.lang.java.programmer:27336 On 1/17/2014 12:08 PM, lipska the kat wrote: > On 17/01/14 16:28, Joshua Cranmer 🐧 wrote: >> On 1/16/2014 7:05 AM, lipska the kat wrote: >>> I can't think of a language that isn't ultimately implemented in C. >> >> Zero-cost exception handling cannot be expressed in (ISO) C code (or, at >> the very least, not in a way that a C compiler will faithfully compile >> it--in the situation that would arise, clang and gcc are both extremely >> happy to mangle the code, even at -O0). Well, MSVC has __try/__catch, >> but that's not ISO C. > > I've been reading up on this Zero-cost exception handling thing. > It seems that while there may be no overhead for exception handlers if > no exception is raised, the performance of exception propagation is > poor. Maybe it should be called 'Zero-cost exception handling if no > exception occurs'. It's not impossible though is it, it's a compiler > thing so it *could* be implemented ... if the compiler supported it. > It's not a fundamental shortcoming of the language per-se is it? Zero-cost exception handling simply cannot be expressed in ISO C code. In essence, it requires building external unwind tables, which can be thought of as "if an exception reaches between these two points, jump to that location instead"--which requires some notion of computed goto (more specifically, the ability to take the address of a label). gcc's computed goto extension is not formally specified, but experimentation with both clang and gcc indicate that taking the address of a label and not jumping to it [in the same function] is insufficient to preserve the existence of the code after that block, even when compiling at -O0. In general, C strongly believes that there exists only a single entry point to every function; constructs where this notion doesn't really hold true (exceptions, generators, coroutines, continuations) can't be effectively expressed in C code. >>> If you think about it, any language *other* than C is simply a high(er) >>> level interface to C (ignoring assembler of course). Even C compilers >>> are written in C (go figure :-) >> >> Clang is written in C++. GCC is written in C++ as of 4.8. MSVC is >> written in C++. I'm pretty sure icc is also written in C++. Open64 >> appears to be in C++ as well. Which means that all the C compilers which >> find major use are written in C++, not C. > > According to lots of references on the intertubes the first C++ compiler > was written in something called 'C with classes' which was written in ... C The assertion I was disagreeing with was "C compilers are written in C"--the major C compilers are in fact written in C++. That C++ was once bootstrapped by a compiler written in C doesn't particularly matter--Java was probably bootstrapped by a C++ compiler and Rust was bootstrapped by OCaml. I suspect OCaml, Haskell, and Scheme are likely to be more popular languages than C for bootstrapping, largely because PL people are the ones who like to design new languages, and they prefer the more powerful constructs in those languages for design than C. > I'm sure you can but implementing simple dynamic data structures (Linked > List for example) in C is trivial isn't it ... I've never really been > attracted to C++, don't know why TBHWY, I have a couple of books. Too > busy earning a crust I suppose. But I shouldn't *have* to reimplement simple dynamic data structures. Compare the simple task of reading in a text file in different languages. In Python, I can write this: with open('file.txt') as fd: words = [line.split(' ') for line in fd] In Java: List words = new ArrayList<>(); BufferedReader reader = new BufferedReader(new FileReader("file.txt")); String line; while ((line = reader.readLine()) != null) words.add(line.split(' '); In C++ [after looking up a split on stack overflow]: std::ifstream file("file.txt"); std::vector> words; while (true) { std::string line; std::getline(file, line); if (file.eof()) break; words.push_back(split(line)); } [It's worth noting that the C++ committee is considering adding split to the standard library]. In C... I'm not even going to attempt it. C++'s split was 10 lines of code. C's split is a good 50 lines of code. I'd have to come up with a representation for an ArrayList or LinkedList-equivalent datatype in C, make sure it works, write unbounded file parsing, double-check I'm not leaking memory, etc., just to read in a bloody file. And that's why C is unusable for me: I spend my time trying to debug my implementation instead of debugging my algorithm. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth