Programming thread

My school already taught QBasic before TP. I struggled to learn any other language after that, like an American monolingual.

To this day, BASIC is the only one I'm (somewhat) competent in.
BASIC was the first language I learned, and as if that wasn't bad enough I went on to learn PHP and Javascript.
 
Not strictly programming-related, but I've recently started using the keyboard more for everything (C-Tab to switch tabs, C-l or C-e to jump to the Omnibox, C-arrows to select / move / delete words and paragraphs instead of characters) and, wow, I've been doing it wrong this whole time. I'm sure that many of you spend at least as much time as I do in front of a computer, using a keyboard, so take some time out of your day to make sure you're getting the most out of the thing.

(I'd also recommend learning vim and/or emacs. I'm getting acquainted with the latter and it's an absolutely lovely tool for doing pretty much anything.)
 
Not strictly programming-related, but I've recently started using the keyboard more for everything (C-Tab to switch tabs, C-l or C-e to jump to the Omnibox, C-arrows to select / move / delete words and paragraphs instead of characters) and, wow, I've been doing it wrong this whole time. I'm sure that many of you spend at least as much time as I do in front of a computer, using a keyboard, so take some time out of your day to make sure you're getting the most out of the thing.

(I'd also recommend learning vim and/or emacs. I'm getting acquainted with the latter and it's an absolutely lovely tool for doing pretty much anything.)

I learned Windows back when having a mouse wasn't a guarantee, so the mouse clicks were taught as optional and the keyboard shortcuts were the first step. If you ever want to impress co-workers with how "good" you are at computers, making things happen magically without touching the mouse is the tech equivalent of making a quarter disappear then pulling it from your kid's ear.

On a related note, the first time I felt tech was moving in the wrong direction was when they started developing web pages with code that didn't jump between links in the correct order when you hit Tab. That forced to take my hand off the keyboard and use the mouse in my daily routine, and I'm still salty about it.
 
On a related note, the first time I felt tech was moving in the wrong direction was when they started developing web pages with code that didn't jump between links in the correct order when you hit Tab. That forced to take my hand off the keyboard and use the mouse in my daily routine, and I'm still salty about it.
Web pages in general just have way too much stuff to be able to navigate through it all using the keyboard. It would theoretically be possible to set up a sane tab order, but no one does.

A few sites (e.g. Gmail, Slashdot) have tried to come up with reasonably usable keyboard navigation systems, but the problem is that they're not standardized, so you have to remember a different navigation system for each site.
 
Web pages in general just have way too much stuff to be able to navigate through it all using the keyboard. It would theoretically be possible to set up a sane tab order, but no one does.

A few sites (e.g. Gmail, Slashdot) have tried to come up with reasonably usable keyboard navigation systems, but the problem is that they're not standardized, so you have to remember a different navigation system for each site.
Vivaldi has an optional feature called spacial navigation that lets you navigate with shift + arrow keys. It's disabled by default, but it works pretty well, mainly only has trouble with text boxes —which it gets stuck in— and things that react to hover. I frankly wish something like it was available everywhere as I too prefer the keyboard to the mouse.
 
Web pages in general just have way too much stuff to be able to navigate through it all using the keyboard. It would theoretically be possible to set up a sane tab order, but no one does.
Use Vimperator inspired extensions or browsers. You can navigate through web sites with your keyboard quicker than with a mouse with those.
 
Does anyone have any advice on writing lightweight and efficient programs for C / C++?

Profile your program, write micro-benchmarks for interesting sections, when you tweak those sections you can use those benchmarks as guidance.

Try to do syscalls/memory allocation/IO in as large chunks as is reasonable.
 
Not sure if this is the correct thread, but I just bought a board and it came from an area of the world no one should trust. Is there any way to sniff out any kind of malware before I start utilizing it?
 
Does anyone have any advice on writing lightweight and efficient programs for C / C++?
  • Pass objects by reference unless the function absolutely has to have its own copy.
  • Never use naked new/delete, use smart pointers instead
  • Just because a C library provides a C++ wrapper doesn't mean your C++ program has to use the wrapper. It might be more efficient to use the C interface directly.
  • Enable link time optimization
  • Order the member variables of classes and structs by their minimum alignment, in descending order
  • Avoid defining functions inside of headers unless you want that function to be inlined
 
  • Pass objects by reference unless the function absolutely has to have its own copy.
  • Never use naked new/delete, use smart pointers instead
  • Just because a C library provides a C++ wrapper doesn't mean your C++ program has to use the wrapper. It might be more efficient to use the C interface directly.
  • Enable link time optimization
  • Order the member variables of classes and structs by their minimum alignment, in descending order
  • Avoid defining functions inside of headers unless you want that function to be inlined
Building on this, @Megatorg you should familiarize yourself of the new r-value reference system too. Fundamentally it is meant to allow you to capture temporary values and avoid unnecessary copying, or having to const-qualify them. R-values are also part of the new move constructor system.

Move constructors allow for resource reuse, so for example move constructing a vector essentially takes the owned memory from the source, and nulls the source.
C++:
// We want to assign this vector
std::vector<int> a;
{
    // Temporary vector
    std::vector<int> b{1, 2, 3};

    // .... Do something complicated to b

    // Now we want to assign a from the results
    // a = b; // Will copy
    a = std::move(b); // Uses move assignment operator, does not create a copy of b
    // Effectively a is cleared, then a and b are swapped
    // A's destruction at this point has no side effects, because it has been cleared
}
// A now contains the contents of b


One other thing to consider is that references may be represented as pointers, and in such a case will likely be 4-8 bytes, where as a simple integer is just 4 bytes on most modern systems anyway and some types are even smaller. Generally, if your object is smaller or equal in size to a pointer, you might as well just pass it by value unless you actually need a reference.
 
Last edited:
Building on this, @Megatorg you should familiarize yourself of the new r-value reference system too. Fundamentally it is meant to allow you to capture temporary values, r-values let you capture temporary values without any copying, or without having to const-qualify them. R-values are also part of the new move constructor system.

Move constructors allow for resource reuse, for example move constructing a vector essentially takes the owned memory from the source, and nulls the source.
C++:
// We want to assign this vector
std::vector<int> a;
{
    // Temporary vector
    std::vector<int> b{1, 2, 3};
 
    // .... Do something complicated to b

    // Now we want to assign a from the results
    // a = b; // Will copy
    a = std::move(b); // Uses move assignment operator, does not create a copy of b
    // Effectively a is cleared, then a and b are swapped
    // A's destruction at this point has no side effects, because it has been cleared
}
// A now contains the contents of b
There's also copy elision, which is one of the exceptions to the as-if rule. The compiler is allowed to replace a copy assignment/construction with a move assignment/construction for optimization purposes, even if copying has observable side effects.
 
Not sure if this is the correct thread, but I just bought a board and it came from an area of the world no one should trust. Is there any way to sniff out any kind of malware before I start utilizing it?
They're not going to waste hardware rootkits on you unless you've done something to specifically cause them to believe you're worth wasting one on.
Every time they use one, they run the risk that that specific model can be identified and countered.
 
They're not going to waste hardware rootkits on you unless you've done something to specifically cause them to believe you're worth wasting one on.
Every time they use one, they run the risk that that specific model can be identified and countered.
Thanks, I feel better now that I know I'm too insignificant to waste money on.
 
Last edited:
Back