Since nobody brought it up yet: I think the ATS language is a very good candidate for a better C! Especially since you enjoy Haskell and thus functional programming with strong types. Note that ATS seems to be specifically designed for systems programming and hard real-time applications as most of it can do without garbage collection.
If you check the shootout you will find that performance is basically on par with C. I think this is quite impressive since modern c compilers have years and years and years of optimization work behind them while ATS is basically developed by one guy. -- while other languages providing similar safety features usually introduce overhead ATS ensures things entirely at compile time and thus yields very similar performance characteristics as C.
To quote the website:
What is ATS?
ATS is a statically typed programming language that unifies implementation with formal specification. It is equipped with a highly expressive type system rooted in the framework Applied Type System, which gives the language its name. In particular, both dependent types and linear types are available in ATS. The current implementation of ATS (ATS/Anairiats) is written in ATS itself. It can be as efficient as C/C++ (see The Computer Language Benchmarks Game for concrete evidence) and supports a variety of programming paradigms that include:
Functional programming. The core of ATS is a functional language based on eager (aka. call-by-value) evaluation, which can also accommodate lazy (aka. call-by-need) evaluation. The availability of linear types in ATS often makes functional programs written in it run not only with surprisingly high efficiency (when compared to C) but also with surprisingly small (memory) footprint (when compared to C as well).
Imperative programming. The novel and unique approach to imperative programming in ATS is firmly rooted in the paradigm of programming with theorem-proving. The type system of ATS allows many features considered dangerous in other languages (e.g., explicit pointer arithmetic and explicit memory allocation/deallocation) to be safely supported in ATS, making ATS a viable programming language for low-level systems programming.
Concurrent programming. ATS, equipped with a multicore-safe implementation of garbage collection, can support multithreaded programming through the use of pthreads. The availability of linear types for tracking and safely manipulating resources provides an effective means to constructing reliable programs that can take advantage of multicore architectures.
Modular programming. The module system of ATS is largely infuenced by that of Modula-3, which is both simple and general as well as effective in supporting large scale programming.
In addition, ATS contains a subsystem ATS/LF that supports a form of (interactive) theorem-proving, where proofs are constructed as total functions. With this component, ATS advocates a programmer-centric approach to program verification that combines programming with theorem-proving in a syntactically intertwined manner. Furthermore, this component can serve as a logical framework for encoding deduction systems and their (meta-)properties.
Unlike some other suggestions, (Go, Nimrod, D, ...) Rust can directly compete with C and C++ because it has manual memory management and does not require garbage collection (see [1]).
What sets Rust apart is that it has safe manual memory management. (The link is to pc walton's blog, one of Rusts main contributors and generally worth a read ;) Among other things, this means it fixes the billion dollar mistake of nullpointers. Many of the other languages suggested here either require garbage collection (Go) or have garbage collection turned on by default and do not provide facilities for safe manual memory management beyond what C++ provides (Nimrod, D).
While Rust has an imperative heart, it does borrow a lot of nice things from functional languages, for example sum types aka tagged unions. It is also really concerned with being a safe and performance oriented language.
[1] Right now there are two main pointer types owned pointers (like std::unique_ptr in C++ but with better support from the typechecker) and managed pointers. As the name suggests the latter do require task-local garbage collection, but there are thoughts to remove them from the language and only provide them as a library.
EDITED to reflect @ReneSacs comment: Garbage collection is not required in D and Nimrod.
I don't know much about Haskell, but if you want a strong type system, take a look at Ada. It is heavily used in embedded systems for aerospace applications. The SIGADA moto is "In strong typing we trust." It won't be of much use, however, if you have to do Windows/Linux type device drivers.
A few reasons it is not so popular:
verbose syntax -- designed to be read, not written
compilers were historically expensive
the relationship to DOD and design committees, which programmers seem to knock
I think the truth is that most programmers don't like strong type systems.
Nim(以前的 Nimrod)拥有强大的类型系统,包含概念和简单的泛型。它还具有带有模板和宏的广泛编译时机制。它还具有简单的 C FFI 以及您期望从系统编程语言获得的所有低级功能,因此您可以编写您自己的例如,内核。
目前它编译为 C,因此您可以在任何运行 GCC 的地方使用它。如果您只想使用 Nim 作为更好的 C,您可以通过 --os:standalone 编译器开关来实现,它为您提供了一个基本的标准库,与操作系统无关。
例如,要编译为 AVR 微控制器,您可以使用:
nim c --cpu:avr --os:standalone --deadCodeElim:on --genScript x.nim
Nim 有一个软实时 GC,您可以在其中指定它的运行时间以及最大暂停时间(以微秒为单位)。如果实在无力承担GC,可以完全禁用它(--gc:none编译器开关),只使用像C那样的手动内存管理,丢失大部分标准库,但仍然保留更加理智和强大的类型系统。
此外,标记指针是一项计划中的功能,例如,它可以确保您不会将内核级指针与用户级指针混合在一起。
Nim (former Nimrod) has a powerful type system, with concepts and easy generics. It also features extensive compile time mechanisms with templates and macros. It also has easy C FFI and all the low level features that you expect from a system programming language, so you can write your own kernel, for example.
Currently it compiles to C, so you can use it everywhere GCC runs, for example. If you only want to use Nim as better C, you can do it via the --os:standalone compiler switch, that gives you a bare bones standard library, with no OS ties.
For example, to compile to an AVR micro-controller you can use:
nim c --cpu:avr --os:standalone --deadCodeElim:on --genScript x.nim
Nim has a soft real-time GC where you can specify when it runs and the max pause time in microseconds. If you really can't afford the GC, you can disable it completely (--gc:none compiler switch) and use only manual memory management like C, losing most of the standard library, but still retaining the much saner and powerful type system.
Also, tagged pointers are a planned feature, that ensure you don't mix kernel level pointers with user level pointers, for example.
D 可能会提供您想要的东西。它具有非常丰富的类型系统,但如果需要,您仍然可以控制内存布局。它有像 C 一样不受限制的指针。它是垃圾收集器,但您不会被迫使用垃圾收集器,并且如果您确实愿意,可以编写自己的内存管理代码。
但是,我不确定您可以在多大程度上将类型丰富性与您想要使用的低级方法混合在一起。
如果您找到适合您需求的产品,请告诉我们。
D might offer what you want. It has a very rich type system, but you can still control memory layout if you need to. It has unrestricted pointers like C. It’s garbage collected, but you aren’t forced to use the garbage collector and you can write your own memory management code if you really want.
However, I’m not sure to what extent you can mix the type richness with the low-level approach you want to use.
Let us know if you find something that suits your needs.
我不确定 Cyclone 处于什么状态,但这为标准 C 提供了更多安全性。D 在某种程度上也可以被认为是“更好的 C”,但它的它的裂脑在标准库中的地位不是很清楚。
我选择的“更好的 C”语言是 OOC。虽然还很年轻,但是很有趣。它为您提供了 OO,但没有 C++ 的杀手级复杂性。它使您可以轻松访问 C 接口(您可以“覆盖”C 结构并在调用外部库时正常使用它们/以这种方式控制内存布局)。它默认使用 GC,但如果您确实不需要它,可以将其关闭(但这意味着您不能再使用标准库集合而不会泄漏)。
I'm not sure what state Cyclone is in, but that provided more safety for standard C. D can be also considered a "better C" to some extent, but its status is not very clear with its split-brain in standard library.
My language of choice as a "better C" is OOC. It's still young, but it's quite interesting. It gives you the OO without C++'s killer complexity. It gives you easy access to C interfaces (you can "cover" C structs and use them normally when calling external libraries / control the memory layout this way). It uses GC by default, but you can turn it off if you really don't want it (but that means you cannot use the standard library collections anymore without leaking).
The other comment mentioned Ada which I forgot about, but that reminded me: there's Oberon, which is supposed to be a safe(-er) language, but that also contains garbage collection mechanisms.
You might also want to look at BitC. It’s a serious language and not a toy, but it isn’t ready yet and probably won’t be ready in time to be of any use to you.
Nonetheless, a specific design goal of BitC is to support low-level development in conjunction with a Haskell-style type system. It was originally designed to support development of the Coyotos microkernel. I think that Coyotos was killed off, but BitC is still apparently being developed.
发布评论
评论(9)
由于还没有人提出:我认为 ATS 语言 是一个非常好的候选者为了更好的C!特别是因为您喜欢 Haskell 以及具有强类型的函数式编程。请注意,ATS 似乎是专门为系统编程和硬实时应用程序设计的,因为大多数应用程序无需垃圾收集即可完成。
如果您检查点球大战你会发现性能基本上与 C 相当。我认为这令人印象深刻
因为现代 C 编译器背后有多年的优化工作,而 ATS 基本上是由一个人开发的。- - 而提供类似安全功能的其他语言通常会引入开销,ATS 完全在编译时确保一切,从而产生与 C 非常相似的性能特征。引用该网站:
Since nobody brought it up yet: I think the ATS language is a very good candidate for a better C! Especially since you enjoy Haskell and thus functional programming with strong types. Note that ATS seems to be specifically designed for systems programming and hard real-time applications as most of it can do without garbage collection.
If you check the shootout you will find that performance is basically on par with C. I think this is quite impressive
since modern c compilers have years and years and years of optimization work behind them while ATS is basically developed by one guy.-- while other languages providing similar safety features usually introduce overhead ATS ensures things entirely at compile time and thus yields very similar performance characteristics as C.To quote the website:
Nimrod 或 瓦拉语言?
What about Nimrod or Vala languages ?
Rust
更好的 C 语言的另一个(真正的)候选者是 Rust 编程语言。
与其他一些建议不同,(Go、Nimrod、D...)Rust 可以直接与 C 和 C++ 竞争,因为它具有手动内存管理并且不需要垃圾回收(参见 [1])。Rust 的与众不同之处在于它具有安全的手动内存管理。 (该链接是 pc walton 的博客,他是 Rust 的主要贡献者之一,通常值得一读;)除此之外,这意味着它修复了 空指针的十亿美元错误。这里建议的许多其他语言要么需要垃圾收集 (Go),要么默认打开垃圾收集,并且不提供超出 C++ 提供的安全手动内存管理的设施(Nimrod、D)。
虽然 Rust 有一颗命令式的心,但它确实从函数式语言中借鉴了很多好东西,例如求和类型,又称为标记联合。它还真正关心成为一种安全且面向性能的语言。
[1] 现在有两种主要的指针类型:自有指针(如 C++ 中的 std::unique_ptr,但类型检查器有更好的支持)和托管指针。顾名思义,后者确实需要任务本地垃圾收集,但是 有想法将它们从语言中删除并仅将它们作为库提供。
编辑以反映 @ReneSacs 评论:D 和 Nimrod 中不需要垃圾收集。
Rust
Another (real) candidate for a better C is The Rust Programming Language.
Unlike some other suggestions, (Go, Nimrod, D, ...) Rust can directly compete with C and C++ because it has manual memory management and does not require garbage collection (see [1]).What sets Rust apart is that it has safe manual memory management. (The link is to pc walton's blog, one of Rusts main contributors and generally worth a read ;) Among other things, this means it fixes the billion dollar mistake of nullpointers. Many of the other languages suggested here either require garbage collection (Go) or have garbage collection turned on by default and do not provide facilities for safe manual memory management beyond what C++ provides (Nimrod, D).
While Rust has an imperative heart, it does borrow a lot of nice things from functional languages, for example sum types aka tagged unions. It is also really concerned with being a safe and performance oriented language.
[1] Right now there are two main pointer types owned pointers (like std::unique_ptr in C++ but with better support from the typechecker) and managed pointers. As the name suggests the latter do require task-local garbage collection, but there are thoughts to remove them from the language and only provide them as a library.
EDITED to reflect @ReneSacs comment: Garbage collection is not required in D and Nimrod.
我对 Haskell 不太了解,但如果你想要一个强大的类型系统,请看看 Ada。它大量用于航空航天应用的嵌入式系统。 SIGADA moto 是“我们信任强类型”。但是,如果您必须执行 Windows/Linux 类型的设备驱动程序,那么它就没有多大用处。
它不那么受欢迎的几个原因:
我认为事实是大多数程序员不喜欢强类型系统。
I don't know much about Haskell, but if you want a strong type system, take a look at Ada. It is heavily used in embedded systems for aerospace applications. The SIGADA moto is "In strong typing we trust." It won't be of much use, however, if you have to do Windows/Linux type device drivers.
A few reasons it is not so popular:
I think the truth is that most programmers don't like strong type systems.
Nim(以前的 Nimrod)拥有强大的类型系统,包含概念和简单的泛型。它还具有带有模板和宏的广泛编译时机制。它还具有简单的 C FFI 以及您期望从系统编程语言获得的所有低级功能,因此您可以编写您自己的例如,内核。
目前它编译为 C,因此您可以在任何运行 GCC 的地方使用它。如果您只想使用 Nim 作为更好的 C,您可以通过
--os:standalone
编译器开关来实现,它为您提供了一个基本的标准库,与操作系统无关。例如,要编译为 AVR 微控制器,您可以使用:
Nim 有一个软实时 GC,您可以在其中指定它的运行时间以及最大暂停时间(以微秒为单位)。如果实在无力承担GC,可以完全禁用它(
--gc:none
编译器开关),只使用像C那样的手动内存管理,丢失大部分标准库,但仍然保留更加理智和强大的类型系统。此外,标记指针是一项计划中的功能,例如,它可以确保您不会将内核级指针与用户级指针混合在一起。
Nim (former Nimrod) has a powerful type system, with concepts and easy generics. It also features extensive compile time mechanisms with templates and macros. It also has easy C FFI and all the low level features that you expect from a system programming language, so you can write your own kernel, for example.
Currently it compiles to C, so you can use it everywhere GCC runs, for example. If you only want to use Nim as better C, you can do it via the
--os:standalone
compiler switch, that gives you a bare bones standard library, with no OS ties.For example, to compile to an AVR micro-controller you can use:
Nim has a soft real-time GC where you can specify when it runs and the max pause time in microseconds. If you really can't afford the GC, you can disable it completely (
--gc:none
compiler switch) and use only manual memory management like C, losing most of the standard library, but still retaining the much saner and powerful type system.Also, tagged pointers are a planned feature, that ensure you don't mix kernel level pointers with user level pointers, for example.
D 可能会提供您想要的东西。它具有非常丰富的类型系统,但如果需要,您仍然可以控制内存布局。它有像 C 一样不受限制的指针。它是垃圾收集器,但您不会被迫使用垃圾收集器,并且如果您确实愿意,可以编写自己的内存管理代码。
但是,我不确定您可以在多大程度上将类型丰富性与您想要使用的低级方法混合在一起。
如果您找到适合您需求的产品,请告诉我们。
D might offer what you want. It has a very rich type system, but you can still control memory layout if you need to. It has unrestricted pointers like C. It’s garbage collected, but you aren’t forced to use the garbage collector and you can write your own memory management code if you really want.
However, I’m not sure to what extent you can mix the type richness with the low-level approach you want to use.
Let us know if you find something that suits your needs.
我不确定
Cyclone
处于什么状态,但这为标准 C 提供了更多安全性。D
在某种程度上也可以被认为是“更好的 C”,但它的它的裂脑在标准库中的地位不是很清楚。我选择的“更好的 C”语言是 OOC。虽然还很年轻,但是很有趣。它为您提供了 OO,但没有 C++ 的杀手级复杂性。它使您可以轻松访问 C 接口(您可以“覆盖”C 结构并在调用外部库时正常使用它们/以这种方式控制内存布局)。它默认使用 GC,但如果您确实不需要它,可以将其关闭(但这意味着您不能再使用标准库集合而不会泄漏)。
另一条评论提到了 Ada,我忘记了,但这提醒了我:有
Oberon
,它应该是一种安全的(呃)语言,但也包含垃圾收集机制。I'm not sure what state
Cyclone
is in, but that provided more safety for standard C.D
can be also considered a "better C" to some extent, but its status is not very clear with its split-brain in standard library.My language of choice as a "better C" is OOC. It's still young, but it's quite interesting. It gives you the OO without
C++
's killer complexity. It gives you easy access to C interfaces (you can "cover" C structs and use them normally when calling external libraries / control the memory layout this way). It uses GC by default, but you can turn it off if you really don't want it (but that means you cannot use the standard library collections anymore without leaking).The other comment mentioned Ada which I forgot about, but that reminded me: there's
Oberon
, which is supposed to be a safe(-er) language, but that also contains garbage collection mechanisms.您可能还想查看BitC。它是一门严肃的语言,而不是一个玩具,但它还没有准备好,并且可能不会及时准备好对您有任何用处。
尽管如此,BitC 的一个具体设计目标是支持与 Haskell 风格的类型系统结合的低级开发。它最初是为了支持 Coyotos 微内核的开发而设计的。我认为 Coyotos 已经被消灭了,但 BitC 显然仍在开发中。
You might also want to look at BitC. It’s a serious language and not a toy, but it isn’t ready yet and probably won’t be ready in time to be of any use to you.
Nonetheless, a specific design goal of BitC is to support low-level development in conjunction with a Haskell-style type system. It was originally designed to support development of the Coyotos microkernel. I think that Coyotos was killed off, but BitC is still apparently being developed.
克服这种态度。只需使用C++。您可以从用 C++ 编写 C 语言开始,然后逐渐转向更好的风格。
Get over this attitude. Just use C++. You can start with coding C in C++ and keep gradually moving to better style.