Re: My experiences with Rust
- In reply to: Sulev-Madis Silber : "Re: My experiences with Rust"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 25 Aug 2025 18:04:35 UTC
On Sat, 23 Aug 2025 14:51:44 +0300
Sulev-Madis Silber <freebsd-hackers-freebsd-org952@ketas.si.pri.ee> wrote:
> On August 22, 2025 9:42:15 PM GMT+03:00, Vadim Goncharov
> <vadimnuclight@gmail.com> wrote:
> >On Fri, 22 Aug 2025 19:10:15 +0300
> >Konstantin Belousov <kostikbel@gmail.com> wrote:
> >
> >> For ktcplist, the more natural action would be to extend netstat(8)
> >> then to write a new tool, but I cannot make myself to use libxo. It
> >> is less painful to write Rust then to try to use libxo, at least for
> >> me.
> >
> >What's the problem with libxo?
> >
>
>
> the problem with libxo is that it makes this:
>
>
> bin/df/df.c
>
> xo_emit("{T:/%-*s}", mwp->mntfrom, "Filesystem");
> if (Tflag)
> xo_emit(" {T:/%-*s}", mwp->fstype, "Type");
> xo_emit(" {T:/%*s} {T:/%*s} {T:/%*s} {T:Capacity}",
> mwp->total, header,
> mwp->used, "Used", mwp->avail, "Avail");
> if (iflag) {
> mwp->iused = imax(hflag ? 0 : mwp->iused,
> (int)strlen(" iused"));
> mwp->ifree = imax(hflag ? 0 : mwp->ifree,
> (int)strlen("ifree"));
> xo_emit(" {T:/%*s} {T:/%*s} {T:\%iused}",
> mwp->iused - 2, "iused", mwp->ifree, "ifree");
> }
> xo_emit(" {T:Mounted on}\n");
>
>
> if you have feeling that this is written by disgruntled employee or perhaps
> even satan himself to annoy others then you're right
Well, I'm seasoned Perl programmer so I'm scared or even impressed much :-)
> it also makes all your utils need to have --libxo or similar option
>
> it's easy to make mistakes with this crazy formatting. i recall spotting one
> and reporting
So the problem is bad readability/maintenance? OK, I understand, this looks too
close to all those make(1) single-two character punctuations (another legacy).
Unfortunately, it's hard to achieve something much better in the C language
intersecting tools available in our base system.
I can offer two ways, short-term and long-term.
Short-term is to make syntax highlighting rules in editors (e.g. vim) for those
libxo constructs - this could make life somewhat easier.
Long-term is not very well achievable in C - it requires templating engine.
See, the same problem was at the dawn of the Web when CGI scripts began
looking as very many print() statements with HTML portions. The solution was
to split source to actual language filling variables and a template file
(which could be given to non-programmer like Web designer) which made
substitution of variables, like:
[% INCLUDE header
title = 'This is an HTML example';
pages = [
{ url = 'http://foo.org'
title = 'The Foo Organisation'
}
{ url = 'http://bar.org'
title = 'The Bar Organisation'
}
]
%]
<h1>Some Interesting Links</h1>
<ul>
[% FOREACH page IN pages %]
<li><a href="[% page.url %]">[% page.title %]</a>
[% END %]
</ul>
[% INCLUDE footer %]
However, for our case it would require FOUR templates - text, JSON, XML, HTML.
libxo tried to achieve this with a single instruction directly in C code,
that's why it looks THIS, and it is somewhat elegant in this all-once
achievement.
> on good side it does indeed allow machine readable and other outputs.
> currently it was iirc still text/json/xml/html. all that hassle for little
> good
>
> of course, what's alternative? write lib for that? maybe libsys?
That is actually very much because you can:
1) make queries by e.g. `jq` utility
2) get the data directly to non-base languages and utilities. For example, you
know that many tools exist e.g. for metrics which do support Linux but not
FreeBSD. And it is much more likely that authors of that tools, in Python or
Go, just slurp in FreeBSD's JSON rather than try to dig yet another library
API. This is important for better FreeBSD support - they usually don't have
FreeBSD machines, and Pull-Requests fromn our supporters much more likely will
be done (we have not so mane resources) and accepted if it is in universal
format rather some library.
This was e.g. one of the reasons to port netlink to FreeBSD, though netlink
does not cover everything.
> this has been discussed within "Massive libxo-zation that breaks everything"
> (which i created because i was pissed about using utils converted to it) and
> possibly earlier or later too, god knows in which lists, irc channels,
> forums or what not
>
> i think he meant that if he found xo bad
As avery time, the idea was excellent, the implementation had problems...
--
WBR, @nuclight