Doods

@Doods@infosec.pub

This profile is from a federated server and may be incomplete. Browse more on the original instance.

Doods,

A single match statement inside a function inside an impl is already 4 levels of indentation.

How about this?

The preferred way to ease multiple indentation levels in a switch statement is to align the switch and its subordinate case labels in the same column instead of double-indenting the case labels. E.g.:


<span style="color:#323232;">switch (suffix) {
</span><span style="color:#323232;">case 'G':
</span><span style="color:#323232;">case 'g':
</span><span style="color:#323232;">        mem <<= 30;
</span><span style="color:#323232;">        break;
</span><span style="color:#323232;">case 'M':
</span><span style="color:#323232;">case 'm':
</span><span style="color:#323232;">        mem <<= 20;
</span><span style="color:#323232;">        break;
</span><span style="color:#323232;">case 'K':
</span><span style="color:#323232;">case 'k':
</span><span style="color:#323232;">        mem <<= 10;
</span><span style="color:#323232;">        /* fall through */
</span><span style="color:#323232;">default:
</span><span style="color:#323232;">        break;
</span><span style="color:#323232;">}
</span>

I had some luck applying this to match statements. My example:


<span style="color:#323232;">
</span><span style="color:#323232;">let x = 5;
</span><span style="color:#323232;">
</span><span style="color:#323232;">match x {
</span><span style="color:#323232;">5 => foo(),
</span><span style="color:#323232;">3 => bar(),
</span><span style="color:#323232;">1 => match baz(x) {
</span><span style="color:#323232;">	Ok(_) => foo2(),
</span><span style="color:#323232;">	Err(e) => match maybe(e) {
</span><span style="color:#323232;">		Ok(_) => bar2(),
</span><span style="color:#323232;">		_ => panic!(),
</span><span style="color:#323232;">		}
</span><span style="color:#323232;">	}
</span><span style="color:#323232;">_ => panic!(),
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span>

Is this acceptable, at least compared to the original switch statement idea?

Doods, (edited )

How about this one? it more closely mirrors the switch example:


<span style="color:#323232;">match suffix {
</span><span style="color:#323232;">'G' | 'g' => mem -= 30,
</span><span style="color:#323232;">'M' | 'm' => mem -= 20,
</span><span style="color:#323232;">'K' | 'k' => mem -= 10,
</span><span style="color:#323232;">_ => {},
</span><span style="color:#323232;">}
</span>

How about this other one? it goes as far as cloning the switch example’s indentation:


<span style="color:#323232;">match suffix {
</span><span style="color:#323232;">'G' | 'g' => {
</span><span style="color:#323232;">	mem -= 30;
</span><span style="color:#323232;">        }
</span><span style="color:#323232;">'M' | 'm' => {
</span><span style="color:#323232;">	mem -= 20;
</span><span style="color:#323232;">        }
</span><span style="color:#323232;">'K' | 'k' => {
</span><span style="color:#323232;">	mem -= 10;
</span><span style="color:#323232;">        }
</span><span style="color:#323232;">_ => {},
</span><span style="color:#323232;">}
</span>
Doods,

Formatters are off-topic for this, styles come first, formatters are developed later.

My other reply:

How about this one? it more closely mirrors the switch example:


<span style="color:#323232;">match suffix {
</span><span style="color:#323232;">'G' | 'g' => mem -= 30,
</span><span style="color:#323232;">'M' | 'm' => mem -= 20,
</span><span style="color:#323232;">'K' | 'k' => mem -= 10,
</span><span style="color:#323232;">_ => {},
</span><span style="color:#323232;">}
</span>

How about this other one? it goes as far as cloning the switch example’s indentation:


<span style="color:#323232;">match suffix {
</span><span style="color:#323232;">'G' | 'g' => {
</span><span style="color:#323232;">  mem -= 30;
</span><span style="color:#323232;">       }
</span><span style="color:#323232;">'M' | 'm' => {
</span><span style="color:#323232;">  mem -= 20;
</span><span style="color:#323232;">       }
</span><span style="color:#323232;">'K' | 'k' => {
</span><span style="color:#323232;">  mem -= 10;
</span><span style="color:#323232;">       }
</span><span style="color:#323232;">_ => {},
</span><span style="color:#323232;">}
</span>
Doods,

I just got some idea yesterday regarding impl blocks, ready to be my respondent?

I had a big impl block with 4 levels of indentation, so I cut the block, and replaced


<span style="color:#323232;">impl InputList {
</span><span style="color:#323232;">    //snip
</span><span style="color:#323232;">}
</span>

with mod impl_inputlist; and moved the impl block to a new file, and did not indent anything inside that block.

The advantage this has over just not indenting the impl block in place, is that people will have difficulty distinguishing between what’s in the block and what’s outside, and that’s why the impl was moved to its own exclusive file, impl_inputlist.rs

Maybe I am overstressing indentation. Ss there something wrong with my setup that prevents me from accepting 4-space indentation?

I use:

Editor: Neovide

Font: “FiraCode Nerd Font Mono:h16” (16px fonts are addicintg)

Monitor: 1366x768, 18.5 inch, 10+ years old, frankenstein-ly repaired Samsung monitor.

Distance: I sit at about 40-60 Cm from my monitor.

That leaves me with a 32x99 view of code excluding line numbers and such.

Doods, (edited )

My emotions just stopped, so I can now think straight.

There are really only 2 changes that - in my eyes - should be made:

  • 8 space-long, hard tabs.
  • 80 character limit instead of 100.

I don’t think a tool like rustfmt can affect most of the original guidelines, and it’s generally compatible with the OG style by default.

Edit: I - surprisingly - never actually used rustfmt, so I will go now and test before I say something stupid.

Edit II: I just found this on their repo:

Rustfmt is designed to be very configurable.

Edit III: I tested rustfmt with:

hard_tabs = true

max_width = 80

It’s great!

Doods, (edited )

The kernel had a consistent style before rust was even an idea! Who do you think has started this inconsistency? (Maybe not, what does someone like me know about the kernel anyway)

Doods, (edited )

having five times more work to use tabs for indentations and spaces for alignment and thus having to use visual whitespace of some kind.

Excuse me. What does that mean? (also see my reply to 1rre)

Doods, (edited )

It has a long-lasting C coding standard, they call it the standard since it was the only language anyway. Then, they made a newly conceived Rust standards, which ignore everything the original standard stood for. (Note the strong language in the post’s first quote, it’s from the original standard)

Doods,

Agreed, and upvoted.

Doods, (edited )

This one in particular I am against. (it’s not like it’s possible in rust anyway)

Doods, (edited )

wasting 10% of that space for each indentation? What are you smoking?

As I said before, this standard is older than C itself, and the kernel’s been using it for decades, I shouldn’t have to explain it. Long tabs and short lines boost readability, and restricting indentation to 3 solves the problem. Read my reply to 1rre@discuss.tchncs.de for more context.

Also rustfmt didn’t move the string in

println!(“a very long string slice with a static lifetime”); to a new line even when it exceeded a 100 columns, I should seek a solution.

Note: The actual string I used was way longer than that.

Doods, (edited )

So, why don’t people just restrict tabs to pre-text, strictly-sized indentation?

On a side note: I think (not sure) that indenting with 8 or more spaces just to align 2 similar but differently sized lines of code is a bit too much.

Doods, (edited )

Well, what I meant was just rustfmt’s default with:

  • 80 character line
  • 8-space hard tabs

In addition to naming local variables short names, and soft-limiting functions to 48 lines long & their local variables to 5-10 (you know, normal reasonable things)

The part about switch statements doesn’t apply as Rust replaced them with match.*

The part about function brackets on new lines doesn’t apply because Rust does have nested functions.

The bad part about bracket-less if statements doesn’t apply as Rust doesn’t support such anti-features.

The part about editor cruft is probably solved in this day & age.

The rest are either forced by the borrow checker, made obsolete by the great type system, or are just C exclusive issues that are unique to C.

I left out some parts of the standard that I do not understand.

I just skimmed through the Rust style guide, and realized the only real difference between the 2 standards is indentation, and line length. Embarrassing.

*: I experimented with not-indenting the arms of the root match expression, it’s surprisingly very good for simple match expressions, and feels very much like a switch, though I am not confident in recommending to people.

Edit: How did I forget?! Indentation is limited to 3, increasing code readability.

Doods,

No, it is not, people have been using 8-space tabs even back when terminals were limited to 80 characters.

Doods,

A semi-rolling distribution, with access to Ubuntu’s many PPA’s, and easily removable extensions that reveal the lovely vanilla Gnome experience, it’s great!

Also they are making a Rust desktop, which I am currently running, though not daily driving.

Doods, (edited )

I am on Pop!_OS, I ran sudo apt install cosmic*.

Don’t worry, you’re not missing out on much, running video games, or any OpenGL thing including 2D games and GPU-accelerated terminal emulators is a bad experience, and alt+f4 isn’t implemented, and f11 to fullscreen is janky, and theming for buttons and such is clearly alpha.

The promise of an Arabic-supporting, Rust based, GPU-accelerated terminal is too attractive, however, as I was teared between multilingual terminal, Wezterm, Alacritty and Kitty for a while.

The first is horrible at everything but supporting languages, the second is really janky, the third doesn’t support tabs, the fourth has bad theming and customization.

Doods, (edited )

Inaccurate report,

I just ran Neovim in terminal and was used to Neovide, so I thought it was choppy.

Intel HD 630.

There is, however, a 2D game - which I am not going to disclose the name of - that’s pretty broken. (It uses Adobe Flash as an engine)

Also the steam client doesn’t maximize properly with tiling but I am sure that’s reported.

I have been daily driving Cosmic for a week now; it caused me Arch-syndrome, everyday I run sudo apt update hoping to get some polish to the desktop.

Edit: there’s more…

Neovide’s transparency is completely broken, and shows a blank, though not a pitch black, color and screenshotting it results in seeing the text with a checkered background. (In the resulting screenshot only) (Running on Proton 8.0-5)

clipboard=unnamed plus, the setting supposed to unify Neovim’s clipboard and system’s, doesn’t work. clipboard: error : Error: target STRING not available

I also was unable to transfer a file to my phone using Cosmic Files, but Nemo worked, though I read that’s fixed in some Blog.

Edit II: I just discovered popdev:master it seems to be a general unstable branch instead of just Cosmic things, but I took the risk and added it, I just have to remember to remove it once 24.04’s released

Doods,

Also, sloppy focus aka focus-follows-mouse

It’s one of those features I always wanted to try, but always forget to look up how to actually enable and start using it, so I never actually tried it.

Doods,

running video games, or any OpenGL thing including 2D games and GPU-accelerated terminal emulators is a bad experience

The thing you replied to; I don’t open social media often enough to reply on time, so I sent you a late reply.

Doods,

Flatpaks never worked for me though, last I tried was 38.

Also didn’t something happen in relation to some encoding?

Pop!_OS would be my recommendation, semi-rolling for sweet driver updates, Ubuntu based for easy searching (how to do x on Ubuntu) and Large software support.

I just remembered that Pop!_OS doesn’t ship with vanilla gnome, sadly, which degrades its position as a recommendation.

Doods,

That’s what I hear Pop people saying.

Doods,

So what should we do then? switch to something else? Host our own email service?

I really don’t know.

Doods,

If the open AI guy made the training data, the hardware, and every electron, then yes.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • megavids
  • kavyap
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • ngwrru68w68
  • cubers
  • thenastyranch
  • Youngstown
  • rosin
  • slotface
  • cisconetworking
  • mdbf
  • ethstaker
  • JUstTest
  • Durango
  • khanakhh
  • GTA5RPClips
  • anitta
  • osvaldo12
  • everett
  • normalnudes
  • tester
  • tacticalgear
  • provamag3
  • modclub
  • Leos
  • lostlight
  • All magazines