Azadi
You should not modify the object in operator+
It modifies the current (lhs) object. Because the objection is to add the rhs object to it.
Danya🔥
Mehrad
a + b Do you expect a to be changed in this expression?
i agree when you write something as method form it does not mean your must modify the caller method object
Ehsan
It modifies the current (lhs) object. Because the objection is to add the rhs object to it.
This is how you do it correctly: T operator+(const T& rhs) const { T result = *this; // add rhs to result return result; }
Ehsan
What you did is modify the operand and also you don't really add anything you are just returning *this unmodified, also it will cause problems if the two added objects are the same
Danya🔥
why ?
Because implicit conversions are error-prone
Ehsan
why ?
because not all compilers are the same
Danya🔥
because not all compilers are the same
What does that suppose to mean?
Azadi
a + b Do you expect a to be changed in this expression?
No, you're right. I confused it with += operator.
Danya🔥
What does that suppose to mean?
Implicit conversions are part of the language we call C++ and are mandated by the standard, so they behave exactly the same everywhere expect the compiler bugs But I don't think there are a lot of bugs related to them because it's the core of language from the very beginning.
Mehrad
Because implicit conversions are error-prone
so you need use explicit keyword for every type that has been decalared
Danya🔥
so you need use explicit keyword for every type that has been decalared
For almost every type yeah You should mark all the single parameter constructors explicit of almost all types This should be the default way to write code And you have to put a lot of consideration on removing the keyword for the specific use of it
Danya🔥
Only the feature itself
Ehsan
I see thanks for the info
Danya🔥
I see thanks for the info
Use clang-tidy even if you don't compile with clang
AlanCcE
If your talking about Data Science you should use Python
Manuel
If your talking about Data Science you should use Python
Why not bringing data science back to C?
Danya🔥
Why not bringing data science back to C?
When was C used for data science?
klimi
When was C used for data science?
what's wrong on using C for data science
Manuel
could be used for data science on the edge, on IoT devices etc.
Danya🔥
what's wrong on using C for data science
The right question is "what's wrong on using C" And the answer is "everything"
Manuel
if it was possible to use Fortran on embedded devices it would be even better, but C is already very efficient
Morocos
Why is Fortran better than C?
Danya🔥
Why is Fortran better than C?
Because it has more science-related capabilities built-in
Danya🔥
But both languages are not great
Manuel
Why is Fortran better than C?
Better at dealing with vector, matrices etc. due to its memory management (essentially the reason why Lapack etc. have been developed in Fortran)
Danya🔥
if it was possible to use Fortran on embedded devices it would be even better, but C is already very efficient
Why do you need data science on such edge where you can't even use Fortran?
Danya🔥
Isn't the better solution to do this on more capable hardware?
Manuel
because 1) it's faster (no network latency for bringing the data on the cloud) 2) it's more energy efficient 3) more reliable and 4) those are resources that are yet under-utilized
Manuel
like esp32, like stm, like many things
Azadi
This is how you do it correctly: T operator+(const T& rhs) const { T result = *this; // add rhs to result return result; }
Yes, it's one of the ways for that purpose and likely one of the easiest things I'm dealing with in C++ on a daily basis. But the shit issue happens when you see + as +=.
klimi
what's bad on calculating the mean in C?
AlanCcE
Why not bringing data science back to C?
It's nice as hobby or as way of learning something different, but if his intention is to work with it it's better to do it in Python
AlanCcE
When was C used for data science?
A long time ago some people used to do some really badass stuff in Data Science, people in old days were like mages haha
Danya🔥
Danya🔥
Yet it's offtop
AlanCcE
I am not sure, data science in Python in pretty crowded and reaching its limits
Your right! But he has freedom to try it I think, if it's really his interest
Manuel
(don't get me wrong, I have been teaching data science in Python, I am not against it, but now every kid and his grand-ma can do a .fit() and .predict() with scikit-learn)
Manuel
Hi
Hi
Anonymous
Hi
Can you teach me coding Am actually a beginner
Manuel
Depends how much you pay me 😆
Danya🔥
Do the business outside of this chat
Azadi
Is sending code disallowed here?
Mehrad
Is sending code disallowed here?
the same problem 👍🏻
Houdaifa
Question about memory managment When you quit a program how the OS can know what memory spaces to free ? In the case when you declare variables on the runtime and lose thier adress
Danya🔥
What does "declare variables on the runtime" mean?
Houdaifa
What does "declare variables on the runtime" mean?
using "new" or "malloc"
Danya🔥
using "new" or "malloc"
It's not related to variable declaration whatsoever
Houdaifa
Because OS allocates the memory and then gives you the pointer
so the OS have a copy of all the pointers ?
XOFF
You dont declare a var when calling new or malloc
XOFF
In a way…
XOFF
OS has your virtual memory page
Danya🔥
OS manages all the resources pf your process: memory, files, pipe, you name it It's one of the essential characteristics of OS
Houdaifa
It's not related to variable declaration whatsoever
I mean by that it is obvious in the case of static and global and local variables because it is esay to group them and free them but when you are using linked list the memory is not consecutive so the OS in this case must store every pointer and I think this is a lot of wasted space
XOFF
My friend you should look for fragmentation, paging, memory pools and memory managements
Houdaifa
I learn this from wikipidia and I feel I am far from understanding it
XOFF
Unfortunately i would do the same thing you would basic Google search and reading lots of stack over flow posts
Danya🔥
can you give me some good resources for this ?
Some books or university courses on OS
XOFF
Nope if you dont need deep understanding