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.
Excuse me if i use the wrong wording. But there is a tree of data-structures. And Scala did it very fine. But one does not want to use Kotlin. Sorry i know nothing about C++ , but there is always dynamic & static. Meaning it can grow or it can grow not.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.
Yeah, sure. I believe you not.not wanting to hack this thread
R5RS Scheme specification is 50 pages.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.
Speaking of different collection classes, here is a psychological test whether you are "compatible" with C++:
This is like collecting & (may be) reading a whole bunch of books on carpentry, instead of spending the bulk of one's time wood working and building stuff! Programming has a lot more in common with carpentry than mathematics. Building stuff, making mistakes and learning from them is part of the process. You can read books *later*, to organize what you learned. Embrace the phrase "learning by doing"!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)
(Typed) racket , will read it. "The racket guide, 400 pages, more than worths its price".R5RS Scheme specification is 50 pages.