4 ms·
> I guess it's only natural that you should defend your own style. I have reasons for writing things that way, that can be documented, if necessary. The style
by kazinator 4y ago
> I guess it's only natural that you should defend your own style.
I have reasons for writing things that way, that can be documented, if necessary. The style is not my own, though.
> However, almost no C programmer would stack and hang their closing curly braces the way Lisp programmers do with closing parens.
But they do it all the time with parentheses, which is the normal thing to do.
By the way: spotted lots of this in the Zstandard compression code base a few days ago:
void fun()
{
if (...)
{
for (...)
{
...
} } }
Yikes; the closes braces line up with the opening ones, but not their corresponding matching ones. I hope that wasn't a Lisp coder (and don't suspect it).
> I'm just curious if maybe part of the reason Lisp is so objectionable to most programmers is because that style is so different from block structured languages.
But it isn't. Almost all the indentation and alignment strategies you see in canonically formatted Lisp code have counterparts in everyday code in mainstream languages.
Found this in Linux's kernel/sched/core.c:
WARN_ON_ONCE(debug_locks && !(lockdep_is_held(&p->pi_lock) ||
lockdep_is_held(__rq_lockp(task_rq(p)))));
^ Lisp disease?
^ gee what is this "arbitrary" alignment?
Would C be more popular if it was more typically like this?
WARN_ON_ONCE(
debug_locks &&
!(
lockdep_is_held(
&p->pi_lock
) ||
lockdep_is_held(
__rq_lockp(
task_rq(p)
)
)
)
);
In fair.c file in the same directory:
if ((ns->nr_running < ns->weight) ||
(((ns->compute_capacity * 100) > (ns->util * imbalance_pct)) &&
((ns->compute_capacity * imbalance_pct) > (ns->runnable * 100))))
return node_has_spare;
in drivers/md/raid5.c:
if (s.written &&
(s.p_failed || ((test_bit(R5_Insync, &pdev->flags)
&& !test_bit(R5_LOCKED, &pdev->flags)
&& (test_bit(R5_UPTODATE, &pdev->flags) ||
test_bit(R5_Discard, &pdev->flags))))) &&
(s.q_failed || ((test_bit(R5_Insync, &qdev->flags)
&& !test_bit(R5_LOCKED, &qdev->flags)
&& (test_bit(R5_UPTODATE, &qdev->flags) ||
test_bit(R5_Discard, &qdev->flags))))))
handle_stripe_clean_event(conf, sh, disks);
All of these examples use pretty much identical formatting logic as what I'm following when I'm coding in Lisp; except that a more pure version of it occurs.
- xscott 4y agoWell, you've successfully found examples of C code that I hate to look at. Those are all various shades of awful in my opinion. And again, I'm not attacking you or your style. I'm sure all 6 or 7 of you from comp.lang.lisp agree it's wonderful. :-)
- kazinator 4y agoThis is a predominant style used in writing "curly-braced C-likes"; you see it everywhere and examples can be found readily. You simply don't seem familiar with this subject area.
- xscott 4y agoHeh. I see we've gotten to the point where you switch from arguing the point to questioning my qualifications. Gross. I guess that means I should return the insult: Showing a few examples of ugly formatting doesn't prove that curly-braced languages are that way "everywhere". And besides, other than the one silly example from Zstandard, which many people would agree is unusual, you didn't even show examples of curly braces. Even with all the different styles of C people use, the block structure is pretty consistent. You're either being deceptive or you need work on your logic skills. Go ahead and grab the last word if you want it, but I think we've gotten away from anything good in this discussion.