# programming language Hare



## Deleted member 70435 (Apr 26, 2022)

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:

```
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");
    };
   };
```



			Announcing the Hare programming language


----------



## Alain De Vos (Apr 27, 2022)

Good that people try new stuff. It's readable. One sidenote the name,






						FreshPorts -- sysutils/hare: Small C client for sending ssh login notications to a hared server
					

hare is a small utility which is installed in a PAM configuration (e.g. for sshd) in order to log successful logins. This is often useful to alert on machines which are seldom visited or otherwise monitored.  This client works in conjunction with the server sysutils/py-hared  This will form part...




					www.freshports.org


----------



## Zare (Apr 27, 2022)

Thoughts on Hare - ~kiedtl
					






					tilde.team
				




If this is the C replacement that doesn't try to do anything fancy but iron out the error-prone idiosyncrasies and repeated syntactic glue for which macros are not an answer, then I'm all for it.


----------



## mer (Apr 27, 2022)

Is it better than Rust or Go?


----------



## Alain De Vos (Apr 27, 2022)

Mer. Don't ask this question. Big things always start small. I have wren,zig,pony installled.
Rust is not bad. But compiling it takes lots of time...


----------



## Geezer (Apr 28, 2022)

Dimitri Chuikov said:


> Hare code example: ......





Dimitri Chuikov said:


> ......  similar to C but simpler than C.



Is it?


----------



## rootbert (Apr 28, 2022)

mer said:


> 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


----------



## mer (Apr 28, 2022)

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?


----------



## Alain De Vos (Apr 28, 2022)

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.


----------



## Deleted member 70435 (Apr 28, 2022)

Alain De Vos said:


> 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.


----------



## Zare (May 2, 2022)

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.


----------



## kpedersen (May 2, 2022)

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.


----------



## msplsh (May 2, 2022)

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.


----------



## mer (May 2, 2022)

msplsh said:


> 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.


----------



## Zare (May 2, 2022)

kpedersen said:


> 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.



msplsh said:


> 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.


----------



## msplsh (May 2, 2022)

Zare said:


> 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?


----------



## mer (May 2, 2022)

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.


----------



## Zare (May 2, 2022)

"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.


----------



## kpedersen (May 2, 2022)

Zare said:


> 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.


Zare said:


> 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.


----------



## mer (May 2, 2022)

kpedersen said:


> 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.


----------



## kpedersen (May 2, 2022)

mer said:


> 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.


----------



## msplsh (May 2, 2022)

Zare said:


> "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.


----------



## kpedersen (May 2, 2022)

msplsh said:


> 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?


----------



## msplsh (May 2, 2022)

Don't think so?  Rust has the unsafe hatch.


----------



## Jose (May 2, 2022)

Geezer said:


> Is it?


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.


----------



## Zare (May 5, 2022)

msplsh said:


> 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.



I don't fundamentally agree with 'one future', but yes that is the gist of my post. If Hare doesn't utilize the already present C ecosystem it will remain niche



kpedersen said:


> 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.
> 
> ...



I think people overstate the commercial impact of "new technologies".
Maybe in the startup scene they're adopted very fast but in the normal industry projects are slower. Way slower. I've worked on huge C99 code bases in late 2010s that were sold as a cutting edge product.

C/C++ are strong on the market. The movement away from those languages in systems development arena is coincidentally pushed by those who made the replacements and those in their wallgardens, it's not a wide phenomenon.

Just imagine the effort needed to convert FreeBSD, Linux, GNU, Windows kernel, etc. to a new technology even if the technology was better than C/C++ in every possible aspect - which these replacements certainly aren't.


----------



## fryshke (May 13, 2022)

Oof, supports only Linux/FreeBSD, no easy way to call Hare from C. Seems very very niche.

Personally when I need C - I use Zig.


----------



## Alain De Vos (May 13, 2022)

For objects there is crystal. For functional there is nim. For C there is zig. With zig you can also compile to different architectures.


----------

