Now draw a circle , any gui-toolkit, using C & Python 
No longer valid as of GCC 14 / Clang 16 (which started enforcing C99):Fortunately, C code is usually clean, clear, readable and understandable. For example, it should be obvious that the following (valid) C program ...
There's a hash (define _ -F<00||--F-OO--;
#) missing at the beginning of this line-fpermissive I get:$ 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
Ah! No problem. The code is commented.... calculates pi.
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: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.
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;
}
Hello Alain De Vos, thanks for the adviceJose 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.
excellent advice. Thank you for your time and effort in this thread. I appreciate you very much.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.