this post was submitted on 03 May 2025
27 points (81.4% liked)

Programmer Humor

22981 readers
1494 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 

Description, because "alt text" can't show it well:

			{
				emit differentFiles (ckFile.absoluteFilePath(),
					otherFile.absoluteFilePath(),
					FileCompareWorker::FileComparisonParams{FileComparisonParams::FileNameMatch,
						(ckFile.size() > otherFile.size()) ? FileComparisonParams::File1IsLarger
							: FileComparisonParams::File2IsLarger});
			}

After Alignment

			{
				emit differentFiles (ckFile.absoluteFilePath(),
					otherFile.absoluteFilePath(),
					FileCompareWorker::FileComparisonParams{FileComparisonParams::FileNameMatch,
						(ckFile.size() > otherFile.size()) ? FileComparisonParams::File1IsLarger
														   : FileComparisonParams::File2IsLarger});
			}
top 19 comments
sorted by: hot top controversial new old
[–] bleistift2@sopuli.xyz 16 points 16 hours ago (1 children)

I find both horrifying.

This is how I’d want to read it:

			{
				emit differentFiles(
					ckFile.absoluteFilePath(),
					otherFile.absoluteFilePath(),
					FileCompareWorker::FileComparisonParams{
						FileComparisonParams::FileNameMatch,
						(ckFile.size() > otherFile.size())
							? FileComparisonParams::File1IsLarger
							: FileComparisonParams::File2IsLarger
					}
				);
			}
[–] ulterno@programming.dev 1 points 3 hours ago* (last edited 3 hours ago)

That looks nice and easy to understand.
I would go one step further and according to my preferences:
(starting from line5)

FileCompareWorker::FileComparisonParams
{
	FileComparisonParams::FileNameMatch,
	(ckFile.size() > otherFile.size())
		? FileComparisonParams::File1IsLarger
		: FileComparisonParams::File2IsLarger
}

Break before the curly as I do for most.

[–] Quill7513@slrpnk.net 36 points 21 hours ago (1 children)

Not random. This is a pretty common standard for most style guides that if you split a ternary operator across lines you align the option colon to the ternary itself. Your alt text formatting is way different from the pic by the way

[–] ulterno@programming.dev 3 points 21 hours ago* (last edited 21 hours ago)

Your alt text formatting is way different from the pic by the way

Hmm.
I really just copied the stuff directly. Let me try again.

pretty common standard

I get it. But I set all available "Align" flags to false and am still getting this.
I just want a simple thing that only does continuation indents. ~~If there is a space added, it should be something according to the coder (Is what I mean by indents only).~~ though not even that, because all spaces before the first character in the line are to be removed.


Not random

Well, I guess I'll go put a better word in there

[–] eager_eagle@lemmy.world 6 points 16 hours ago (1 children)

is it my lack of go skills, or they're both really awful to read? It takes me multiple seconds to match the first parenthesis opened and it seems the code could really use a refactoring, but both formatting options suck.

[–] ulterno@programming.dev 0 points 3 hours ago

Honestly, I'd prefer all curly's in a new line, indented according to the previous one and in some cases, even parentheses in new lines.

But if I had a problem with that, I would just go ahead and break the line down (that's a single statement, I consider it 1 line of code) into multiple, with the arguments put into variables.

[–] Agrivar@lemmy.world 14 points 20 hours ago (1 children)

The "after" version looks better to my eyes...

[–] ulterno@programming.dev 0 points 19 hours ago

I am noone to say no to your preferences. and you can set your config that way.
I want the "before" in my project.


Also, consider the case where the thing after the : were longer and it would be using another line.

[–] Lucien@mander.xyz 8 points 21 hours ago (1 children)

Like the other commented said, this isn't random, but also I'd add that your first ternary option, the ?, should be on the next line; it would make the alignment make more sense to you then, and it would make the block more legible.

[–] ulterno@programming.dev 3 points 20 hours ago* (last edited 20 hours ago)

I think I'd rather go with the ? being on the same line as the 'condition' and the rest can go on the other line.

Otherwise, I'd be looking one line downwards and then coming back up after realising that it is a (cond)?ex:ex operator.


And I get that it's not random, just that I asked for it at as many places as possible to not do alignment.
And from what I can recall, I had managed to make stuff work with the older clang-formats...
Or maybe not. Maybe this kind of code never went through it.

[–] Flipper@feddit.org 7 points 20 hours ago (2 children)

You shouldn't use tabs for alignment. It breaks for everyone with a different tab size.

[–] mmddmm@lemm.ee 9 points 17 hours ago

You shouldn't align code anyway.

If it's important to have stuff on the same column, make it an indentation level and add a line break where it starts.

[–] ulterno@programming.dev 4 points 19 hours ago* (last edited 19 hours ago) (1 children)
  1. I am using tabs for INDENTATION. I don't want alignment.
  • I have tried my best to remove all alignment operations of clang-format
  1. What do you use tabs for?
[–] Quill7513@slrpnk.net 5 points 18 hours ago (1 children)

if you don't want alignment don't be surprised when your code doesn't align 🤷

[–] ulterno@programming.dev 0 points 3 hours ago

If that's supposed to be a pun, I didn't get it.

[–] ulterno@programming.dev 2 points 21 hours ago

BTW, I changed my code to avoid the formatting:

{
	if (ckFile.size() > otherFile.size())
	{
		emit differentFiles (ckFile.absoluteFilePath(),
			otherFile.absoluteFilePath(),
			FileCompareWorker::FileComparisonParams{
				FileComparisonParams::FileNameMatch, FileComparisonParams::File1IsLarger});
	}
	else
	{
		emit differentFiles (ckFile.absoluteFilePath(),
			otherFile.absoluteFilePath(),
			FileCompareWorker::FileComparisonParams{
				FileComparisonParams::FileNameMatch, FileComparisonParams::File2IsLarger});
	}
}

BTW, here is my .clang-format in case you are interested

[–] MNByChoice@midwest.social 1 points 18 hours ago (1 children)

Seems like a lot of work, when the font I use will mess it up. And compiler/interpreter won't care.

But if it makes you happy, go for it.

[–] Quill7513@slrpnk.net 1 points 4 hours ago (1 children)

are you not using a monospace font?

[–] ulterno@programming.dev 0 points 3 hours ago