MaryAux
Posts: 5
Joined: Wed May 05, 2021 6:20 am

For beginners

Sat May 08, 2021 10:10 am

Guys, i think about start learning C++. It really interest me but i don't know anything about programming. I have just some knowledge about HTML and it's all. Can you suggest me some really useful courses for begginers, or may be a good video tutorials. Cause what i found on youtube is too complicated to understand who doesn't know anything about it.
:) Keep calm and travel the world ;)

User avatar
B.Goode
Posts: 12085
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: For beginners

Sat May 08, 2021 10:16 am

MaryAux wrote:
Sat May 08, 2021 10:10 am
Guys, i think about start learning C++. It really interest me but i don't know anything about programming. I have just some knowledge about HTML and it's all. Can you suggest me some really useful courses for begginers, or may be a good video tutorials. Cause what i found on youtube is too complicated to understand who doesn't know anything about it.

Pleased to hear of your success with HTML.

Maybe see:
https://magpi.raspberrypi.org/books/essentials-c-v1

https://magpi.raspberrypi.org/books/c-gui-programming

dsyleixa123
Posts: 1482
Joined: Mon Jun 11, 2018 11:22 am

Re: For beginners

Sat May 08, 2021 10:56 am

additionally to the both links above i found this one helpful:
https://www3.ntu.edu.sg/home/ehchua/pro ... asics.html

and for checking usage of arbitrary function syntax (manual + example code) plus tutorial:
https://www.cplusplus.com/
https://www.cplusplus.com/reference/clibrary/
https://www.cplusplus.com/doc/

fizzyade
Posts: 52
Joined: Wed Aug 14, 2019 10:34 am

Re: For beginners

Sat May 08, 2021 11:40 pm

Any particular reason for picking C++ to learn programming with?

I've been writing C++ for 35 years on embedded and desktop platforms. It's not the easiest language to get to grips with as you delve deeper into the rabbit hole. You have to deal with pointers a lot, even experienced programmers can make mistakes with them if you end up with a complex "chain of pointers".

There was a time when every little utility I wrote was done in C++, but I have moved to use Python for those because the libraries that are available for it are vast and provide massive shortcuts, it also enforces white space, which means you get into the habit of properly formatting code from the start.

Heater
Posts: 18252
Joined: Tue Jul 17, 2012 3:02 pm

Re: For beginners

Sun May 09, 2021 2:18 am

I also ask is there any particular reason for picking C++ to learn programming with?

I would really advise agains selecting C++ (or C) as a first programming language to learn. There is a reason what you found on YouTube to be too be complicated, C++ is a very large and complicated programming language. Starting to program with C++ when you only just mastered a little HTML is like trying to learn Calculus when you have only just learned how to count. Not only is the language complicated, if you type in some incorrect code the error messages it will produce can be very hard to understand if you are not used to such things. Not only that, if your program builds without error it is still prone to crash or produce wrong results when you run it.

In recent decades millions of people have started in programming with languages that are much simpler to understand from the get go. Where you can become familiar with the very basic concepts of programming without having to deal with a lot of complicated and arcane language syntax and the mechanics of just building a program from your source code at all.

Python is a big one of those. If you are into HTML and want to do web page things then Javascript is an excellent starter language. There are thousands of books tutorials, blogs and YouTube videos on beginning with these languages.


When you have mastered one of those then you may want to move on to something more sophisticated. Especially if you find you need better performance or run into the fact that creating large programs in languages like Python or Javascript starts to be problematic.

Now a days the Julia language is attracting a lot of Python users. Has a much nicer syntax and performs very well.

Even then I would be wary of suggesting C++. The Rust language is a good modern alternative which can deliver the same performance but is much more logical and has excellent error messages to guide you along as you learn.
Memory in C++ is a leaky abstraction .

dsyleixa123
Posts: 1482
Joined: Mon Jun 11, 2018 11:22 am

Re: For beginners

Sun May 09, 2021 8:27 am

I have to disagree, C++ is not so ugly as it had been stated if you do not want to learn all and everything of the overwhelming C++ features but instead start using handsome high level libraries and focus on learning by doing for your arbitrary project of interest (improving your C ++ skills as you gradually expand your project features).
Not to forget to mention, that C++ (gcc/gpp) is successfully used on all the Arduino boards (both on puny AVR boards and up to powerful dual core ARM Cortex or espressif tensilica boards and even the new Raspberry Pi Pico) providing millions of step-by-step-tutorials and enough driver libs to sink a ship, simply to include and ready to use.
It provides a user- and beginner-friendly API and IDE, uses legal C++ coding, and I think it might be the right way to start learning a monster PL like C++ because you do not have to mess around with the cumbersome and nasty Linux OS underneath and the lack of beginner support. The simplified C++ API wrappers, the handsome IDE (editor + compiler-interface, no awkward makefiles) and the tons of libraries for every conceivable target application are the reason for the world-wide tremendous success of Arduino, made for beginners, hobbyists, do-it-yourselfers, and makers, even as it uses C++.
OTOH, for the Raspberry Pi even a simple and user-friendly C/C++ GPIO interface is missing (there once was wiringPi, remotely similar to the convenient Arduino syntax, but even that meanwhile has been abandoned...).
Of course it depends on what you want to use C++ for in the end, but even by the Arduino platform you can build and control anything from a RFID-controlled cat door flap or an automatic irrigation system, up to mobile SLAM robots, webservers/clients, IoT smart home applications, all by C++, and you will sorely miss all of this comprehensive library range when you try to create either project on a Raspberry Pi.

User avatar
jahboater
Posts: 7075
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: For beginners

Sun May 09, 2021 9:41 am

MaryAux wrote:
Sat May 08, 2021 10:10 am
Guys, i think about start learning C++. It really interest me but i don't know anything about programming.
I believe the most popular teaching language these days is Python.
Python is included with Raspberry Pi OS, installed and ready to use, so its easy to get started.
There is also vast amount of help and the coding examples for use with the Pi are frequently written in Python.
Python and its libraries are very capable. The only downside of Python is poor performance compared to the compiled languages like C or C++. But that should not matter while learning to code!

C and C++ are also available, ready to use, on the Pi.
These require much more understanding of "how things work" in a computer, but give great speed and power in return.
These languages have been around for a very long time and a vast amount of software is written in them.
Start slowly (with C perhaps), write simple programs, making sure you fully understand everything about the code you are writing.
At first with these languages you may get crashes or strange errors, so learning the "debugger" would be helpful (gdb).
These languages use the standard Linux development support tools, which is a good thing.

Python and C/C++ are the two most popular languages on the Pi and that is, in itself, very helpful.

The Raspberry Pi can run countless other languages of course.
More modern languages such as Rust, D, and others also work fine but will require separate installation.
These languages, especially Rust, should give you more support, detecting more errors for you which is always a good thing.

On the Pi, you may even write code easily in assembler (the assembler is also pre-installed).
For fun (only) you might like to write a few lines of assembler as that will give you a good appreciation of how the Pi processor works, and also why languages such as C are so fast. Assembler is the actual machine instructions in a human readable form.
Don't write real programs in assembler of course.
Last edited by jahboater on Sun May 09, 2021 9:46 am, edited 1 time in total.

swampdog
Posts: 698
Joined: Fri Dec 04, 2015 11:22 am

Re: For beginners

Sun May 09, 2021 9:46 am

It's the errors where C++ falls down. I contrived this as an example..

Code: Select all

#include <string>

int
main()
{
 std::string s(0);
 return 0;
}
..hoping for a cryptic template error. However, what I got was a even worse - no error but a runtime..

Code: Select all

foo@pi18:/wrk $ ./c
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_M_construct null not valid
Aborted (core dumped)
Okay..

Code: Select all

foo@pi18:/wrk $ ulimit -c unlimited
foo@pi18:/wrk $ g++ -o c -O0 -g -DDEBUG -Wall -pedantic -ansi -Werror d.cc
foo@pi18:/wrk $ ./c
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_M_construct null not valid
Aborted (core dumped)

foo@pi18:/wrk $ gdb ./c core
GNU gdb (Raspbian 8.2.1-2) 8.2.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./c...done.
[New LWP 18028]
Core was generated by `./c'.
Program terminated with signal SIGABRT, Aborted.
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50	../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0xb6bf9230 in __GI_abort () at abort.c:79
#2  0xb6e538d8 in __gnu_cxx::__verbose_terminate_handler() ()
   from /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
#3  0xb6e515b0 in ?? () from /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
#4  0xb6e51624 in std::terminate() ()
   from /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
#5  0xb6e51990 in __cxa_throw ()
   from /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
#6  0xb6e7a234 in std::__throw_logic_error(char const*) ()
   from /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
#7  0xb6ee5c10 in void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>(char const*, char const*, std::forward_iterator_tag) () from /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
#8  0xb6ee5d90 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) ()
   from /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
#9  0x000106a4 in main () at d.cc:6
(gdb) q
foo@pi18:/wrk $
..because basic_string(char const*..) took that zero to be NULL.

We can get the complex template error I was initially looking for by passing a char..

Code: Select all

#include <string>

int
main()
{
 std::string s('0');
 return 0;
}

Code: Select all

foo@pi18:/wrk $ gcc -c d.cc
d.cc: In function ‘int main()’:
d.cc:6:19: error: no matching function for call to ‘std::__cxx11::basic_string<char>::basic_string(char)’
  std::string s('0');
                   ^
In file included from /usr/include/c++/8/string:52,
                 from d.cc:1:
/usr/include/c++/8/bits/basic_string.h:614:9: note: candidate: ‘template<class _InputIterator, class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(_InputIterator, _InputIterator, const _Alloc&)’
         basic_string(_InputIterator __beg, _InputIterator __end,
         ^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:614:9: note:   template argument deduction/substitution failed:
d.cc:6:19: note:   candidate expects 3 arguments, 1 provided
  std::string s('0');
                   ^
In file included from /usr/include/c++/8/string:52,
                 from d.cc:1:
/usr/include/c++/8/bits/basic_string.h:576:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
       basic_string(basic_string&& __str, const _Alloc& __a)
       ^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:576:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/8/bits/basic_string.h:572:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
       basic_string(const basic_string& __str, const _Alloc& __a)
       ^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:572:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/8/bits/basic_string.h:568:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::initializer_list<_Tp>, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
       basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
       ^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:568:7: note:   no known conversion for argument 1 from ‘char’ to ‘std::initializer_list<char>’
/usr/include/c++/8/bits/basic_string.h:541:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
       basic_string(basic_string&& __str) noexcept
       ^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:541:7: note:   no known conversion for argument 1 from ‘char’ to ‘std::__cxx11::basic_string<char>&&’
/usr/include/c++/8/bits/basic_string.h:529:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, _CharT, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]’
       basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
       ^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:529:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/8/bits/basic_string.h:514:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ <near match>
       basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
       ^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:514:7: note:   conversion of argument 1 would be ill-formed:
d.cc:6:19: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive]
  std::string s('0');
                   ^
In file included from /usr/include/c++/8/string:52,
                 from d.cc:1:
/usr/include/c++/8/bits/basic_string.h:499:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]’
       basic_string(const _CharT* __s, size_type __n,
       ^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:499:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/8/bits/basic_string.h:481:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]’
       basic_string(const basic_string& __str, size_type __pos,
       ^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:481:7: note:   candidate expects 4 arguments, 1 provided
/usr/include/c++/8/bits/basic_string.h:465:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]’
       basic_string(const basic_string& __str, size_type __pos,
       ^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:465:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/8/bits/basic_string.h:450:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]’
       basic_string(const basic_string& __str, size_type __pos,
       ^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:450:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/8/bits/basic_string.h:437:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
       basic_string(const basic_string& __str)
       ^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:437:7: note:   no known conversion for argument 1 from ‘char’ to ‘const std::__cxx11::basic_string<char>&’
/usr/include/c++/8/bits/basic_string.h:429:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
       basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT
       ^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:429:7: note:   no known conversion for argument 1 from ‘char’ to ‘const std::allocator<char>&’
/usr/include/c++/8/bits/basic_string.h:420:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
       basic_string()
       ^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:420:7: note:   candidate expects 0 arguments, 1 provided
This is why C++ is hard and not for the novice. Imagine all the things they have to already know to figure out that 0 typo should be "0" and not '0'. ;-)

User avatar
jahboater
Posts: 7075
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: For beginners

Sun May 09, 2021 9:53 am

swampdog wrote:
Sun May 09, 2021 9:46 am
This is why C++ is hard and not for the novice. Imagine all the things they have to already know to figure out that 0 typo should be "0" and not '0'. ;-)
Yes indeed, that's awful.

Perhaps start with C where strings are very simple and the error messages are much easier to understand.

fizzyade
Posts: 52
Joined: Wed Aug 14, 2019 10:34 am

Re: For beginners

Sun May 09, 2021 10:36 am

dsyleixa123 wrote:
Sun May 09, 2021 8:27 am
I have to disagree, C++ is not so ugly as it had been stated if you do not want to learn all and everything of the overwhelming C++ features but instead start using handsome high level libraries and focus on learning by doing for your arbitrary project of interest (improving your C ++ skills as you gradually expand your project features).
Not to forget to mention, that C++ (gcc/gpp) is successfully used on all the Arduino boards (both on puny AVR boards and up to powerful dual core ARM Cortex or espressif tensilica boards and even the new Raspberry Pi Pico) providing millions of step-by-step-tutorials and enough driver libs to sink a ship, simply to include and ready to use.
It provides a user- and beginner-friendly API and IDE, uses legal C++ coding, and I think it might be the right way to start learning a monster PL like C++ because you do not have to mess around with the cumbersome and nasty Linux OS underneath and the lack of beginner support. The simplified C++ API wrappers, the handsome IDE (editor + compiler-interface, no awkward makefiles) and the tons of libraries for every conceivable target application are the reason for the world-wide tremendous success of Arduino, made for beginners, hobbyists, do-it-yourselfers, and makers, even as it uses C++.
OTOH, for the Raspberry Pi even a simple and user-friendly C/C++ GPIO interface is missing (there once was wiringPi, remotely similar to the convenient Arduino syntax, but even that meanwhile has been abandoned...).
Of course it depends on what you want to use C++ for in the end, but even by the Arduino platform you can build and control anything from a RFID-controlled cat door flap or an automatic irrigation system, up to mobile SLAM robots, webservers/clients, IoT smart home applications, all by C++, and you will sorely miss all of this comprehensive library range when you try to create either project on a Raspberry Pi.
It is, however, a poor choice as a language for somebody learning to code though, there are much better languages than C++ for that purpose.

Python is a much more suitable language because it forces the programmer to structure their code correctly right from the start, that's one of the biggest issues that people have when learning to code with c++, if you can't read your own code then you're heading for trouble.

Which dialect of C++ do you choose 98, 11, 14, 17, 20? If you choose 20, don't be surprised if you write valid C++20 code that doesn't compile because your compiler doesn't implement the entire specification. This is unimportant to somebody learning to code, they need to learn the basics of coding, not the basics of managing a toolchain. Python is not devoid of this to some degree, but installing a recent version of Python 3 is simple if your distribution has an older version.

My current personal project, pingnoo (https://github.com/nedrysoft/pingnoo if anybody wants to look at the code) is written in C++ with a load of python scripts dotted around the script that are utilities for handling things such as creating deployable images, setting up build environments and so on, there's no chance I'd implement those in C++, Python is a much better choice. As a recent example, pingnoo is Qt-based, and I made a decision recently to support a few older Linux distributions (including Raspbian stretch), the issue I had is that I had made use of several C++17 features, the main one being nested namespaces, I had to refactor the code from:

Code: Select all

namespace MyProject::MyClass {
    // C++17 and later
}
to:

Code: Select all

namespace MyProject { namespace MyClass {
    // All earlier C++ standards
}}
I'm a huge fan of C++, I've written it for 35 odd years, I've worked commercially on everything from embedded medical instruments to projects in formula 1 to radar signal processing software to CAD software, but I wouldn't recommend it as a language for a beginner, there's zero point making things hard for yourself when learning the basics.

I've taught a few people to code and I find it hard to get through the frustration that I see people learning C++ and programming at the same time experience, that's with just the very basics, once you start putting in pointers and more complex aspects of C++ people start to melt.

Then you can find things in the language that are just plain old weird.

Code: Select all

void weird_definition() try {
    // trying something
} catch (...) { 
    // catch something
}
Learn the fundamentals of programming in the easiest manner possible, and then take those skills and learn other more complex languages, you wouldn't learn to juggle and unicycling at the same time.

dsyleixa123
Posts: 1482
Joined: Mon Jun 11, 2018 11:22 am

Re: For beginners

Sun May 09, 2021 10:45 am

structuring one's C++ code is no issue if you learn C++ by Arduino tutorials.
And I finally abandoned Python when I needed 2D and 3D float (double) arrays, lots of variable type declarations and castings, and multiple realtime rotation encoder readings for robot navigation.

Heater
Posts: 18252
Joined: Tue Jul 17, 2012 3:02 pm

Re: For beginners

Sun May 09, 2021 6:20 pm

dsyleixa123 wrote:
Sun May 09, 2021 10:45 am
structuring one's C++ code is no issue if you learn C++ by Arduino tutorials.
That's because you are not really learning C++ by using the Arduino tools.

The Arduino is a wonderful thing but for a beginner programmer with a Raspberry Pi there are some issues:
1) One needs and Arduino and the desire to hook up LEDs and such to get it going. None of that Arduino code works on a Pi.
2) What one learns on Arduino is not C and it's hardly C++. It is of no use on anything else.

Since the days of BASIC a common requirement for a beginner language has been to require the student to know as little as possible to get something meaningful done in the first few minutes. Typically with a "Hello World" program. Typically just typed into the system with instant feed back. No distraction of compilation or messing with editors and files. After that the ability to quickly try out and experiment with code as one learns is thought to be a good idea.

We can still use BASIC for that of course. But the modern alternatives are things like Python, Javascript, Julia.

I think anyone who is used to making web pages would so well to start programming with Javascript. It's a natural and builds on what they already know. Also can be used interactively like BASIC if they install node.js.

Julia takes a bit of effort to get installed and working on the Pi so that pretty much brings us to Python as the "least friction" language for the raw beginner. Not ideal but there we go.
Memory in C++ is a leaky abstraction .

dsyleixa123
Posts: 1482
Joined: Mon Jun 11, 2018 11:22 am

Re: For beginners

Sun May 09, 2021 6:30 pm

Heater wrote:
Sun May 09, 2021 6:20 pm
dsyleixa123 wrote:
Sun May 09, 2021 10:45 am
structuring one's C++ code is no issue if you learn C++ by Arduino tutorials.
That's because you are not really learning C++ by using the Arduino tools.
I have to disagree, by Arduino (and NXC) tutorials I learned programming mobile SLAM robots with multiple sensors, an AStar (Dykstra) for route finding, an autonomous chess engine, and also neural backpropagation nets in C and C++, even I managed to develop own classes for button presses and TFT menus, and for those purposes my C and C++ knowledge I learned by Arduino is sufficient 8-)
(not to forget, I even could port some of the Arduino progs to the Pi)
Last edited by dsyleixa123 on Sun May 09, 2021 6:35 pm, edited 1 time in total.

User avatar
jahboater
Posts: 7075
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: For beginners

Sun May 09, 2021 6:34 pm

dsyleixa123 wrote:
Sun May 09, 2021 6:30 pm
Heater wrote:
Sun May 09, 2021 6:20 pm
dsyleixa123 wrote:
Sun May 09, 2021 10:45 am
structuring one's C++ code is no issue if you learn C++ by Arduino tutorials.
That's because you are not really learning C++ by using the Arduino tools.
I have to disagree, by Arduino tutorials I learned programming mobile robots with multiple sensors, a autonomous chess engine, and also neural backpropagation nets in C and C++, even I managed to develop own classes for button presses and TFT menus, and for those purposes my C and C++ knowledge I learned by Arduino is sufficient 8-)
What if you don't have an Arduino and have no intention of buying one?

User avatar
jahboater
Posts: 7075
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: For beginners

Sun May 09, 2021 6:37 pm

Heater wrote:
Sun May 09, 2021 6:20 pm
Julia takes a bit of effort to get installed and working on the Pi
The latest release 1.6.1 that came out a few days ago, now has ready to go binaries for the 32-bit Pi if you want to try it.
ARMv7 hard-float - perhaps they provided it specially for the Pi!!
Aarch64 has always been available.
Last edited by jahboater on Sun May 09, 2021 6:41 pm, edited 1 time in total.

dsyleixa123
Posts: 1482
Joined: Mon Jun 11, 2018 11:22 am

Re: For beginners

Sun May 09, 2021 6:41 pm

What if you don't have an Arduino and have no intention of buying one?
an Arduino compatible board (e.g., a Nano or an esp8266) costs <5 EUR, providing all pins (GPIOs, i2c, UART, SPI) and/or even WiFi features one needs (e.g. IoT Smart Home control via website and a Smartphone) or for mobile robots, all by C++. A RaspberryPi Pico is a little more expensive but also works with the Arduino IDE and the Arduino libs via C++.
But finally it depends of course on what actual project one wishes to develop (programming multi-user database engines, image processing, and building operating systems of course are out of the scope of Arduinos)
Last edited by dsyleixa123 on Mon May 10, 2021 9:16 am, edited 1 time in total.

Heater
Posts: 18252
Joined: Tue Jul 17, 2012 3:02 pm

Re: For beginners

Sun May 09, 2021 7:01 pm

Like I said. Arduino is a wonderful thing. Especially if you are all kitted out with a robot and/or a pile of sensors and things to play with. And that is the direction one wants to go.

My point was that for someone who has never programmed before all of that is a lot more expense and faffing around with things they likely have no idea about than just typing 'python3' and then '"Hello world"' on a Pi or whatever computer they have. With that, in no time at all they are experimenting with expressions, variable, conditionals, loops, functions....

Similarly with Javascript and Julia.
Memory in C++ is a leaky abstraction .

User avatar
MikeDB
Posts: 511
Joined: Sun Oct 12, 2014 8:27 am
Contact: Website

Re: For beginners

Mon May 10, 2021 10:51 am

Isn't Geany and gcc also pre-installed on a Pi ? I don't recall installing them when I started with it, though it's a long time ago. So a C or C++ program to say Hello World shouldn't be any slower to get going. And you'd be learning a language that almost every company in the world uses, against one which a lot of companies specifically ban any use of even for prototyping :-)
Always interested in innovative audio startups needing help and investment. Look for me on ModWiggler or other sites that have PMs.

dsyleixa123
Posts: 1482
Joined: Mon Jun 11, 2018 11:22 am

Re: For beginners

Mon May 10, 2021 10:53 am

yes, Geany and gcc are preinstalled, and with Geany it's exactly the way I'm always building my Raspi C and C++ projects.
Geany is also used in the Raspi magpi tutorials https://magpi.raspberrypi.org/books/essentials-c-v1

Return to “C/C++”