390 karma · joined April 17, 2014
AwesomenessT largerFunction(Foo1 foo1, Foo2 foo2)
{
ResultT1 result1 = [&] {
Bar bar = barFromFoo1(foo1);
Baz baz = bar.makeBaz();
return baz.awesome();
} ();
ResultT2 result2 = [&] {
Bar bar = barFromFoo2(foo2);
return bar.awesome();
} ();
return result1.howAwesome(result2);
}
Bonus: you can initialize 'const' variables with multiple statements: const auto values = [&] {
std::vector <int> v (n);
std::iota (begin (v), end (v), 0);
std::shuffle (begin (v), end (v), std::mt19937 {seed});
return v;
} ();Some end up being minuscule (I'm looking at a ~1px-wide ownCloud icon right now) and the location is definitely non-obvious. I didn't even know Gnome 3 had a system tray for about a month, until I accidentally pulled it up.
> alt+drag to move/resize windows
This is not enabled by default, and there's no way to enable it in the default settings manager. I think gnome-tweak-tool has added support, but I had to dig around in dconf to enable it not too long ago.
> even alt+tab don't work out-of-the-box
Alt-Tabbing in Gnome 3 is fscked. You're expected to use Alt-~ to switch between windows of the same "application," while Alt-Tab only switches between application-group-things. You can fix it with a plugin, but you have to fix it with a plugin. That's ridiculous.
> Window focus seems completely broken
New windows are sometimes raised above other windows. Sometimes they're raised below. Sometimes they have focus. Sometimes they don't. I've experienced this issue with other window systems too, though, so I don't know if Gnome is to blame for it.
> more often than not, their way has turned out pretty good
It's something of an 80/20 scenario: yes, most of "their way" is perfectly fine, but a good chunk of it just sucks. Worse, which chunk of it sucks is different for different people and for different reasons. For example, I can't stand workspaces, but I know people who swear by them. Conversely, a lot of people prefer the old program menus, but I like the incremental search Gnome uses.
This is a universal problem, and it's easily solved: give the user options. No matter how well you design an interface, it's going to be wrong in some way for someone. By all means, yes, ship sane defaults, but give your users the ability to control their workflows on their computers.
Thank you!
> a non-obvious spot
No kidding; the Compose key being an actual key, it really belongs with the rest of the keyboard mapping settings. I guess since they removed that section altogether, they had to stick it somewhere.
> It's also in a more traditional form in Gnome Tweak Tool.
Not anywhere I can see, but that's not a big deal.
A big one for me is keyboard input: at one point, I could use the Super key for whatever I liked, and I could easily set the right Alt key to be a Compose key. Now, there is no reclaiming the Super key from hard-coded shortcuts (Unity is even worse about this!), and the Compose key is outright missing from the keyboard settings menu.
The obvious fix is simply not to use Gnome. I'm personally partial to Openbox; it's amenable to customization in a way I don't think Gnome will ever be again. The problem is that with the flurry of new system(d?) technologies -- dbus, policykit, consolekit, who knows what the hell else -- nothing works. I can't even mount removable drives from any file manager under an Openbox session now. At the moment, Gnome is the only system sufficiently tightly coupled into this stuff to work at all, and that's frustrating.
Anyway, the problem with using assembly is that it imposes an artificial temporal total ordering on the actions being performed. Under temporal total ordering, the possibility of unsequenced actions disappears, and the message is lost.
>no-one outside of compiler developers has the right vocabulary for descriptions to work
There's nothing here specific to implementing compilers. There are a few uses of standardese and graph theory, but they're relatively basic concepts that are important to familiarize yourself with if you want to use tools like C++ effectively.
I personally find code like that harder to follow. The first version is clearer than the second (and you forgot to take the address of foo->bar->baz[i]).
You can also compile to assembly with -S. I think it's clearer that way.
foo->bar->baz[i]
unless "meep" has side effects.To address the question, these some of the guidelines I try to follow:
- Compile with "-Wall -Wextra" (and "-pedantic" if feasible)
- Modularize your code. You can always mark functions "static inline."
- Don't try to be clever; "Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?" In fact, Kernighan has a lot of good advice: https://en.wikipedia.org/wiki/The_Elements_of_Programming_St....
- Be careful with signed integers. Overflow can do weird things to your program. You can make signed integers act like unsigned integers on overflow using -fwrapv, but if that behaviour is correct, you probably should have used an unsigned integer outright.
- Be careful with pointers; specifically, the requirements of any pointer passed to a function should be explicitly documented: whether it is allowed to be null, whether it's an "in" parameter or an "out" parameter, whether it points to one object or an array, etc. If a pointer points to an array, carry a length parameter with it; null-termination is really easy to foul up.
- Don't optimize until the program needs to be faster. When it does, profile and target the low-hanging fruit. Personally, I usually use either -O0 or -Ofast, depending on whether or not I'm debugging something (-Og is a good one if you need speed while debugging).
- Speaking of optimization, don't underestimate the power of inlining. It's easy to go overboard with it, but it can make a big difference in the right situations.
- Your compiler probably has a peephole optimizer. Replacing "i / 16" with "i >> 4" is probably not an improvement to the quality of either the source code or the object code.
- If you find yourself reimplementing something that C++ knows how to do, consider using C++ to do that. It's not always politically feasible, but remember that you can link C and C++ code.
You do. Yes, there's LTO, but to do it effectively relies on storing source code or information derived from it in the intermediate object files. Without the source, the best you can do is try to inline what is hopefully a reasonably well-behaved hunk of object code without any of the high-level information associated with it that the compiler threw away when it emitted it.
>C++ has many faults, but overhead with the C FFI is not one of them [...]
I'm not sure exactly what you mean, but if you're talking about the runtime overhead of calling an extern C function, then that is very much a fault. Inlining can make all the difference in the world with respect to performance in an inner loop, the classic example being qsort and std::sort, and to take advantage of that, source-level compatibility is needed.
Now, if you said that source-level compatibility were better achieved using a fully-fledged FFI than by stuffing all but the worst (well, some of the worst) of C into your language, I would whole-heartedly agree with you. If C++ had done the former, it would be a much cleaner, much less popular language, and instead of using a warty language with templates, useful user-defined datatypes, and function overloading, we'd all be using a warty language without templates, useful user-defined datatypes, or function overloading. Hell, many of us still do anyway.
>ABI compatibility
In other words, conversion overhead and indirection, respectively. There is no substitute for having an inline definition available at the point of use.
It doesn't take much experience with C to appreciate something of the magnitude of difficulty of keeping a million lines of C UB-free. I'm not in the security field, but if the code there is anything like the codes I've worked with, I'd be surprised to find even a "security-critical" C program of any appreciable complexity that doesn't invoke undefined behaviour.
>Every time you write '+' in a C program between two signed values, do you do an overflow check beforehand?
Personally? I use signed scalar arithmetic very rarely. The bulk of the arithmetic I do is with unsigned integers (bit vectors, really) and arbitrary-precision integers. In fact, essentially the only time I do use signed scalar arithmetic is when I can determine statically that it won't overflow. Signed integer overflow is a bitch, UB optimizations or no.
>Or do you do a global dataflow analysis of the program to prove that it can't overflow?
That's the basic idea behind seL4, for example.
>Arguing for a technical correctness that is observably almost impossible to achieve in the wild is what's really pointless.
Sure, but only because everyone writes their security-critical programs in a language that couldn't more effectively impede security if it were designed to do so. Could a "friendly" dialect help? Maybe, but the proposed changes are far from sufficient to make formal verification feasible, and frankly, I don't know how seriously I can take "security-critical" without formal verification.
No, that one's a consequence of C's insane type system. The solution here isn't to change the semantics of signed integer arithmetic. The solution is to change integer promotion to use unsigned arithmetic like it should have done in the first place.
That's not a problem. That's a good thing.
>Such optimizations can cause very strange, unintuitive behavior that is very difficult to discover
That's a problem -- or at least the "difficult to discover" part is. "Strange" and "unintuitive" is helpful; it's a nice, big red flag. How does migrating from undefined behaviour to producing unspecified values make bugs easier to discover? I can see how they would make results more consistent, and the bugs easier to hunt down, but that's only useful once you know the bugs are there (inconsistency is another useful red flag here), and there are already good tools like valgrind and ubsan for tracking down the source of the bug.
>The goal of this proposal is to make them wrong in reasonable ways
That isn't the purview of C, though. It's a noble goal, don't get me wrong, but stepping on the optimizer's toes and reinforcing plainly bad programming practices -- I know that's not an intended effect, but it will happen -- isn't the way to do it. A better way, just as an example, would be to give the programmer a proper mechanism for encoding preconditions and other interprocedure-analysable constraints. This doesn't reinforce bad practices, it could actually help the optimizer if done right, and would perhaps encourage programmers to reason a little more rigorously about their code -- an ounce of prevention and all that.
It makes it possible to use C definitions directly and inline with no conversion overhead or indirection. When your work is writing fast code, the ability to leverage existing fast code damned well is a feature.
>C++ is like mold >you don't want it, precisely because this is the most efficient life form compatible with your stale food
You don't want mold because it causes respiratory and neurological problems. C++ does not cause respiratory or neurological problems, unless you count the insanity it inherited from C like, "A character is the same thing as a byte," "A pointer is the same thing as an array" (which isn't even actually true within the language, unless you count parameter declarations), and my personal favourite, "The mathematical value of false, the cardinality of the empty set, and the identity of nothing are all the same thing. After all, they have the same representation!"
Granted, not everything listed stops at unspecified behaviour. I'm not convinced that that's a good thing, though. Even something like giving signed integer overflow unsigned semantics is pretty effectively useless. Sure, you can reasonably rely on twos-complement representation, but that doesn't change the fact that you can't represent the number six billion in a thirty-two bit integer, and it doesn't make 32-bit code that happens to depend on the arithmetic properties of the number six billion correct just because the result of multiplying two billion by three is well-defined.
Then there's portability. Strict aliasing is a good example of this. Sure, you can access an "int" aligned however you like on x86. It'll be slow, but it'll work. On MIPS, though? Well, the compiler could generate code to automate the scatter-gather process of accessing unaligned memory locations. This is C, though. It's supposed to be close to the metal; it's supposed to force-- I mean, let you do everything yourself, without hiding complexity from the programmer. How far should the language semantics be stretched to compensate for programmers' implicit, flawed mental model of the machine, and at what point do we realize that we already have much better tools for that level of abstraction?
For example, moving forward a character is C-f, moving forward a word is M-f, and moving a balanced expression forward is C-M-f. Same with b for backwards movement. C-a moves to the previous beginning-of-line, C-e to the next end-of-line. M-a and M-e do the same with statements in place of lines.
I can't even remember at this point how much of this is standard, but I've replicated the forward/backward movement for killing: C-d deletes a character forward, M-d kills a word, and C-M-d an expression. C-h deletes a character backward. Guess what M-h and C-M-h do.
Of course, both editors let you do basically whatever you want, so really the text input issue is just one of whether you prefer chording or modal input. And I'm not saying modal input isn't useful; Magit's input system is closer to vim's than to the rest of Emacs, as is Ediff's, and I like it that way, but I prefer chords for editing -- less state to hold in my head.
Sequential chords, though, like C-c C-v C-d, are right out, and using C-n and C-p and co. for up and down sucks, especially when I try to use M-p to select the last input in minibuffer history and hit M-o instead, prompting me to select Bold, Italic, or Other. I'll change them eventually; the hardest part is deciding what to replace them with.
/aimlessramble. I guess it all just boils down to "Use the tool you can best configure to work the way _you_ want it to." I think the linked article was trying to make the case that Emacs can be that tool for vim users.
Personally, though, I don't find the worst strain comes from the placement of Ctrl. The worst comes from the awful staggered layout of keyboards that serves no purpose save for a long chain of HCI backwards compatibility with the typewriter. I hope someday keyboards like the TEK (which, incidentally, gives a perfect spot for Alt or Ctrl under the left thumb) become more commonplace, or eye movement-based systems supplant the use of one's hands for focus control.
Emacs, as has been said time and again, is not a text editor. It is, if anything, a development shell. It contains a text editing program (the default program), and that program does not manage child processes or SSH or Git.
You could also take the stance that Emacs _is_ a program that "does one thing well:" develop programs. That's the actual task of importance. Text editing is a secondary, ancillary task that owes its importance entirely to the archaic practice of representing complex interrelationships between data and operations on those data as a static linear stream of ASCII-encoded bytes.
Unfortunately, almost all programming languages are like this (hence, "languages"), but if you ever use Emacs to edit Lisp, you'll find that it's far less like text editing than it is like directly manipulating the abstract structure of the program. It does a reasonable job trying to replicate this experience in other languages, but when you have utterly inane constructions like seventeen-precedence-level infix notation, there's only so much you can do.
Is constantly hitting the Escape key (even remapped to Caps Lock, or using ^[) really any better on your pinky?
There's also whether the probability of a crash occurring on any given day is actually 1/365, but that's another issue.
Then there's the fact that Emacs really isn't an editor. If anything, it's a shell that runs elisp programs, chief among which is a text editor. Programs like magit and ansi-term (and gnus and compile and dired and TRAMP and…) are good examples of this.
I couldn't count the number of times I've been writing C or C++ and wished I could express an idea more complex than "Initialize some variables (which may or may not be of the same type (but not of arbitrary different types)); run while this is true; do this thing after every iteration" without just slapping everything into and in the immediate vicinity of a while-true block. I don't have that problem with LOOP.
As for verbosity, I'll take ":accessor foo" over methods "getFoo" and "setFoo" with inane, useless autogenerated comments any day of the week.
Of memory. Any other resource, you've basically got C with UNWIND-PROTECT and a cheap Schrödingerian knock-off of destructors.