Re: [hackers] [st][PATCH v2] code-golfing: cleanup osc color related code

From: NRK <nrk_AT_disroot.org>
Date: Mon, 21 Mar 2022 15:13:49 +0600

On Mon, Mar 21, 2022 at 09:24:50AM +0100, Roberto E. Vargas Caballero wrote:
> I think is better to keep every ternary in a line by itself, because it makes
> easier to read them:
>
> fprintf(stderr, "erresc: failed to fetch %s color %d\n",
> is_osc4 ? "osc4" : "osc",
> is_osc4 ? num : index);

Done.

> I think we force here to put braces around if and else because the body of the
> if part is more of one line. Again, I think is better to use a line for every
> ternary and have something like:
>
>
> if (n < 0 || n >= sizeof(buf)) {
> fprintf(stderr, "error: %s while printing %s response\n",
> n < 0 ? "snprintf failed" : "truncation occurred",
> is_osc4 ? "osc4" : "osc");
> } else {
> ttywrite(buf, n, 1);
> }
>
> > + if ((j = par - 10) < 0 || j >= LEN(osc_table))
> > + break; /* shouldn't be possible */
> >
> > if (!strcmp(p, "?"))
> > - osc_color_response(defaultcs, 12);
> > - else if (xsetcolorname(defaultcs, p))
> > - fprintf(stderr, "erresc: invalid cursor color: %s\n", p);
> > + osc_color_response(par, osc_table[j].idx, 0);
> > + else if (xsetcolorname(osc_table[j].idx, p))
> > + fprintf(stderr, "erresc: invalid %s color: %s\n",
> > + osc_table[j].str, p);
> > else
> > tfulldirt();
> > return;
>
> Same apply here, I think our style forces to have braces in every if and else if
> because there is a body with more of one lines.

I agree with that, but I wasn't sure what the preferred style here is
since I've seen a lot of multi-line bodies have no braces, most notably
on the DWM source code. Though, looking around a bit, the ST source
seems to be consistent with it's braces.

Attached the amended patch.

- NRK

Received on Mon Mar 21 2022 - 10:13:49 CET

This archive was generated by hypermail 2.3.0 : Mon Mar 21 2022 - 10:24:40 CET