Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Xanthir
My HERO!!!
Posts: 5215
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Wed Dec 16, 2015 11:11 pm UTC

ucim provided an example a few posts ago:

ucim wrote:Of course, when the user resizes the window, "hilarity ensues". But as an alternative, the text could be snake-scrollable.... inside scrolling would yield (i.e. by the time the user scrolled an entire column worth)

2|3|4|
5|6|7|


Basically, when you scroll the content moves through the columns. It's like the column layout was actually just an offset series of windows viewing the content, so when you scroll, you see it move in all the columns.

(It's "snake" scrolling because the content slithers back and forth as it reaches the top of one column, then down to the bottom of the next.)
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

commodorejohn
Posts: 958
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Wed Dec 16, 2015 11:27 pm UTC

Ah. Yeah, that seems terribly confusing.
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

User avatar
phlip
Restorer of Worlds
Posts: 7543
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Wed Dec 16, 2015 11:46 pm UTC

My first guess when I heard the term "snake scrolling" was that you'd read the first column top-to-bottom, then the second column bottom-to-top, so you don't have to scroll all the way back up to the top each time. But that sounded terrible, so I assumed (apparently correctly) that I was misunderstanding.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
ucim
Posts: 5570
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Coding: Fleeting Thoughts

Postby ucim » Thu Dec 17, 2015 3:40 am UTC

Xanthir wrote:Is it broken at the link I provided?
Nope, that one works fine. I'll post the broken one when I come across it again. It could be broken by the browser, but (like all websites!) it could be broken by the web designer. (Why can't we bring back the shock modem? :) )

commodorejohn wrote:I've never even heard of snake-scrolling, and Google isn't being any help. What is it?
Ninja'd by Xanthir, who is right. Imagine lots of text arranged in (e.g.) three columns. It still doesn't all fit, so the rest of the text is invisible "under" the third column. There is nothing "underneath" the other two columns - text continues from the bottom of the window of the first column to the top of the window of the second column, etc. If you leave everything alone, you read it as if it were laid out in three columns, all of which are visible.

The remaining text, is "under" the third column and thus not visible, is accessed by scrolling the inner scrollbar. That third column scrolls, revealing the remaining text. The text that scrolls off the top of the third column reappears at the bottom of the second column (which also scrolls), and the text that disappears at the top of the second column reappears at the bottom of the first one. The text that disappears at the top of the first one disappears like any other scrolled text.

The rest of the page remains static. The effect is that, at any point, the visible text is a contiguous part of the fulltext, displayed in three (in this example) columns.

Sure it's unusual because nobody's done it. But it's probably the most natural of the options, which is why I'm suggesting it. Consider the alternatives:

  • Vertical scrolling: Text is displayed in three (or whatever...) columns whose height may be greater than the viewport, and whose contents therefore require scrolling. Scroll down to see the rest of the (static) first column, and then scroll back up manually to see the start of the second column. Rinse, repeat.
  • Horizontal scrolling: Text is displayed in however many columns are needed given the height of the viewport. Read the first few columns normally, then scroll to the right to access the rest of the columns.

In all cases, the content will need to reflow if the viewport is resized; snake-scrolling would be no exception. But I think it's a significant improvement, and recommend that it be added as an option. Something like

<span style="column-width-min:25em; column-width-max:40em; scroll:snake;">lots of content</span>

The options for scroll would be "horizontal", "vertical", "snake". The web designer could decide what to suggest to the browser (and the browser, especially older ones, will be like unto the sea, and do what it wants anyway. :) )

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

User avatar
Wildcard
Candlestick!
Posts: 251
Joined: Wed Jul 02, 2008 12:42 am UTC
Location: Outside of the box

Re: Coding: Fleeting Thoughts

Postby Wildcard » Thu Dec 17, 2015 4:06 am UTC

Ugh. Snake scrolling.

(1) Yes, that would be the most natural, and
(2) Yes, it would confuse the hell out of users. Anyone not super-technical (like my parents, for instance) would just be confused, because it no longer bears any resemblance to a piece of paper.

Personally, I like nice narrow columns, like what's used for Paul Graham's essays. Then I can just zoom in with my browser and get a comfortable large-text reading experience without scrolling sideways.
There's no such thing as a funny sig.

User avatar
ucim
Posts: 5570
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Coding: Fleeting Thoughts

Postby ucim » Thu Dec 17, 2015 5:19 am UTC

Wildcard wrote:(2) Yes, it would confuse the hell out of users [...] because it no longer bears any resemblance to a piece of paper.
A web page is not a piece of paper! Every time we make something more like something else, we destroy more of the value of that initial something. Case in point, frozen yogurt. Nowadays it's pointless - it tastes like ice cream. If I wanted ice cream, I'd have ice cream. But back when it started, frozen yogurt had this neat tang that made it a new and wonderful taste experience. Can't get that any more, they made it taste like ice cream. Another case in point, Google Docs. Every change they make makes it harder to use and makes it take longer to load. A simple document takes about fifteen seconds to find, get to, and load now. It used to be instant. On an older and slower machine. And don't get me started on the "new improved" Nissan Sentra. They took a wonderfully flexible body style (is that the right word for how configurable the interior was?) and made it an inferior copy of something they already make (the Altima). [/rant]
Spoiler:
Get off my lawn!
Wildcard wrote:Personally, I like nice narrow columns, like what's used for Paul Graham's essays. Then I can just zoom in with my browser and get a comfortable large-text reading experience without scrolling sideways.
Ugh. Narrow columns. Two thirds of the space on my monitor is wasted with that site and I can't get it back. Snake scrolling would put the whole document in front of me in an easy-to-read format.

And how long do you think it would take for people to get used to snake-scrolling? Maybe three or four encounters? We give people pictures of owls and birds and let them figure out what they mean... confusing the hell out of users until they figure out that first, it's not just a decoration, and second, where it takes you, and third, what it does when it takes you there.

Somehow they figured it out. Even I figured it out. :) They'll figure out snake-scrolling too, and then say "why didn't I think of that?"

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

commodorejohn
Posts: 958
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Thu Dec 17, 2015 5:30 am UTC

Yes, a web page is not a piece of paper, and trying too hard to make it one is the source of a lot of what's bad about the modern web. (Oh, for the days when people weren't constantly trying to format their pages to look like a print magazine!) But, as Dan Ingalls put it:
The mechanisms of human thought and communication have been engineered for millions of years, and we should respect them as being of sound design. Moreover, since we must work with this design for the next million years, it will save time if we make our computer models compatible with the mind, rather than the other way around.

However much theoretical sense it might make, it doesn't match up with the "usable by humans" criteria for good UI design, because it violates the principle of least surprise. (And no, I don't buy the "well just get used to it then!" argument. Yes, humans can acclimate themselves to be able to function in a very broad range of working environments, but "can work with it" rarely translates to "seriously comfortable with it," and humans will always, always work better in an environment they're actually comfortable with.)
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

User avatar
ucim
Posts: 5570
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Coding: Fleeting Thoughts

Postby ucim » Thu Dec 17, 2015 6:20 am UTC

Well, the principle of least surprise needs to be balanced against the principle of least annoyance, and also against the principle of increasing usefulness.

Least surprise hinders progress. Asymptotically, it makes new stuff the same as the old stuff, and thus pointless. Surprise is good when it opens doors. Surprise is good when it banishes annoyance. Surprise is good when, after being surprised, one thinks "Oh wow! I didn't know it could do that!

When I expect something lame, because everything before it was lame, and I find (to my surprise) that this thing is useful, I am pleased, and only wish I had discovered it before.

Actually, I think there's something else at work that is mis-identified as engendering the principle of least surprise; that is, clarity. To wit:

1: When you know how to use it it should be clear and easy and powerful. (Vim?) But also...
2: It shouldn't be difficult to learn how to use. (definitely not Vim!), and equally important...
3: It should be easy to find out how to learn how to use it. (Linux still fails here).

All other things being equal, the principle of least surprise should be considered, but it has a high cost. It enshrines "We already know a stupid way to do it, let's not change that." Progress requires surprise. Granted, not all surprise is good (Unity, I'm looking at you. And Windows 8. Ugh, what a surprise!) But it's important to realize that the bad part of "bad surprise" is "bad". Not "surprise". And there is good surprise too. That's what progress is all about.

Computers are powerful. People are smart (albeit mentally lazy). Don't sell either of them short.

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

User avatar
Wildcard
Candlestick!
Posts: 251
Joined: Wed Jul 02, 2008 12:42 am UTC
Location: Outside of the box

Re: Coding: Fleeting Thoughts

Postby Wildcard » Thu Dec 17, 2015 9:11 am UTC

I grant you your premise and raise you a hypothesis: Pretty much any wild new idea is okay provided there is an easily discovered way to turn it off. :)

I think the most immediate reaction to snake scrolling would be for the reader to think they are viewing normally-column-formatted text that is twice (or 3x or whatever) as long as it actually is. They would see two columns, scroll to the bottom and see how long it took them, and then think they are looking at an article twice as long as it really is. (Well, twice as long minus one page height.) But I suppose I can think of some good use cases for snake scrolling anyway....

ucim wrote:Granted, not all surprise is good (Unity, I'm looking at you. And Windows 8. Ugh, what a surprise!)
I hate Windows 8.

But you make me curious...given that I've hardly used the Linux GUI at all, and given that all of that has been in GNOME on CentOS, and given that I just today helped a close relative install Ubuntu...what should I beware of for the next few days in Unity? Mind writing a "spoiler'd for O.T." rant on the subject? :wink:
There's no such thing as a funny sig.

User avatar
ucim
Posts: 5570
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Coding: Fleeting Thoughts

Postby ucim » Thu Dec 17, 2015 4:07 pm UTC

Wildcard wrote:I grant you your premise and raise you a hypothesis: Pretty much any wild new idea is okay provided there is an easily discovered way to turn it off. :)
Wholeheartedly agree. It starts to become a bit problematic though when there are inherently a lot of fingers in the pie (web designer, browser, end user) each of which has opinions, and each of which is counting on the others to make some of the decisions for them. (That's kind of the whole point of layout in the first place!)

Wildcard wrote:I think the most immediate reaction to snake scrolling would be for the reader to think they are viewing normally-column-formatted text that is twice (or 3x or whatever) as long as it actually is.
No, I don't think so. And certainly not the second time they see it. If the article is long enough to scroll, the visitor will see new text come in at the bottom right, and disappear at the top left. It should be pretty clear what's happening because they'll see the text snake-move when it's scrolled.

To make snake-scrolling work, there would (of course) need to be an inner scrollbar, and the box would have a height (which shouldn't have to be specified beforehand, and could be the existing and resizable height of the viewport). Within that box the columns and inner-scollbar would be housed. Inner (snake) scrolling would not move the main window, just the text in the multicolumn box.

If the web page is big enough to require scrolling too (such as other stuff beneath the snake-scroll box), scrolling the page down would move the box, intact, along with the rest of the page. The text would not snake-scroll in that case.

Wildcard wrote:I hate Windows 8.

But you make me curious...given that I've hardly used the Linux GUI at all, and given that all of that has been in GNOME on CentOS, and given that I just today helped a close relative install Ubuntu...what should I beware of for the next few days in Unity? Mind writing a "spoiler'd for O.T." rant on the subject?
I won't spoiler it because it's not really a rant (well, ok, a little bit of one) and it's also a fleeting thought, and it's related. By Unity and Gnome I'm talking about the user interface, aka the desktop and the way one interacts with it. Ditto Windows-8 vs (say) Windows 98 or NT. I'm not talking about the underlying code. (Ok, it got a bit long. Spoilering. :) )
Spoiler:
Note: There is no "linux interface". Linux has and allows for many different interfaces (desktops*).

*Desktop means "the interface to linux" as well as having the other meaning "screen where you can see your icons and windows and such"

Anybetheway, my preference is for the computer to quietly do its thing, and not bother me. Gnome is great for that. The interface stays out of the way, and when I want to do something, it's a keystroke or mouse click away. I know what the keystrokes are, and I know which icon to click. The icons are small and out of the way. I can concentrate on my work. If the computer wants to tell me something, it "raises its hand" (perhaps by making in icon change color or something) and waits patiently for me to give it heed while still doing the things I am telling it to do.

There is however a growing trend in interface design that has the computer constantly interrupting my work, throwing things in my face and shouting "DO YOU WANT TO DO THIS THING? DO YOU? C'MON, SAY YES!", often with a modal window that demands that you drop what you're doing and stoke the machine's ego before you can continue your own work. Part of this is making things big and screen-filling (a reaction I suppose to the increasing size of desktop monitors and the increasing popularity of smartphones).

So here I am with Gnome, which I've been happy with for ages, and along comes this new thing which is throwing big pictures in my face when I don't need to see them because I know where the stuff is. And the first thing I discovered (I think it's fixed now - there's a hidden setting for it) is that I didn't have my desktops any more. "Unity" unified them all for me, so that when I shove something off the edge of one desktop, it reappears on the edge of another one where I didn't want it to be! And every time I wanted to change (what used to be) desktops, I got a bunch of giant windows thrown in my face from which to pick. It broke my workflow, I couldn't get out of it, and I couldn't figure out why they destroyed a perfectly good thing. Change for its own sake.

Now, to be fair, it turns out (at least those are the rumors!) that Unity does allow for different, separate desktops. They were just disabled by default (in my first frustrating experience), and some people claim to like it. I can even see that, if you know what's coming at you (and I think they aim it near your mouse), there could be less mouse moving to do stuff. But it involves learning a whole new system, and the old one was perfectly fine.

You might like it, since you are coming at it fresh. But for me, it's too "noisy". Things keep happening if my mouse goes too far one way or the other. So, I switched back to GNOME and have been happy ever since. (Note - to switch back to GNOME you have to do several things and it's not obvious you didn't do them all).

When I set up a computer, I put a text file (called "tweaks") somewhere in the Documents folder, and put a link to it on the desktop. There, I record all the things I did so that later, when I've forgotten, I can redo, undo, fix, whatever. I make notes there for every program I install. Here are the ones for GNOME on Ubuntu 14.04LTS for my machine (an ASUS laptop). Your mileage may differ.

added gnome desktop:
..sudo apt-get install ubuntu-gnome-desktop
....(had to sudo apt-get --reinstall install ubunto-gnome-desktop due to failed connection
..configured for gdm (as opposed to lightdm) when installed
..then (maybe I could have done this instead!) in the software center, added
....gnome-flashback
..Log out, then click on the ubuntu icon in the login screen to choose the desktop
added Full GNOME Desktop Environment, with extra components
..from Ubuntu software center
....search for "full gnome de". Typing more makes it disappear. Dunno why.


Windows 8 (ugh!) turns your 21 inch monitor into a smartphone display, covered with giant icons of things they want you to do. It takes me a minute or to for each application just to find the icon (and I know where they are now!). I have it on a dual-boot laptop; sometimes I need to use windows and I put on my rubber gloves, but otherwise it's GNOME all the way. :)
Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

Markus__1
Posts: 36
Joined: Wed Apr 20, 2011 6:42 pm UTC

Re: Coding: Fleeting Thoughts

Postby Markus__1 » Thu Dec 17, 2015 9:01 pm UTC

ucim wrote:... snake-scrolling: Imagine lots of text arranged in (e.g.) three columns. It still doesn't all fit, so the rest of the text is invisible "under" the third column. There is nothing "underneath" the other two columns - text continues from the bottom of the window of the first column to the top of the window of the second column, etc. If you leave everything alone, you read it as if it were laid out in three columns, all of which are visible.

The remaining text, is "under" the third column and thus not visible, is accessed by scrolling the inner scrollbar. That third column scrolls, revealing the remaining text. The text that scrolls off the top of the third column reappears at the bottom of the second column (which also scrolls), and the text that disappears at the top of the second column reappears at the bottom of the first one. The text that disappears at the top of the first one disappears like any other scrolled text.

The rest of the page remains static. The effect is that, at any point, the visible text is a contiguous part of the fulltext, displayed in three (in this example) columns.

Sure it's unusual because nobody's done it. But it's probably the most natural of the options, which is why I'm suggesting it. Consider the alternatives:

  • Vertical scrolling: Text is displayed in three (or whatever...) columns whose height may be greater than the viewport, and whose contents therefore require scrolling. Scroll down to see the rest of the (static) first column, and then scroll back up manually to see the start of the second column. Rinse, repeat.
  • Horizontal scrolling: Text is displayed in however many columns are needed given the height of the viewport. Read the first few columns normally, then scroll to the right to access the rest of the columns.

In all cases, the content will need to reflow if the viewport is resized; snake-scrolling would be no exception. But I think it's a significant improvement, and recommend that it be added as an option. Something like

<span style="column-width-min:25em; column-width-max:40em; scroll:snake;">lots of content</span>

The options for scroll would be "horizontal", "vertical", "snake". The web designer could decide what to suggest to the browser (and the browser, especially older ones, will be like unto the sea, and do what it wants anyway. :) )

Jose


Let me add another - similarly confusing - option:

  • Mixed scrolling (better name welcome): The layout is like with horizontal scrolling, but mouse-wheel scrolling switches to moving the columns horizontally while the column area fills the viewport. I'd also make the inner scollbar used to move the columns left-right vertical - a bit more confusing when first dragging it, but another hint that "scrolling through" with the mouse wheel is possible.
This is based on two observations: Up/down on a web page is almost synonymous to forward/backward in the displayed content; and the natural forward/backward direction in column text is left/right, not up/down.

Markus__1
Posts: 36
Joined: Wed Apr 20, 2011 6:42 pm UTC

Re: Coding: Fleeting Thoughts

Postby Markus__1 » Thu Dec 17, 2015 9:09 pm UTC

ucim wrote:Windows 8 (ugh!) turns your 21 inch monitor into a smartphone display, covered with giant icons of things they want you to do. It takes me a minute or to for each application just to find the icon (and I know where they are now!). I have it on a dual-boot laptop; sometimes I need to use windows and I put on my rubber gloves, but otherwise it's GNOME all the way. :)

Jose


Talk sternly to your Windows 8 about acting like a desktop operating system :D , i.e. install ClassicShell, and most of that annoyance goes away.

commodorejohn
Posts: 958
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Thu Dec 17, 2015 9:14 pm UTC

Markus__1 wrote:Talk sternly to your Windows 8 about acting like a desktop operating system :D , i.e. install ClassicShell, and most of that annoyance goes away.

Most, not all (it still has annoyances I can't figure out how to get rid of, like the fact that minimizing a window no longer sends it to the back of the Alt-Tab list, so you have to manually bubble-sort windows out of your way.) But yes, employ Classic Shell and you can get it acting almost like 7.
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

User avatar
ucim
Posts: 5570
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Coding: Fleeting Thoughts

Postby ucim » Fri Dec 18, 2015 12:48 am UTC

Thanks - I'll give Classic Shell a go next time I'm on Windows. :)

As to mixed scrolling; also sounds good.

I would say that the user (or browser) should be able to choose between mixed scrolling and snake scrolling, given that the inner box remains the same size during the operation. Snake scrolling gives the user finer control, mixed scrolling is probably easier on the rendering engine (and on the layout designer). I can't think of a reason why the web designer would insist on one over the other.

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

commodorejohn
Posts: 958
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Fri Dec 18, 2015 12:59 am UTC

ucim wrote:I can't think of a reason why the web designer would insist on one over the other.

Why do web designers insist on anything? Ego and laziness.

But yes, in a perfect world the choice of presentation really ought to be left up to the user, or at least the browser, and that goes for a whole lot of aspects of web design.
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

User avatar
ucim
Posts: 5570
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Coding: Fleeting Thoughts

Postby ucim » Fri Dec 18, 2015 3:04 am UTC

commodorejohn wrote:Why do web designers insist on anything? Ego and laziness.

But yes, in a perfect world the choice of presentation really ought to be left up to the user, or at least the browser, and that goes for a whole lot of aspects of web design.
No, I don't think so. Presentation is an important part of (some) content. The mistake web designers make isn't in choosing presentation, but in making their choice of presentation ignore the reality of the user environment.

Good website design is adaptive. This is what makes web design hard. When I visit a web page, I want good choices to have already been made. I don't want to have to make all those choices myself (and I couldn't make good choices anyway until I've seen the content in the first place).

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Fri Dec 18, 2015 12:53 pm UTC

FT: I recently compared a few memcpy() implementations and got some interesting results: A naive C implementation (gcc 4.8 with -O3) is just as fast as GLIBCs implementation (EGLIBC 2.19). Both are ~40% slower than quite trivial assembly implementations.

Source code:
Spoiler:

Code: Select all

#include <stddef.h>
#include <immintrin.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <iostream>

timespec diff(timespec end, timespec start) {
   timespec result;
   if(end.tv_nsec - start.tv_nsec < 0) {
      result.tv_sec = end.tv_sec - start.tv_sec - 1;
      result.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
   }else{
      result.tv_sec = end.tv_sec - start.tv_sec;
      result.tv_nsec = end.tv_nsec - start.tv_nsec;
   }
   return result;
}

void *naive_copy(void *__restrict dest, const void *__restrict src, size_t length) {
   char *dest_bytes = static_cast<char *>(dest);
   const char *src_bytes = static_cast<const char *>(src);
   for(size_t i = 0; i < length; i++)
      dest_bytes[i] = src_bytes[i];
   return dest;
}

void *movsq_copy(void *__restrict dest, const void *__restrict src, size_t length) {
   asm volatile ( "rep movsq" : : "D" (dest), "S" (src), "c" (length / 8) );
   return dest;
}

void *sse_copy(void *__restrict dest, const void *__restrict src, size_t length) {
   char *dest_bytes = static_cast<char *>(dest);
   const char *src_bytes = static_cast<const char *>(src);
   
   size_t offset = 0;
   while(offset < length) {
      double *dest_block = reinterpret_cast<double *>(dest_bytes + offset);
      const double *src_block = reinterpret_cast<const double *>(src_bytes + offset);
      auto r0 = _mm_load_pd(&src_block[0]);
      auto r1 = _mm_load_pd(&src_block[2]);
      auto r2 = _mm_load_pd(&src_block[4]);
      auto r3 = _mm_load_pd(&src_block[6]);
      auto r4 = _mm_load_pd(&src_block[8]);
      auto r5 = _mm_load_pd(&src_block[10]);
      auto r6 = _mm_load_pd(&src_block[12]);
      auto r7 = _mm_load_pd(&src_block[14]);
      auto r8 = _mm_load_pd(&src_block[16]);
      auto r9 = _mm_load_pd(&src_block[18]);
      auto r10 = _mm_load_pd(&src_block[20]);
      auto r11 = _mm_load_pd(&src_block[22]);
      auto r12 = _mm_load_pd(&src_block[24]);
      auto r13 = _mm_load_pd(&src_block[26]);
      auto r14 = _mm_load_pd(&src_block[28]);
      auto r15 = _mm_load_pd(&src_block[30]);
      _mm_stream_pd(&dest_block[0], r0);
      _mm_stream_pd(&dest_block[2], r1);
      _mm_stream_pd(&dest_block[4], r2);
      _mm_stream_pd(&dest_block[6], r3);
      _mm_stream_pd(&dest_block[8], r4);
      _mm_stream_pd(&dest_block[10], r5);
      _mm_stream_pd(&dest_block[12], r6);
      _mm_stream_pd(&dest_block[14], r7);
      _mm_stream_pd(&dest_block[16], r8);
      _mm_stream_pd(&dest_block[18], r9);
      _mm_stream_pd(&dest_block[20], r10);
      _mm_stream_pd(&dest_block[22], r11);
      _mm_stream_pd(&dest_block[24], r12);
      _mm_stream_pd(&dest_block[26], r13);
      _mm_stream_pd(&dest_block[28], r14);
      _mm_stream_pd(&dest_block[30], r15);
      offset += 256;
   }

   return dest;
}

void evaluate(const char *name, void *dest, const void *src, size_t length,
      void *(*function) (void *, const void *, size_t)) {
   std::cout << "Evaluating " << name << std::endl;

   timespec start, end;
   clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
   
   int num_iter = 40;
   for(int i = 0; i < num_iter; i++)
      function(dest, src, length);

   clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end);

   timespec elapsed = diff(end, start);
   std::cout << "    " << elapsed.tv_sec << "s, " << (elapsed.tv_nsec / 1000000) << "ms" << std::endl;
}

int main() {
   size_t length = 0x40000000;
   void *src = malloc(length);
   void *dest = malloc(length);

   evaluate("naive_copy()", dest, src, length, &naive_copy);
   evaluate("movsq_copy()", dest, src, length, &movsq_copy);
   evaluate("sse_copy()", dest, src, length, &sse_copy);
   evaluate("memcpy()", dest, src, length, &memcpy);
}

256/512-bit AVX instructions could be faster than the 128-bit SSE ones but my CPU doesn't support them.


Results:
Spoiler:

Code: Select all

$ g++ -std=c++11 -O3 -fno-builtin main.cpp
$ ./a.out
Evaluating naive_copy()
    4s, 672ms
Evaluating movsq_copy()
    2s, 916ms
Evaluating sse_copy()
    3s, 649ms
Evaluating memcpy()
    4s, 660ms

$ g++ -std=c++11 -O0 -fno-builtin main.cpp
$ ./a.out
Evaluating naive_copy()
    77s, 840ms
Evaluating movsq_copy()
    3s, 205ms
Evaluating sse_copy()
    6s, 594ms
Evaluating memcpy()
    4s, 997ms

-fno-builtin makes sure that gcc does not "optimize" the naive copy-loop by calling the memcpy() library function.
Note that my CPU has Intel's new "rep mosvq" implementation; on older CPUs the SSE version will outperform "rep movsq".
Also note that sse_copy() and movsq_copy() are not generic memcpy() implementations because they have stricter alignment requirements.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11045
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Fri Dec 18, 2015 1:10 pm UTC

You cannot get reasonably reliable results by tring a b c d in a fixed order. The before/after state of caches can impact performance, no? I guess you presume you are trashing the cache enough.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Fri Dec 18, 2015 2:16 pm UTC

Yeah, I'm transferring 1 GB of data so I assume that caching effects are irrelevant here.

User avatar
Jplus
Posts: 1692
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: Coding: Fleeting Thoughts

Postby Jplus » Sat Dec 19, 2015 10:45 am UTC

ucim wrote:
Wildcard wrote:I think the most immediate reaction to snake scrolling would be for the reader to think they are viewing normally-column-formatted text that is twice (or 3x or whatever) as long as it actually is.
No, I don't think so. And certainly not the second time they see it. If the article is long enough to scroll, the visitor will see new text come in at the bottom right, and disappear at the top left. It should be pretty clear what's happening because they'll see the text snake-move when it's scrolled.

No, no, no. As you previously described, text is coming in at the bottom of every column and disappearing at the top of every column. The user is focusing only on the first column (initially), so they can't see that the lines disappearing at the top of the second column are the same lines as those that appear at the bottom of the first column. It looks exactly like scrolling through columns that extend beyond the viewport in height. Then, when the first column doesn't scroll further (hits the "bottom"), depending on the semantics of snake scrolling, the user will either assume that they need to scroll back up to the "top" of the second column because the text stops abruptly (and then be frustrated because they find text they already read), or they will be surprised to find the end of the text and be confused about the reason for the second column to exist. Either way, any columns beyond the first will be mostly just adding noise.

Most readers will probably figure it out after a while, but I don't think anyone will turn to like it after the initial frustration. It's still essentially a vertical scrolling design, so it just doesn't add any value over a single column with vertical scrolling. Yes, you can put more text on the screen, but in this way it's just a noisy filler. I think everyone will be better off if you use the remaining space for other stuff. Like navigation, side remarks, references, illustrations, ads, and so forth.

To make snake-scrolling work, there would (of course) need to be an inner scrollbar, and the box would have a height (which shouldn't have to be specified beforehand, and could be the existing and resizable height of the viewport). Within that box the columns and inner-scollbar would be housed. Inner (snake) scrolling would not move the main window, just the text in the multicolumn box.

It will be impossible for users to distinguish this from existing effects where some part of the page scrolls but the rest doesn't. For example iframes, divs with overflow: scroll, and the sticky navigation header pattern. So this won't help users to figure out the semantics of snake scrolling.
"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined

(Julian/Julian's)

bittyx
Posts: 194
Joined: Tue Sep 25, 2007 9:10 pm UTC
Location: Belgrade, Serbia

Re: Coding: Fleeting Thoughts

Postby bittyx » Sat Dec 19, 2015 12:20 pm UTC

I think this is what's meant by "snake-scrolling: http://jsfiddle.net/qkv5ubub/ - is that correct?

I took the contents of the Wikipedia article on scrolling as an example. I didn't bother to deal with edge cases (such as getting to the "bottom" of the first column, which should in theory probably mean that the second column has to have one complete height of empty content added to the bottom, and the third one two of those, etc.), and I also didn't bother to hide the scrollbars, so it looks a bit ugly. But in general, it should demonstrate the mechanics of the idea (if I understood it at all) - and I must admit that I don't like it at all; it's very confusing and I have no idea where I am while trying to read the content.

User avatar
ucim
Posts: 5570
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Coding: Fleeting Thoughts

Postby ucim » Sat Dec 19, 2015 7:35 pm UTC

Yes, that's what I have in mind, but it's very important to hide the other scrollbars, and to ensure that the box fills the viewport vertically (I had to change the height to 100vh and the width to 49% in the css area (so two columns are fully visible). That is what is making it confusing; it was much clearer when that was fixed. When I first came to it I saw three separate scrolling windows that magically scrolled together, and I was confused. But if you ensure that you can't see the "lower" columns, and there is only one scrollbar, then I think it will be much clearer that when you get to the bottom of the first column, you just start reading at the next one.

(You could also optionally put a footer "continued next column" as a hint for early adopters).

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

User avatar
Robert'); DROP TABLE *;
Posts: 730
Joined: Mon Sep 08, 2008 6:46 pm UTC
Location: in ur fieldz

Re: Coding: Fleeting Thoughts

Postby Robert'); DROP TABLE *; » Mon Dec 21, 2015 12:52 am UTC

FT: Doing a recursive search to solve the n-queens problem and using futures to paralelize the branches turned out to be a lot slower than I was expecting. Although I guess since running this doesn't actually take up much CPU time, the problem is the scheduling rather than any ineffiency with the algorithm.

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace EightQueensFutures
{
    static class EightQueensFutures
    {
      static Stopwatch S = Stopwatch.StartNew();
      const int MAXLENGTH = 8;

      /// <summary>
      /// Stolen from Stack Overflow to theorectically produce a Task that returns the first result of a group of Tasks that match a given condition.
      /// </summary>
      static async Task<T> WhenAny<T>(IEnumerable<Task<T>> tasks, Predicate<T> cond, T defaultval)
      {

         var taskList = tasks.ToList();
         Task<T> completedTask = null;
         do
         {
            completedTask = await Task.WhenAny(taskList);
         } while (!cond(completedTask.Result) && taskList.Any());

         return (completedTask == null) ? return defaultval : completedTask.Result;
      }

      /// <summary>
      /// Return a new solution to the N-Queens problem
      /// </summary>
      /// <param name="existingMoves">Column indices so far specified</param>
      /// <returns>A string specifying one more column index, except if the input was a complete solution</returns>
      static string TryNewMove(string existingMoves)
      {
         if (existingMoves.Length > MAXLENGTH) throw new InvalidOperationException();
         if (existingMoves.Length == MAXLENGTH) return existingMoves;

         var possibilities = Enumerable.Range(1, MAXLENGTH).ToList();

         for (int i = 0; i < existingMoves.Length; i++)
         {
            var curVal = int.Parse(existingMoves[i].ToString());

            possibilities.Remove(curVal); // Remove same-row possibility.

            var diffWidth = (existingMoves.Length - i);

            possibilities.Remove((curVal + diffWidth)); // Upper-right diagonal.
            possibilities.Remove((curVal - diffWidth)); // Lower-right diagonal
         }

         if (possibilities.Count == 0)
         {
            Console.WriteLine("Stop");
            return null;
         }
         if (possibilities.Count == 1)
         {
            return TryNewMove(existingMoves + possibilities[0].ToString());
         }

         
         var newTasks = possibilities.Select(s => Task.Factory.StartNew(() => TryNewMove(existingMoves + s)));
         var tasks = WhenAny(newTasks, StringNotEmpty, null);
         return tasks.Result;
      
      }

      static bool StringNotEmpty(string s)
      {
         return !string.IsNullOrEmpty(s);
      }

      static void Main()
      {
         var r = TryNewMove("");
            Console.WriteLine("Answer: {0}", r);
      }
}
...And that is how we know the Earth to be banana-shaped.

Maelstrom.
Posts: 76
Joined: Tue Oct 21, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Maelstrom. » Mon Dec 21, 2015 11:49 am UTC

I've made some changes to the snake scrolling demo: the columns are now 100vh, automatically stretch to fill the width correctly, and all but the right-most scroll bar is hidden. Additionally, I've changed up the JS so the number of columns is automatically adapted to, as well as stopping a weird jankiness that happened due to conflicting updates of scrollTop.

Snake scrolling v2

I don't like it. Reading the first column, when I get to the bottom, I have a choice: either scroll the columns, or continue reading from the top of the next column. If I scroll the columns, there is no reason to read the second or third column until I get to the bottom, and suddenly cant scroll all the way (in an ideal implementation, see the note on unhandled behaviour above). This renders the second and third columns useless until right at the end. Alternately, if I continue reading from the next column and then the next, I eventually hit the bottom of the third column. I would then scroll the whole set of columns. What is my motivation for switching back to the first column, when I can continue reading the third column in the normal way?

In both cases, the extra two columns become visual noise that distracts me from reading the column that I am scrolling. There is no reason to scroll just one 'page' to reset the columns to read them left-to-right again when it is simpler to just scroll the one column. Additionally, scrolling just one page is quite difficult, as you have to remember where you were at the bottom of the third column, and carefully scroll the first column to just beyond this point. This is needlessly awkward compared to just scrolling a bit more content on the page as you would normally. Another issue is with half cut of lines of text, most noticeable with headings as they are larger. You cant read half a line of text easily, so you have to scroll just a little bit to get the rest of the text in to the column you're reading. You will probably have to do it again when you get to the bottom of the next column. Again, normal whole page scrolling avoids this as you can just scroll a whole bunch more content on to the screen at once.

User avatar
ucim
Posts: 5570
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Tail of the snake

Postby ucim » Mon Dec 21, 2015 4:29 pm UTC

I also dummied up a snake scrolling mockup using tables. You are right. Snake scrolling stinks, for all the reasons given.
Spoiler:
It looks different than it did in my mind, primarily in that in reality it's monolithic, and in my mind it played more like a snake, where each column would scroll in opposite directions. Visually that would get the metaphor across, but would obviously not work in reality. (However, maybe some kinetic eye-candy would make the difference - some sort of inbetween-the-columns animation showing the text "pouring" from one column to the other during a scroll - though this is antithetcial to my "keep it clean, quiet, and simple" design philosophy)
I withdraw my suggestion, but offer another - tail scrolling. Only the last column would scroll. The rest would be fixed.

Content would be laid out in columns, and if it all fit, great. If it didn't fit, the last column would contain (only) the remaining text, and scroll vertically.
Spoiler:

Code: Select all

(plug into the same jsfiddle)
CSS:
.col1, .col2{float:left;overflow-x:hidden; overflow-y:hidden;width:33%;height:100vh;}
.col3{float:left;overflow-x:hidden; overflow-y:scroll;width:33%;height:100vh;}


HTML (adjust the break points manually to fit your page to see the demo):
<div class="col1">
<h2>Computing</h2>

<p>Scrolling is often carried out on a computer by the CPU or a graphics card. In a WIMP-style graphical user interface (GUI), user-controlled scrolling is carried out by manipulating a scrollbar with a mouse, or using keyboard shortcuts, often the arrow keys. Scrolling is often supported by text user interfaces and command line interfaces. Older computer terminals changed the entire contents of the display one screenful ("page") at a time; this paging mode requires fewer resources than scrolling. Scrolling displays often also support page mode. Typically certain keys</p></div><div class="col2"><p>or key combinations page up or down; on PC-compatible keyboards the page up and page down keys or the space bar are used; earlier computers often used control key combinations.[notes 1] Some computer mice have a scroll wheel, which scrolls the display, often vertically, when rolled; others have scroll balls or tilt wheels which allow both vertical and horizontal scrolling.</p>

<p>Some software supports other ways of scrolling. Adobe Reader has a mode identified by a small hand icon ("hand tool") on the document, which can then be dragged by clicking on it and moving the mouse as if sliding a large sheet</p></div><div class="col3"><p> of paper. When this feature is implemented on a touchscreen it is called kinetic scrolling. Touch-screens often use inertial scrolling, in which the scrolling motion of an object continues in a decaying fashion after release of the touch, simulating the appearance of an object with inertia. An early implementation of such behavior was in the "Star7" PDA of Sun Microsystems ca. 1991–1992.</p>

<p>Scrolling can be controlled in other software-dependent ways by a PC mouse. Some scroll wheels can be pressed down, functioning like a button. Depending on the software, this allows both horizontal and vertical scrolling by dragging in the direction desired; when the mouse is moved to the original position, scrolling stops. A few scroll wheels can also be tilted, scrolling horizontally in one direction until released. On touchscreen devices, scrolling is a multi-touch gesture, done by swiping a finger on the screen vertically in the direction opposite to where the user wants to scroll to.</p>

<p>If any content is too wide to fit on a display, horizontal scrolling is required to view all of it. In applications such as graphics and spreadsheets there is often more content than can fit either the width or the height of the screen at a comfortable scale, and scrolling in both directions is necessary.</p>

<h3>Text</h3>

<p>In languages written horizontally, such as most Western languages, text documents longer than will fit on the screen are often displayed wrapped and sized to fit the screen width, and scrolled vertically to bring desired content into view. It is possible to display lines too long to fit the display without wrapping, scrolling horizontally to view each entire line. However, this requires inconvenient constant line-by-line scrolling, while vertical scrolling is only needed after reading a full screenful.</p>

<p>Software such as word processors and web browsers normally uses word-wrapping to display as many words in a single line as will fit the width of the screen or window or, for text organised in columns, each column.</p>

<h4>Demos</h4>

<p>Scrolling texts, also referred to as scrolltexts or scrollers, played an important part in the birth of the computer demo culture. The software crackers often used their deep knowledge of computer platforms to transform the information that accompanied their releases into crack intros. The sole role of these intros was to scroll the text on the screen in an impressive way.</p>

<p>Many scrollers were plain horizontal scrollers, but demo coders also paid a lot of attention to creating new and different types of scrolling. The characters could, for example, continuously alter their shape, take unusual flying paths or incorporate color effects such as raster bars. Sometimes it makes the text nearly unreadable.</p>

<h2>Film and television</h2>

<p>Scrolling is commonly used to display the credits at the end of films and television programs.</p>

<p>Scrolling is often used in the form of a news ticker towards the bottom of the picture for content such as television news, scrolling sideways across the screen.</p>

<h2>Video games</h2>

<p>In computer and video games, scrolling of a playing field allows the player to control an object in a large contiguous area. Early examples of this method include Taito's 1974 vertical-scrolling racing video game Speed Race, Sega's 1976 forward-scrolling racing games Moto-Cross (Fonz) and Road Race, and Super Bug.</p>

<p>Parallax scrolling, which was first featured in Moon Patrol, involves several semi-transparent layers, which scroll on top of each other at varying rates in order to give an early pseudo-3D illusion of depth. Belt scrolling is a method used in side-scrolling beat 'em up games with a downward camera angle where players can move up and down in addition to left and right. A previously much used alternative to video game scrolling is the flip-screen method.</p>
</div>
Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

User avatar
Wildcard
Candlestick!
Posts: 251
Joined: Wed Jul 02, 2008 12:42 am UTC
Location: Outside of the box

Re: Coding: Fleeting Thoughts

Postby Wildcard » Fri Jan 01, 2016 9:03 pm UTC

Fleeting Thought:

I can't imagine good software development done in the absence of at least an intuitive knowledge of the Basics of the Unix Philosophy, if not actual deliberate adherence to those principles.

Is there really any realm of software development where those basics don't hold true as excellent guidelines to follow? (I think probably not....)
There's no such thing as a funny sig.

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Coding: Fleeting Thoughts

Postby ahammel » Sun Jan 03, 2016 2:19 pm UTC

Wildcard wrote:Fleeting Thought:

I can't imagine good software development done in the absence of at least an intuitive knowledge of the Basics of the Unix Philosophy, if not actual deliberate adherence to those principles.

Is there really any realm of software development where those basics don't hold true as excellent guidelines to follow? (I think probably not....)

There is a great deal of demand among business users for software that tries to be all things to all people, rather than doing one thing well.
He/Him/His/Alex
God damn these electric sex pants!

KnightExemplar
Posts: 5489
Joined: Sun Dec 26, 2010 1:58 pm UTC

Re: Coding: Fleeting Thoughts

Postby KnightExemplar » Mon Jan 04, 2016 6:56 am UTC

Wildcard wrote:Fleeting Thought:

I can't imagine good software development done in the absence of at least an intuitive knowledge of the Basics of the Unix Philosophy, if not actual deliberate adherence to those principles.

Is there really any realm of software development where those basics don't hold true as excellent guidelines to follow? (I think probably not....)


Ah yes, like ioctl in Linux. :-)

I think there's a time and place for everything. When making Unix command line programs, what is said there is excellent. However, when making other programs (ie: Windows GUIs or Web Pages), a lot of that advice is irrelevant or worthless.

This is the Unix philosophy: Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.


Text Streams are no longer the universal interface, but likely JSON or REST. Creating a RESTful service is an easy business decision. In Windows, the universal interface is copy/paste and drag-and-drop. On iOS and Android, the universal interface is... erm... I dunno. Probably a database backend connected to a RESTful webservice.

But for Linux / Unix command line programs, yeah, be sure to make text streams and know how to manipulate them. Even then, Linux / Unix GUI programs probably want to work with drag-and-drop and copy-paste.
First Strike +1/+1 and Indestructible.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1397
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Mon Jan 04, 2016 10:01 am UTC

Wildcard wrote:Fleeting Thought:

I can't imagine good software development done in the absence of at least an intuitive knowledge of the Basics of the Unix Philosophy, if not actual deliberate adherence to those principles.

Is there really any realm of software development where those basics don't hold true as excellent guidelines to follow? (I think probably not....)

Code: Select all

> ls --help | wc -l
123
> man ls | wc -l
250

Oops?

Code: Select all

> man find | wc -l
1587

Oh god...

Basically, chaining together lots of little things gets really complicated and confusing, really fast.
So we compromise, make trade offs. We gravitate to a smaller number of more complicated tools.
A lot of the time, good software development is about making good trade offs.
Image

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Mon Jan 04, 2016 11:53 am UTC

KnightExemplar wrote:
Wildcard wrote:Fleeting Thought:

I can't imagine good software development done in the absence of at least an intuitive knowledge of the Basics of the Unix Philosophy, if not actual deliberate adherence to those principles.

Is there really any realm of software development where those basics don't hold true as excellent guidelines to follow? (I think probably not....)


Ah yes, like ioctl in Linux. :-)

perf_event_open() is also a beautiful linux system call.

KnightExemplar
Posts: 5489
Joined: Sun Dec 26, 2010 1:58 pm UTC

Re: Coding: Fleeting Thoughts

Postby KnightExemplar » Mon Jan 04, 2016 2:39 pm UTC

korona wrote:
KnightExemplar wrote:
Wildcard wrote:Fleeting Thought:

I can't imagine good software development done in the absence of at least an intuitive knowledge of the Basics of the Unix Philosophy, if not actual deliberate adherence to those principles.

Is there really any realm of software development where those basics don't hold true as excellent guidelines to follow? (I think probably not....)


Ah yes, like ioctl in Linux. :-)

perf_event_open() is also a beautiful linux system call.


The greatest part about reading through that documentation was realizing that everything is a file descriptor, and therefore the ioctl behemoth strikes again.

ioctl's job in Linux? Control File Descriptors. Everything is a file descriptor, so lets have a single function control any aspect of any file descriptor... except when you need to use netlink, or rtnetlink (ie: socket file descriptors, which are of course different from all the other kinds of file descriptors)

I think that the lesson here is that in practice, big projects tend to have a behemoth hiding somewhere... somehow. I've never managed a project the size of the Linux kernel before, so I really can't criticize the design decisions made there.
First Strike +1/+1 and Indestructible.

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Tue Jan 05, 2016 1:32 am UTC

Xenomortis wrote:

Code: Select all

> ls --help | wc -l
123
> man ls | wc -l
250
I'm actually surprised it's that small. If I copy and paste the ls section of the GNU coreutils manual into a text file and remove the navigation headers (initially keeping paragraphs all one line):

Code: Select all

evan@picard:~$ wc -l ls.txt
501 ls.txt
evan@picard:~$ fold -w 80 -s ls.txt | wc -l
732


And to me, ls is actually a great example of a place where the Unix philosophy of piping human-readable text around works extremely poorly. A significant majority of ls's options are violating "do one thing and do it well." For example, take sorting; more than 1/10 of the manual by lines is talking about ls's sorting. But why should it be sorting in the first place? We have a utility that sorts and sorts well... it's called sort! If the Unix philosophy actually worked well, we'd say something like ls | sort <something saying to sort by size or whatever> instead of ls --sort=size. But the fact that ls "has to" produce human-readable output means that there's no reasonable way to build that pipeline, which means that ls itself has to implement sorting. And so on for various other things, like timestamp formatting.

Another place I argue that many of the Unix utils should be built around outputting a semi-structured text format like JSON, which would actually allow you to start composing programs like this. I started working on that actually and got a couple things done, but I haven't done anything for years. (If I quit my job, maybe I'd have time for half of what I want to do. :-))

But the other thing is that, some of the time, you really do want to integrate things. And ls is also an example of this: because if you don't want to re-design the Unix command-line interface from the utilities at least through the shell, putting --sort into ls instead of a rigid adherence to the "do one thing" philosophy is the right thing to do.

Wildcard wrote:Is there really any realm of software development where those basics don't hold true as excellent guidelines to follow?


I think if really take a good look at the standard Unix utilities, one of two things is true: (1) a lot of Unix utilities (e.g. ls) do a poor job at following the Unix philosophy, or (2) the Unix philosophy needs to be broken frequently. I don't know where you'd fall between those decisions. :-)

So "follow"? No. "Bear in mind?" "Consider?" yes.

---

KnightExemplar wrote:The greatest part about reading through that documentation was realizing that everything is a file descriptor
...except for xattrs, because who knows. Apparently whoever designed them either forgot they were on Unix or actually hated the fact that they were adding support for them in the first place so deliberately did as bad of a job as they reasonably could.

(Unless there's some API for access I don't know about other than getxattr/setxattr.)

commodorejohn
Posts: 958
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Tue Jan 05, 2016 1:48 am UTC

My knowledge of the history of XWindows is sketchy, but I get the impression it was initially intended to be somewhat system-independent (I know it was ported to VMS at the least.) That might explain its detachment from Unix standards (and now I've gone and written the phrase "Unix standards" and I have to go laugh myself silly for the rest of the evening.)
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Tue Jan 05, 2016 2:52 am UTC

commodorejohn wrote:My knowledge of the history of XWindows is sketchy, but I get the impression it was initially intended to be somewhat system-independent (I know it was ported to VMS at the least.) That might explain its detachment from Unix standards (and now I've gone and written the phrase "Unix standards" and I have to go laugh myself silly for the rest of the evening.)
If that's meant to be a response to my xattrs comment, I was talking about extended attributes, not anything X Windows. So you literally have a file-like object on the disk and you can't get a file descriptor to it.

commodorejohn
Posts: 958
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Tue Jan 05, 2016 3:23 am UTC

Ah. My mistake.
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Tue Jan 05, 2016 12:10 pm UTC

Are there xattrs that store more than a few bytes of data? Otherwise a key-value based interface seems pretty okay to me.

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Tue Jan 05, 2016 12:52 pm UTC

korona wrote:Are there xattrs that store more than a few bytes of data? Otherwise a key-value based interface seems pretty okay to me.

First, it depends what you mean. Fixed size, no, but limited to a small size is common but not universal. Plenty of systems have arbitrary-length xattrs, including, on paper, ReiserFS and probably Reiser4 counts though it gets a bit weird. However, the Linux kernel imposes its own limit of 64K. But for example, Solaris supports arbitrary-length xattrs, and provides a file-descriptor interface to them. If you consider file system forks as an xattr on steroids, several other systems support those, including HFS, NTFS, ZFS, and Reiser4.

Second, I'd argue that the limited size is just another instance of Linux's xattr's poor design.

Third, it shouldn't even matter. If I implemented a special purpose file system that restricted file size to 64K for some reason, should I not use the usual file system API? And there are APIs out there that use file descriptors that have no information, e.g. inotify's watch descriptors are file descriptors for the purpose of being passed to select and such, but some have no information that can be read from them.

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Fri Jan 08, 2016 7:05 pm UTC

Maybe this is religious wars, but I'll put it here for now...

Goddammit C++ can be a terrible language sometimes. Some of this anger is directed at the fact that we're not using C++11 for some reason, but most of it C++98/03 deserves.

Code: Select all

template<typename T>
void foo() {
    // declare and value-initialize 'x' of type 'T'
}


How do you do it?

You can't, not without jumping through lots of hoops.

  • T x; fails for primitive types because it leaves them uninitialized,
  • T x(); fails because of the most vexing parse
  • T x(()); fails (even though adding an extra set of parentheses is the usual way to solve the most vexing parse) because the people writing the first standard had no idea what the hell they were doing (not the only example of this by any means, and yes, I'm aware that parens normally working to fix it is a side effect and not an official grammar feature)
  • T x = T(); officially requires T to be copy-constructable, and doesn't require the compiler elide the copy
  • T x = {}; doesn't work for classes with a default constructor
  • T x{}; is C++11-only

If you need to actually make it work generally, probably the best way is boost:

Code: Select all

#include <boost/utility/value_init.hpp>
template<typename T>
void foo() {
    T x = boost::initialized_value;
}


Let's see, how many lines of code do we need to make that work:

Code: Select all

$ cat boost.cpp
#include <boost/utility/value_init.hpp>
$ gcc -E boost.cpp -I third-party/boost | wc -l
14880
$ gcc -E boost.cpp -I third-party/boost | grep . | wc -l
10201
$ gcc -E empty.cpp | wc -l
6

So it only took 10,000 lines of code to declare an object in a template!

Good work C++. Truly the language for dedicated professional programmers.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11045
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Fri Jan 08, 2016 7:31 pm UTC

"T x = T(); officially requires T to be copy-constructable, and doesn't require the compiler elide the copy"
Ok, I've had it with people who say "elision is not required".

Know what else isn't required? That 1+1 doesn't email Obama and ask him for the answer prior to finishing the calculation. (Note that if the email contact fails, or times out (say, a few years), you do have to proceed with the local calculation).

Do you avoid integer addition because efficient integer addition "isn't required"?

Simple elision occurring reliably is a compiler-quality problem.

(But yes, it does require it be copy-constructable)
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Fri Jan 08, 2016 7:38 pm UTC

"It requires a copy constructor" is definitely the bigger objection there by a significant margin, though I'd argue that the copy-elision "optimizations" are of a much different character than most, in that they can actually change the non-timing semantics of your program. (In that sense, they're actually not really optimizations in the "common" sense of the word in a compiler sense.) According to the Boost docs, there are actually real-world compiler bugs with that solution as well, though the docs I was looking at were several years out of date.

At any rate, T x = T(); is the answer I went with in my case.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 5 guests