git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/3] diff --stat: sometimes use non-linear scaling.

From
DRDavid Rientjes <rientjes@cs.washington.edu>
Date
Sep 27, 2006, 06:49 UTC
Message-ID
<Pine.LNX.4.64N.0609262320260.9088@attu4.cs.washington.edu>
In-Reply-To
<7vejtxhlv6.fsf@assigned-by-dhcp.cox.net>
On Tue, 26 Sep 2006, Junio C Hamano wrote:
> Well, the thing is, I end up being the guy who needs to stare at
> git code longer than you do ;-).
> 

Really? This is the only community that hacks git? There _are_ people out there that make their own changes specifically tailored to their purposes or that of their organization.

Show 24 quoted lines
> Before --stat-width was introduced there was code like this:
> 
> 	if (max + len > 70)
> 		max = 70 - len;
> 
> Here "len" is the width of the filename part, and "max" is the
> number of changes we need to express.  The code is saying "if we
> use one column for each changed line, does graph and name exceed
> 70 columns -- if so use the remainder of the line after we write
> name for the graph".  Your "constant at right" rule makes this
> kosher.
> 
> If we make that to a variable, say line_width, we can still
> write:
> 
> 	if (max + len > line_width)
>         	...
> 
> I however tend to think "if line_width cannot fit (max + len)
> then we do this", which would be more naturally expressed with:
> 
> 	if (line_width < max + len)
>         	...
> 

First of all, it's not my "constant at right" rule, it's a preference that the _majority_ of computer programmers have used in virtually every language that you see source code for.

The grammar for C is
  relational-expression:
	shift-expression
	relational-expression < shift-expression

in this case. Now while this supports both your variations above, it _suggests_ that the higher degree of computation is associated on the left side because the less-than operator associates that way.

What happens here:
	a < b < c
it turns out that this is equivalent to:
	(a < b) < c

so if you want your entire code base to conform to a particular style, it's _preferable_ to place the constant on the right. And that's what the majority of programmers do. Your taste is in the minority and out of respect to the code base you should make your code conform to what is most popular in the surrounding code.

Your argument of saying to yourself "if line_width cannot fit max + len then we do this" has no relevance at all. I can say "if max + len is too big for line_width we do this" just the same.

If we're going by what sounds better in your head, then I expect _no_ argument when I write a function called conseguir_la_linea_longitud instead of get_line_length because Spanish is my first language.

Please respect what the majority of computer programmers write and unify the code base so that it's a similar style everywhere.

Show 9 quoted lines
> > To change the code itself because of a hard 80-column limit or because 
> > you're tired of hitting the tab key is poor style.
> 
> Well, the program _firstly_ matches the logic flow better, and
> _in_ _addition_ if you write it another way it becomes
> unnecessarily too deeply indented.  So while I agree with you as a
> general principle that indentation depth should not dictate how
> we code it does not apply to this particular example.
> 

This is a ridiculous argument. The C code will emit the exact same assembly regardless of how you write it. You say that you wrote it that way to avoid idents which is an absolutely horrible way to dictate the code you use. There are tons of opportunities where you can write cryptic source code that functions great with the least number of tokens and least number of lines to get the job done in every large project. But, given that there are no assembler or performance tradeoffs, it should be written as clearly and nicely as possible for the reader. I assert again what I did previously: if that if clause runs the length of my screen the indents will help me later to remember we're still in a conditional. That's the SOLE purpose of indents: to make it easy for the reader to tell you're inside a block.

And in one of your patches you had:
	if (...)
		;
	else {
		...
	}

without any other if statements. If you're supporting that type of code, I'll simply consider this entire thread a lost cause.

		David
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 18 in “diff --stat: sometimes use non-linear scaling.”
  1. 3/3 diff --stat: sometimes use non-linear scaling.Junio C Hamano, Sep 27, 2006
  2. David RientjesSep 27, 2006
  3. Junio C HamanoSep 27, 2006
  4. David RientjesSep 27, 2006
  5. Junio C HamanoSep 27, 2006
  6. David RientjesSep 27, 2006
  7. Junio C HamanoSep 27, 2006
  8. David RientjesSep 27, 2006
  9. Johannes SchindelinSep 27, 2006
  10. Petr BaudisOct 6, 2006
  11. Johannes SchindelinSep 27, 2006
  12. Martin WaitzSep 27, 2006
  13. Linus TorvaldsSep 27, 2006
  14. Martin WaitzSep 28, 2006
  15. Junio C HamanoSep 28, 2006
  16. Andreas EricssonSep 29, 2006
  17. Johannes SchindelinSep 27, 2006
  18. SeanSep 27, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.