News for hackers. Stuff that matters.
Re:Transmission torrent client ported to C++ by ziftface on Sunday September 12, 2021 @05:12PM (#28505006)
But if that's the case couldn't there just be a library that provides all the functionality without having to switch languages? Something like boost but for plain C?
Re:Transmission torrent client ported to C++ by lalaland1125 on Sunday September 12, 2021 @05:38PM (#28505244)
The lack of generics for C makes it difficult to write those sorts of libraries in an efficient way.
Re:Transmission torrent client ported to C++ by klyrs on Sunday September 12, 2021 @11:16PM (#28507518)
C has had generics since C11. Can't fault you for not knowing that, as they're a pain to use and I think folks would rather forget that the language feature exists.
Re:Transmission torrent client ported to C++ by edflsafoiewq on Monday September 13, 2021 @12:08AM (#28507774)
_Generic is basically a switch on typeof(x). Despite the name, it's really a specialization/overloading mechanism.
Re:Transmission torrent client ported to C++ by junon on Monday September 13, 2021 @05:10AM (#28509244)
Those aren't generics, they're more like overloading.
Re:Transmission torrent client ported to C++ by rwmj on Monday September 13, 2021 @03:20AM (#28508706)
I wrote this (slightly crazy) generic vector for C: https://gitlab.com/nbdkit/nbdkit/-/blob/master/common/utils/... If you search for "string" in this page you can see how it is used: https://gitlab.com/nbdkit/nbdkit/-/blob/master/plugins/data/...
Re:Transmission torrent client ported to C++ by ncmncm on Sunday September 12, 2021 @11:11PM (#28507485)
And, generally impossible to write C generics so they may confidently be used safely. There are reasons why C++ was necessary.
Re:Transmission torrent client ported to C++ by tekknik on Monday September 13, 2021 @10:20PM (#28519444)
You’d use a code generator for this, similar to how you’d do it in golang.
Re:Transmission torrent client ported to C++ by zucker42 on Sunday September 12, 2021 @10:51PM (#28507373)
C libraries can't be simultaneously as generic and as fast as equivalent C++ libraries without (or sometimes even with) the aforementioned "clunky macro hacks".
Re:Transmission torrent client ported to C++ by lionkor on Monday September 13, 2021 @03:47AM (#28508851)
if "fast" was the only requirement we would be writing it in assembly
Re:Transmission torrent client ported to C++ by zucker42 on Monday September 13, 2021 @10:46AM (#28512158)
"Fast" is never the only requirement but often is a requirement. And the problem with a slow library is you don't know when rewriting the program to not use the library will be necessary to achieve the desired performance.
Re:Transmission torrent client ported to C++ by tempodox on Monday September 13, 2021 @07:20AM (#28510063)
Nope, folks didn't invent higher-level programming languages (the first of which was arguably Fortran, see case in point [1]) because they wanted their code to run slower.

In fact, if “fast” is the most important requirement we'll probably write it in Fortran or C++. With C++ you just have to know which parts not to use.

[1] Fortran Web Framework https://news.ycombinator.com/item?id=28509333

Re:Transmission torrent client ported to C++ by rbanffy on Monday September 13, 2021 @06:42AM (#28509791)
If fast were the only requirement, we’d have vastly different processor and memory architectures and we’d probably write in higher level languages with compilers that would also generate the optimal ISA to be compiled into architecture-specific microcode along with the binary that runs on it with enough information the OS can pick which part of the heterogeneous machine is best suited to run the program.
Re:Transmission torrent client ported to C++ by tekknik on Monday September 13, 2021 @10:22PM (#28519458)
No OS, it’s too slow. The binary needs to bootstrap the machine as well.
Re:Transmission torrent client ported to C++ by guerrilla on Sunday September 12, 2021 @09:43PM (#28506982)
Yes, Gtk+ and Glib do that with the catch that C has no type polymorphism, so everything is done with casts and void pointers. It's even fully object-oriented.
Re:Transmission torrent client ported to C++ by qalmakka on Monday September 13, 2021 @04:40AM (#28509115)
The Glib approach is an immense monolith of nonsensical zealotry towards C. Reimplementing an Object-Oriented system in C using hacks and void pointers when GCC already had not one but two fully object oriented languages built-in was a completely pointless endeavor. There are a million different ways to shoot youself in the foot with Glib, and it definitely doesn't feel like writing C at all.

I understand the historical context that lead to the creation of Glib (no C++ standard in the mid-'90s, no decent open Objective-C libraries, Stallman and most of the FOSS movement at the time harbouring a deep disgust towards C++ for some reason, etc), but it can't be pointed at as a good example of how to code in C - on the contrary, it's IMHO exactly what your C project shouldn't do. You've picked C because it's simple and clear, don't butcher it up with macros and weird hacks just to get a worse Objective-C.

Re:Transmission torrent client ported to C++ by guerrilla on Monday September 13, 2021 @06:08AM (#28509559)
> understand the historical context that lead to the creation of Glib

Well, yeah, that was 23 years ago. Back then there was no GNUstep and no free as in freedom C++ or Objective-C compiler. Now GCC's main development language is C++ and GNOME is slowly becoming somewhat language agnostic and also has Vala which at one point was supposed to cover up that mess.

I guess another point is that they seem happy with it[1], so why should we care anyway.

1. http://planet.gnome.org

Re:Transmission torrent client ported to C++ by rbanffy on Monday September 13, 2021 @06:44AM (#28509806)
I’d love to have a good excuse to program in Vala… it seems like a very nice language.
Re:Transmission torrent client ported to C++ by qalmakka on Monday September 13, 2021 @07:47AM (#28510268)
Both g++ and the objective-C frontend already existed back then, so your argument isn't correct. I think the main reason back then was that Stallman and the FSF were very much against C++, and pushed very hard for everything under the GNU umbrella to be written preferably in C or Scheme. They only relaxed that after much insistence from the GCC developers, which wanted to be able to use templates and RAII.

I think that Glib was born from the same mentality which considered C as the perfect language, with the end goal of getting the same functionalities of modern languages without leaving it.

Re:Transmission torrent client ported to C++ by guerrilla on Monday September 13, 2021 @09:09AM (#28511015)
You're right, g++ was there by the end of the first year but as far as I can tell libstdc++ didn't show up until around 1998. I don't know when GCC started supporting Objective-C (another commenter says maybe by 1992) but GNUStep didn't 1.0 until 1998 (it was fairly incomplete before that.)

But yes, you're right, they could have developed Glib in either of those languages even if STL and *step didn't exist yet. I also found this e-mail[1] from Stallman that supports your claim. Do you know of more documentation? I'm interested in this history.

1. http://harmful.cat-v.org/software/c++/rms

Re:Transmission torrent client ported to C++ by pjmlp on Monday September 13, 2021 @10:07AM (#28511680)
The main reason why Gtk and GNOME exist was Qt's license and yes C above all.

Here is one of the original versions of the GNU Coding Standards from 1994,

https://www.schwedler.com/old/HTML/standards_7.html#SEC12

> Using a language other than C is like using a non-standard feature: it will cause trouble for users. Even if GCC supports the other language, users may find it inconvenient to have to install the compiler for that other language in order to build your program. So please write in C.

Re:Transmission torrent client ported to C++ by qalmakka on Monday September 13, 2021 @10:09AM (#28511700)
I found an archived copy of the GNU guidelines from 2004 that well represents what was the GNU policy of the time:

https://web.archive.org/web/20041029162424/https://www.gnu.o...

As you can see, it basically consisted in "use C, unless you _really_ have too". It was also well known that C++ was heavily discouraged by Richard Stallman, so picking it could well end up in your project having a hard time being adopted by GNU.

The guidelines were relaxed afterwards, especially since GCC came to rely on C++ and every relevant C compiler was then written in C++, making the whole "we don't want to force people to install g++" even more nonsensical. In 2004 C++ was already way too ubiquitous to not have g++ installed.

Re:Transmission torrent client ported to C++ by epmos on Monday September 13, 2021 @06:47AM (#28509830)
> no free as in freedom C++ or Objective-C compiler

G++ was available in 1990. I don't recall when Objective C became available in GCC, but it was present in at least gcc-2.2.2 in 1992.

Re:Transmission torrent client ported to C++ by ncmncm on Sunday September 12, 2021 @11:09PM (#28507476)
"Something like boost but for plain C" is, exactly, Standard C++.
Re:Transmission torrent client ported to C++ by whaaswijk on Sunday September 12, 2021 @05:21PM (#28505096)
In theory there could be such a library but in practice I don’t think there is. Maybe because maintaining something like the STL is a non-trivial task.
Re:Transmission torrent client ported to C++ by mastrsushi on Sunday September 12, 2021 @05:45PM (#28505308)
That’s pretty much what glib is. There are generic structures.
Re:Transmission torrent client ported to C++ by cassepipe on Sunday September 12, 2021 @05:55PM (#28505395)
Does transmission use glib?
Re:Transmission torrent client ported to C++ by guerrilla on Sunday September 12, 2021 @09:44PM (#28506991)
Yes, it's built on Gtk+ (which is built on Glib.)
Re:Transmission torrent client ported to C++ by _ZeD_ on Monday September 13, 2021 @12:45AM (#28507942)
thats (one of) the client(s)?
Re:Transmission torrent client ported to C++ by LAC-Tech on Sunday September 12, 2021 @07:06PM (#28505921)
I wonder if Dlangs "betterC" would be a good fit, since you get real metaprogramming then.
Re:Transmission torrent client ported to C++ by elcritch on Sunday September 12, 2021 @08:23PM (#28506506)
Dlang's betterC would be a good option for just a better-than-C language but looks like it doesn't support D's standard library [1]. That'd mean being stuck with plain C container libraries. :/

Personally, I was impressed by an approach taken by the authors of Pixie (a fast 2d library like Cairo) [2]. They created a "library wrapper" generator for Nim code that supports creating libraries Python, Node, C, and Nim itself that they call Genny [3]. Haven't tried it but being able to use Nim and it's ref based gc but still export to nice API's in other languages is fantastic. Pixie's aim is to be a Cairo alternative so it makes sense they'd need this. I hope the approach takes off. Usually writing any cross language API's is a lossy operation.

Here's a sample of the API definition:

    exportObject Matrix3:
      constructor:
         matrix3
      procs:
         mul(Matrix3, Matrix3)
1: https://dlang.org/spec/betterc.html 2: https://github.com/treeform/pixie 3: https://github.com/treeform/genny

(edited formatting)

Re:Transmission torrent client ported to C++ by david2ndaccount on Sunday September 12, 2021 @10:56PM (#28507397)
The consequences of betterC are listed out here. https://dlang.org/spec/betterc.html#consequences

Notice that betterC does not exclude templates or destructors, so you could still use c++-style containers based around RAII, etc.

The argument against it is a smaller ecosystem and you’d end up having to roll your own containers etc.

Re:Transmission torrent client ported to C++ by ksec on Sunday September 12, 2021 @09:50PM (#28507020)
>I wonder if Dlangs "betterC" would be a good fit,

You mean "Das C" ? :)