programming language Hare

  • Thread starter Thread starter Deleted member 70435
  • Start date Start date
D

Deleted member 70435

Guest
Drew DeVault, author of the Sway email client Aerc co-development SourceHut , introduced programming language Hare , which he and his team have been working on for the past two and a half years. Hare is touted as a systems programming similar to C but simpler than C. Of the key design principles of Hare, an orientation towards simplification and complete trust in the actions of the programmer (do exactly what is indicated, without initiative and implicit behavior), with auxiliary tools for identifying typical errors and problems, is declared.

The source code for the compiler and toolkit is distributed under the GPLv3 license, and the standard library code under the MPL (Mozilla Public License). The first public release announced support for Linux and FreeBSD operating systems on x86_64, aarch64, and riscv64 platforms, as well as stand-alone use to run on top of hardware without an operating system. The plans mention support for NetBSD, OpenBSD, Illumos, Haiku and Plan 9 operating systems and ppc64le, i686 and arm32 platforms.

The language uses manual memory management and a static type system, in which each variable must be explicitly assigned a specific type. A minimum runtime is attached to run the application. The language is optimized for low-level tasks such as developing operating systems, compilers, network applications, and system utilities that require maximum performance and full control over execution.

A standard library of functions , providing access to the basic interfaces of the operating system, typical algorithms and implementations of protocols and formats. The library covers areas such as I/O, file manipulation, regular expressions, encryption, networking, time and date operations, access to generic Unix primitives (such as poll, fnmatch, and glob), parsing, and type checking. Separately, bindings are provided to access OpenGL , SDL2 and libui features .

are mentioned as examples of projects written in Hare language Helios password manager Himitsu , raytracing ray tracing system bittorrent encryption program, box daemon btqd , scheduled (analogous to cron system), toothbrush (client and server for finger protocol) Of the plans for the future, the stabilization of the language specification and the composition of the standard library, the implementation of support for missing platforms and architectures, the addition of library functions to support TLS 1.2 and 1.3 are noted.
Hare code example:
Code:
   use crypto::sha256;
   use encoding::hex;
   use fmt;
   use hash;
   use io;
   use os;

   export fn main() void = {
    const hash = sha256::sha256();
    const file = os::open("main.ha")!;
    defer io::close(file);
    io::copy(&hash, file)!;

    let sum: [sha256::SIZE]u8 = [0...];
    hash::sum(&hash, sum);
    hex::encode(os::stdout, sum)!;
    fmt::println()!;




    const greetings = [
        "Hello, world!",
        "¡Hola Mundo!",
        "Γειά σου Κόσμε!",
        "Привет, мир!",
        "こんにちは世界!",
    ];
    for (let i = 0z; i < len(greetings); i += 1) {
        fmt::println(greetings[i])!;
    };




    let x: *int = alloc(42);
    fmt::printfln(" x: {}", x)!;
    fmt::printfln("*x: {}", *x)!;
    free(x);

    const file = os::open(os::args[1])!;
    defer io::close(file)!;

    let buffer: *[65535]u8 = alloc([0...]);
    defer free(buffer);

    const n = io::read(file, buffer)! as size;
    io::write(os::stdout, buffer[..n])!;

   };

   fn sort(items: []int) void = {
      ...
   };

   @test fn sort() void = {
    let items = [5, 4, 3, 2, 1];
    sort(items);
    for (let i = 1z; i < len(items); i += 1) {
        assert(items[i - 1] <= items[i], "list is unsorted");
    };
   };
 
Good that people try new stuff. It's readable. One sidenote the name,

 
Is it better than Rust or Go?
without knowing hare: it all depends on your use-case. However, in general I do not see it being better than both those large backed and awesome programming languages/environments. From the description its more targeting the rust space, however, the rust community is big and really awesome, and I cannot imagine hare being a safer language than rust
 
Apologies to everyone. My post about Rust/Go was a bit sarcastic, tongue in cheek; simply because there have been a number of threads about different languages that get, shall we say, a bit religious.
Languages are just a tool, like all tools, pick the one that is the best for your needs.
A lot of the benefits of the latest new and improved languages are the same that have been touted for others in the past.
Anyone remember when Ada was the best thing since presliced bread?
 
A bit of humor makes us smile in our sometimes dull day.
I used to use ada, until i needed object orientation and ada gave complexities & memory leakage.
I.e. there is always a field where a certain tool no longer becomes useful but becomes a burden.
 
A bit of humor makes us smile in our sometimes dull day.
I used to use ada, until i needed object orientation and ada gave complexities & memory leakage.
I.e. there is always a field where a certain tool no longer becomes useful but becomes a burden.
when we think about the past we found some ridiculous things for but it was something so simple to do, today I draw conclusions about it.
 
What is the thing with projects' ecosystem? Don't tell me they plan on having a closed ecosystem, that's nonsense. Where is the support for linking C symbols in, I can't find it anywhere.
 
Hare could better serve developers if it was a superset of C. I.e 100% compatible with existing C libraries. Then in new codebases developers can start taking advantage of unique things it provides such as defer.

As it stands, people will need to waste time writing bindings to go between C <-> Hare. Same issue with all non-C based languages.
 
Yeah no thanks. There's a reason why people do automatic memory management now. If people are going to move off C, why bother wasting all that time and effort going sideways.
 
There's a reason why people do automatic memory management now.
Garbage collection/automatic memory management is easier, but a lot of faith has to be placed on the GC itself. Is the algorithm correct by default? Can it be tuned for specific workloads if needed? One also needs to make sure that running the GC doesn't starve the system of doing real work.

Some still has to write the code to implement it and could make a mistake and wind up with a memory leak. Java VM has gone through periods where memory leaks happened and got fixed in a later release.
 
Hare could better serve developers if it was a superset of C. I.e 100% compatible with existing C libraries. Then in new codebases developers can start taking advantage of unique things it provides such as defer.

As it stands, people will need to waste time writing bindings to go between C <-> Hare. Same issue with all non-C based languages.

Can you link me to some example on binding pls?

All I see in their extended support libraries is that everything has been reimplemented natively.

The thing is the lang will take off to nowhere unless it has a good C interlinking system. All the usability is in the billions of libs not libc/C spec itself.

Yeah no thanks. There's a reason why people do automatic memory management now. If people are going to move off C, why bother wasting all that time and effort going sideways.

Memory management is the #1 thing of why people use C in the first place.

The problem for C programmer is the lack of tagged union. The problem for C programmer is the lack of a powerful macro system. Lack of namespaces. Painful string API. Everything C programmers improvise now is for the next C to handle better.
 
Memory management is the #1 thing of why people use C in the first place.
Yeah, and people looking to move off of C are looking towards automatic. Linux kernel accepts Rust. Are people really looking to rewrite manual memory managed code with a new manual memory managed language and deal with all the interop?
 
After years of programming in C/C++, counting malloc/free or new/delete, I must admit to anxiety in languages with automatic memory management. I can see the allocations but not the deallocations and I have a hard time placing my memory in the hands of others. But I do appreciate the simplicity it.
 
"People looking to move off C" doesn't concern me or any other C programmer.
I'm unable to take this as an argument, sorry.

There is automatic memory management in C, it's called making your own arena if you need it.
 
Can you link me to some example on binding pls?
It looks like the language isn't well known enough yet to have any bindings for things. I am sure this will change but no doubt they will come up with an unfortunate concept of a "language based package manager" such as NPM, crates.io and PIP just to wrangle this mess of additional bindings dependencies.
The thing is the lang will take off to nowhere unless it has a good C interlinking system. All the usability is in the billions of libs not libc/C spec itself.
Not the libc but certainly C libraries is where functionality generally comes from. If the language can consume these natively (i.e not needing FFI, JNI, etc and thus bindings) then they might be on to something. So far only C, C++ and Objective-C has managed this.

I am probably sounding negative about Hare but I *really* hope they do manage to find a cool solution to accessing existing C code. Looking through the language itself I actually really like it. But unfortunately functionality from C libraries does take a very high priority to language preference.
 
But unfortunately functionality from C libraries does take a very high priority to language preference.
I agree, but what is/are the alternatives?
Rewrite the functionality in language native libraries? Lot of testing there to ensure correct behavior.
Provide similar functionality in language native libraries so one doesn't have to link against C libs? Again, more testing, you wind up with more effort to port existing C/C++ code.
I don't know what is better, but I completely agree that ability to natively link against C libs would help.
 
I agree, but what is/are the alternatives?
It is a tricky one. If I reflect upon how I use C++, even though I can use C libraries directly, I tend to wrap them into simple RAII objects. It is an OK compromise between rapid development and safety.

So potentially if a new language like Hare did have a simple C compiler bolted onto it which you can activate via inline C (similar to inline Assembly in C compilers).

This has proven to be quite effective with Emscripten (C/C++ -> ASM.js/WebAssembly transpiler). You can inline Javascript and does tend to eliminate the need for bindings.
 
  • Like
Reactions: mer
"People looking to move off C" doesn't concern me or any other C programmer.
I'm unable to take this as an argument, sorry.
Yeah, so, if C programmers don't want this and people who recognize that automatic memory management is the future don't want this, I'm not really sure what this is even for.
 
Yeah, so, if C programmers don't want this and people who recognize that automatic memory management is the future don't want this, I'm not really sure what this is even for.
Probably we all end up with something we don't absolutely want:
  • C developers may end up having to work outside of their box and use non-C languages, perhaps due to corporate requirements or lack of native access inside a sandbox.

  • People who believe automatic memory management is the future may end up needing to work outside of their perfect little box and actually need to consider the physical hardware.
So perhaps Hare could be a compromise that neither group despises?
 
Doesn't look similar or simpler to me. I see some "functional" idioms that worry me.

Objective-c would be the perfect language if it had namespaces. I think it wouldn't be a strict superset of C if it did, though.
 
  • Like
Reactions: mer
Back
Top