attn cpp coders

Fortunately, C code is usually clean, clear, readable and understandable. For example, it should be obvious that the following (valid) C program ...
No longer valid as of GCC 14 / Clang 16 (which started enforcing C99):
😞
define _ -F<00||--F-OO--;
There's a hash (#) missing at the beginning of this line

Compiling with -fpermissive I get:
Code:
$ gcc -fpermissive foo.c 
foo.c: In function 'main':
foo.c:3:12: warning: implicit declaration of function 'F_OO' [-Wimplicit-function-declaration]
    3 | int main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO()
      |            ^~~~
foo.c:3:19: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
    3 | int main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO()
      |                   ^~~~~~
foo.c:1:1: note: include '<stdio.h>' or provide a declaration of 'printf'
  +++ |+#include <stdio.h>
    1 | #define _ -F<00||--F-OO--;
foo.c:3:19: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
    3 | int main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO()
      |                   ^~~~~~
foo.c:3:19: note: include '<stdio.h>' or provide a declaration of 'printf'
foo.c: At top level:
foo.c:3:50: warning: return type defaults to 'int' [-Wimplicit-int]
    3 | int main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO()
      |                                                  ^~~~
$ ./a.out 
0.250
 
I think Python is gross, but I'm just a weak-minded Java programmer. I can probably be ignored safely.

I recently ran into something like this at work:
Python:
def __getattr__(self, name: str):
        # If class is extened, or name doesn't start with query_by_
        if self.__class__ is not DatabaseTable or not name.startswith("query_by_") or not name[9:]:
            raise AttributeError(f"{name} not found")
        bin = name[9:]
        schema: DatabaseSchema = self.__dict__.get("schema")  # type: ignore
        if bin not in schema.index_keys:
            raise AttributeError(f"Index not found for attribute {bin}")

        def func(
            value: str | int | None = None,
            modifier: Callable[[Query], None] | None = None,
            policy: dict | None = None
        ) -> Iterable[DatabaseResponse]:
            return self.query(bin=bin, value=value, modifier=modifier, policy=policy)
        return func

Maybe you're smarter than me and what this does is intuitively obvious to you.
Hello Jose, I am not a Python programmer and i have yet to read anything about this language. I'm assuming it is Python and i get a headache looking at this code. C, C++ and Java are more like PHP and i feel more comfortable working with these languages. However, if you want an answer, then i will post a guess as to what it is doing:

a class to check attributes of a database and its schemas?
checking an attribute string via slice starting at index 9?
containing a boolean testing the object is callable?
containing a boolean testing if the object is iterable?
error handling is self-explanatory

intelligence has nothing to do with it. One may not be able to understand someone elses code if one has not learned the language or learned the language well enough. But reading and understanding someone elses code can oftentimes be like a heavyweight fight without the gloves.

I will now post some of my dirty php code and see if you can guess what it is doing. My point is that whenever we are coding as part of a team, then we need to code with other coders in mind. obscurity is very bad. keep it clean and understandable.

Code:
function name_is_concealed_for_this_thread($m, $n, $v, $mp, $np) {
  $mt = (array) ['d' => 'center', 't' => (array) []];
  $half = floor(($v + 1) / 2); $halves = $half + 1;
  $t1 = $half - floor($half / $m);
  $t2 = $t1 + 1; $t3 = $t1 + $n; $t4 = $t3 + 1;
  switch ($np) {
    case 0:
      if ($mp) { $mt['d'] = 'vertical'; $mt['t'][$t1] = $t1; $mt['t'][$t3] = $t3; break; }
      $mt['t'][$half] = $half; break;
    case 1:
      if ($mp) { $mt['t'][$t1] = $t1; $mt['t'][$t2] = $t2; $mt['t'][$t3] = $t3; $mt['t'][$t4] = $t4; break; }
      $mt['d'] = 'horizontal'; $mt['t'][$half] = $half; $mt['t'][$halves] = $halves; break;
  } return $mt;
}
 
Jose is the specialist here detecting how you can abuse any language. And he is right. Any language can be abused. Even ADA.
But with this thinking in mind, you will never learn any language as all can be abused. So you must make a choice.
- Start with python if you want to create something quick (& a bit dirty), as as far as i know , no static type checking, and probably a garbage collector running in the background.
- Start with C if you want to learn internals, yep, the kernel is written in C.
- Start with C++ if you need Classes e.g. for developing a GUI application using QT6.

Me , i use NIM or DLANG when I can, but then the user base is low & no professional uses it.
Both languages have compile time static type checking , NIM has reference counting I think & DLANG optional garbage collection.
And neovim-qt editor is fantastic, coloring , code completion, info about libraries,functies,types of these functions, errors as you type.
When the editor says ok, 99% chance , program compiles to a runnable executable without any error.
 
Jose is the specialist here detecting how you can abuse any language. And he is right. Any language can be abused. Even ADA.
But with this thinking in mind, you will never learn any language as all can be abused. So you must make a choice.
- Start with python if you want to create something quick (& a bit dirty), as as far as i know , no static type checking, and probably a garbage collector running in the background.
- Start with C if you want to learn internals, yep, the kernel is written in C.
- Start with C++ if you need Classes e.g. for developing a GUI application using QT6.

Me , i use NIM or DLANG when I can, but then the user base is low & no professional uses it.
Both languages have compile time static type checking , NIM has reference counting I think & DLANG optional garbage collection.
And neovim-qt editor is fantastic, coloring , code completion, info about libraries,functies,types of these functions, errors as you type.
When the editor says ok, 99% chance , program compiles without any error.
Hello Alain De Vos, thanks for the advice:) I appreciate you taking time to reply. Also, i am somewhat aware of Jose. I have seen threads where he has posted and he is very knowledgeable. Actually, alot of members in this forum are quite capable coders :)
 
Well we can guide you to tiktok & twitter (joke).
Here a link why i personally like neovim-qt,
 
I would do a quick experiment with both (C++ and Python). Make a very simple program that reads pixels in from OpenCV and displays them on a simple GUI window. This is useful because it gives you a taster of setting the project up and how dependencies will be handled for each.

  • If you find the effort comparable, then I would go with C++. As mentioned it may be a bit slower to get started with but the quality of output will be higher and more resilient.

  • If you find yourself struggling, then I would stick with Python. You don't want to get bogged down with some of the nonsense C++ creates when your purpose is to make the program itself.
excellent advice. Thank you for your time and effort in this thread. I appreciate you very much.

I am going to read some more books today and then start tinkering with code.

I want to learn C++ regardless. I have much interest in continuing my education. I once played with assembler language to get an idea of how it works but i never got around to learning C or C++. Web Development has kept me chained to HTML, CSS, JavaScript and PHP. I once learned QBasic when i was using Windows 98 but Microsoft languages are disturbing in my opinion. I stay away from MS code.
 
just one note, thickness of books give an indication time needed to learn a language
- C Programming a modern approach, by K.N. King, 800 pages.
- Programming principles and Partice Using C++ , by Bjarne Stroustrup the inventor of C++ , 600 pages but multiply by a factor 2 , as it's rigorous and might need two passes to grasp the intent.
- Mastering Nim, A complete guide to the programming languge , by Andreas Rumph, 300 pages.
 
Alain De Vos i am not familiar with Nim. I've never heard of it until now.

regarding C++ books, i have the following books:
The C++ Standard Library (Nicolai M. Josuttis)
Data Structures and Algorithm Analysis in C++ (Mark Allen Weiss)
C++ Data Structures (Nell Dale)
The C++ Programming Language (Bjarne Stroustrup)
A Tour of C++ (Bjarne Stroustrup)
Programming Languages C++ ISO/IEC 14882
An Introduction to Programming with C++ (Diane Zak)
Modeling Derivatives in C++ (Justin London)
C++ for Engineers and Scientists (Gary R. Bronson)
C++ for Everyone (Cay Horstmann)
Cross-Platform Development in C++ (Syd Logan)
C++ for Mathematicians (Edward Scheinerman)
C++ Solutions for Mathematical Problems (Arun Ghosh)
C++ The Complete Reference (Herbert Schildt)
C++ 20 The Complete Guide (Nicolai M. Josuttis)
C++ How to Program (Paul Deitel, Harvey Deitel)
C++ Network Programming (Douglas C. Schmidt, Stephen D. Huston)
C++ Primer (Stanley B. Lippman, Josee Lajoie, Barbara E. Moo)
API Design for C++ (Martin Reddy)
Expert C++ (Marcelo Guerra Hahn, Araks Tigranyan, John Asatryan, Vardan Grigoryan, Shunguang Wu)
Effective Modern C++ (Scott Meyers)
 
Haha, just like me but worse , for me it would be,
1. C++ primer
2. Effective modern C++
3. Datastructures and Algoritms.

The rest for the library, reference , too look, when i hit something.
 
Most of the time, just use std::vector. It beats everything else hands down most of the time. Quite often you can use std::vector instead of any of the map/set containers (typically when you have an integral index that is contiguous). std::flat_map and std::flat_set are also good choices.

You need to take care of std::vector insertion resulting in iterator invalidation.

When the key is either non-integral or there are large holes in the range then you will need the map/set containers.

You will rarely or never need to use deque, stack, queue or priority queue. The performance of std::list is so bad that you will only ever need it if you are splicing many large objects into the middle or beginning of the container.

I haven't played with it yet, but C++26 added std::hive which should have most of the benefits of std::list (stable iterators and lower cost insertion) without the large memory overhead, spending vast amounts of time in new/delete and chronic memory fragmentation.
 
Back
Top