What Makes C++ "Hard"?

Go To Last Post
186 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

C++17 will be along shortly cheeky

 

(that was one of my points above - this language is still "growing" so every 3 years there's going to be new stuff to learn).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh, sorry - I said C++14 above but meant C++17. No, designated initializers didn't make it into C++17 as far as I know.

 

The workgroup(s) are done, there is a last draft for the standard released: http://www.open-std.org/jtc1/sc2...

 

I would be very surprised to see anything but minor corrections/adjustments.

 

Next tentative standard is C++20, IIRC.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Mon. Jul 24, 2017 - 10:06 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
Next tentative standard is C++20, IIRC.
Bound to be - they have now entered a pattern of every 3 years so 11, 14, 17, 20, 23, 26, 29, ....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
I *liked* that C++ was supposed to be a superset of C

I'm not sure that was ever actually true?

 

They certainly shared a (large) common subset - but  I didn't think C++ was ever a strict superset of C ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
westfw wrote:
I *liked* that C++ was supposed to be a superset of C

I'm not sure that was ever actually true?

 

They certainly shared a (large) common subset - but  I didn't think C++ was ever a strict superset of C ... ?

'Twas supposed to be close,

hence the name.

Never was exactly.

There were always programs valid as C and as C++, but semantically different.

Two issues come to mind:

C++'s comments allowed strange constructions that would parse differently in C and C++.

Character literals are ints in C and chars in C++.

There were always valid C programs that were not valid C++.

Function declarations and definitions provide lots of examples.

Moderation in all things. -- ancient proverb

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Great to see a C v C++ war and the poor ASM users are not blown to bits and described as Luddites..... devil

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i don't really understand this topic, or why you even need 10 years to learn C++....

 

the most important thing is that you know how to find documentation on the subject / libraries you need for your project. Its impossible to know everything 

 

I am actually from a computer science background and work with C#, but i use java as well sometimes, and other web programming languages like php and python. Never worked with C++ but i don't think that really does matter

While C# and Java and C++ are different programming languages, they are all 3 OOP languages, the differences are mostly in the libraries and the syntax

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
Great to see a C v C++ war and the poor ASM users are not blown to bits and described as Luddites..... devil

 

<-- Luddite.  We gave up and went home. 

 

Fortunately there isn't avr-assembler-2014, avr-assembler-2017, avr-assembler-2020 ...

 

S.

 

PS - And yes, in carefully chosen situations, C and C++ can compile down to the exact same instructions a clever assembler coder would use, but the point is the rest of the time, not the carefully cherry-picked examples.  One:  In assembler, all the registers are available as the location of the returned value, so you don't have to 'mov' it around (or into and out of SRAM) in order to use it again in the next instruction.  Edited to add PS.  S.

 

Last Edited: Tue. Jul 25, 2017 - 01:15 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

zerco wrote:
Its impossible to know everything
But that is not true for C. So it comes as a shock to C programmers (who know every last detail of the language and libc) to come to C++ which apparently is so large that you would never have a hope of carrying it all around in your head.

 

Think of a carpenter and a box of tools. After 20 years experience the guy knows all of:

 

Ball-peen hammer
Boiler scaling hammer
Brass hammer
Carpenter's hammer
Cow hammer
Cross-peen hammer
Dead blow hammer
Drilling hammer
Engineer's hammer
Geologist's hammer
Joiner's hammer
Knife-edged hammer
Lathe hammer
Lump hammer
Mallets
Rounding hammer
Sledgehammer
Soft-faced hammer
Splitting maul
Stonemason's hammer
Tinner's hammer
Upholstery hammer
Welder's chipping hammer

 

He knows what each one of those is and when is the right time to go looking for a particular one. Same for spanners, screwdrivers and so on.

 

C is like that - it's a complete toolbox and the skilled engineer knows every tool in the box, when to pick one and what they can achieve.

 

C++ is more like:

 

http://craphound.com/images/009H0259000.jpeg

 

(worse in fact!). There may be some very clever tools in there with very specific jobs but if you don't know about them how are you ever going to know that they would make a particular job easier?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
(worse in fact!)

Choice of words.. "worse" or "more". The latter is more neutral.

 

Still, that's a viable picture of it. And even worse, uh, more..

 

Template meta programming is half-way to having your own forgery to make new tools if you want to. I have not explored this area much more than making myself informed enough to have an rough understanding about what it is. Never practiced it. Might be interesting as an "intellectual exercise", but I have too many things on my to-do-in-life list for it to have bubbled up to the level of "do this with an effort".

 

I believe I've read this article before, but am not sure. Looks good, but no guarantees:

 

https://www.codeproject.com/Arti... - This one has interesting stuff on letting the compiler generate an unrolled loop.

 

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

whats wrong with that? 

Use what you know, and look for what you need to complete the job... 

 

there are endless of libs in C# or in the case of Java, and so it seems in the case of C++

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

zerco wrote:
whats wrong with that? 

If this was re my TMP stuff above: Nothing. It was not my intention to slam TMP in any way. I was just trying to express that it is some of the most advanced (and, for me, hard to penetrate) stuff in C++. OTOH, the newer C++ STLs offer and/or make use of it, so for anyone with a general interest in C++ it makes sense to at least be informed. I'm still working on being that.. ;-)

 

zerco wrote:
Use what you know, and look for what you need to complete the job

Agree.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Every now and then I learn something new about assembler.

 

S.

 

PS - My toolbox has a finder, a grabber, a spanner, a screwer, and a lever.  laugh  S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've concluded that C++ is not that hard, if you just focus on the language and ignore the standard library with all its bells and whistles. It also doesn't cause any particular bloat compared to C, once you understand the mechanics behind how code is generated.

 

I think it may be too flexible, there are many ways to accomplish anything, so naturally everyone and their dog writes libraries to do the same, according to their particular taste.

For example, I wrote a blink program using a class template (for Arduino style hardware), this template generates a class for every different pin that is used. It's a bit like a C macro, but better.

The generated code is the same as a C implementation would create, there is no penalty in terms of size. So, I guess I like C++.

 

#include <avr/io.h>
#include <util/delay.h>

// arbitrarly use PORT as base addres
enum base {B = (const uint16_t) &PORTB,	C = (const uint16_t) &PORTC, D = (const uint16_t) &PORTD};

template <base b, int pin_bit>
class Pin {
    // calculate offsets for DDRx and PINx
	static const int8_t dir_offset = &DDRB - &PORTB;
	static const int8_t in_offset = &PINB - &PORTB;

	public:
		static void set(){
			*(volatile uint8_t*)b |= 1<<pin_bit;
		}
		static void clear(){
			*(volatile uint8_t*)b &= ~(1<<pin_bit);
		}
		static void as_output(){
			*(volatile uint8_t*) (b + dir_offset) |= 1<<pin_bit;
		}
		static void as_input(){
			*(volatile uint8_t*) (b + dir_offset) &= ~(1<<pin_bit);
		}
		static void toggle(){
			*(volatile uint8_t*) (b + in_offset) |= 1<<pin_bit;
		}
};

int main(){
	Pin<B,5>::as_output();
	while (1) {
		Pin<B,5>::toggle();
		_delay_ms(500);
	}
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd suggest C# as a nice way to get into C++. It's much easier and more forgiving.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, and no. There are so much of syntax differences that there's a lot to forget or learn when switching fromn C# to C++.

 

The inheritance mechanism looks different. No "outlined" (as oppose to inlined) function definitions in C#. Templates are different..The "assembly" concept in .NET differs from the #include concept + linking in C++..

 

If you had said "I'd suggest C# as a nice way to get into OOP" I would agree 100%. C# or Java. Much better, IMO, to get to the principles of OO in one of those than in C++.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I would subject Python, very popular (indent are part of the language, making C codes more beautiful)

or R (is very easy , has a great help (*.txt with less, *.pdf, *.html) with examples and fuzzy search (if one needs help and makes typos...) , supports polymorphism).

The fact that R and Python supports polymorphism (ex sin(MPI) returns zero; sin(c(0, MPI/2., MPI)) returns an array of {0,1,0}) is pleasant enough and one can think it lacks in C... then, if one is not too lazy,  one goes to C++ (other advantage : Arduino) , though it is less easy...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can I just mention Python?

 

Also OOP and t may be just marginally easier to follow what is going on because "this" is not hidden". Your class functions all take "self" as the first parameter which, apart from anything else, makes it clear what are members and what aren't because they are all referenced as self.something

 

(I imagine there was a lot of to-ing and fro-ing in the design meetings for Python before they made the decision to expose that!)

 

EDIT: oops had this in the editor for 30 mins while distracted - seems I'm not the only advocate of Python ? ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am not a Python advocate :

I learned R before : this is a sujective reason;

R has better documentation than Python, with working examples (they are used for test, unless specified, if the result is stored , before installing a package/R itself)

you do not need to indent (Python is very boring in this respect); just "compile" a function, then decompile and it will get indented (if variable names are long, comments -which are lost-  may be felt as redundent).

OTOH :

R is less popular than Python (but should be, of course)

R has too many libraries (perhaps 100 for regressions / robust regressions ; python's scipy has may be one for this topic -carefully selected-)

R is meant for statistics (can be extended for geostatistics, geography...) and people think it is "only" meant for that.

 

Python is general purpose :

 

youtube-dl is coded in Python;

 

Python  calls opencv in a comfortable way http://www.pyimagesearch.com/201... ;

 

matplotlib gives very nice plots, without effort https://balau82.wordpress.com/20... )

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dbrion0606 wrote:
R has better documentation than Python, with working examples
Better than...

https://docs.python.org/3/

 

Seems difficult to believe that anything could be better - I think it's great - I learned Python almost exclusively from those pages and nothing else.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

What we really want is lisp.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am afraid R https://en.wikipedia.org/wiki/R_(programming_language)#History  is a grand(son/daughter) of lisp through https://fr.wikipedia.org/wiki/XL... ...

For documentation:

under Python, if you write a library/package/module  , you are free not to write one line of documentation (I agree Pythons official documentation is good) and nothing is done to make life easier while writing documentation (one may forget an important item) .

 

under R, if one writes a library, one downloads a skeleton, and the paragraphs of the documentation (input parameters, output object's structure, examples ) are just to be filled. The documentation (which can be plain text) can be called from the interpreter (invokes "less") , even on a non graphical terminal (seems stupid in this century, but xxxPis are so cheap one can link them together, and only one has a screen; other have just text terminal). Tests can be made consistent with documentation (would be terrible with image processing....), just using "diff"

 

Examples : every bold part of https://cran.r-project.org/web/p... is the skeleton of the doc (comes with a package skeleton, IIRC) ; if an example is commented with "##Not run", it is not used for checking library works (ex : page 2 : they download a sudoku  , but, even if the sudoku disappears, library remains valid....

In https://cran.r-project.org/web/p..., page 3-4, every doubly commented part of an example is the result of the previous  command line, making tests quite easy (graphical libraries / very long computations cannot be automatically tested).

 

Edited : Oh, I forgot the essential :

https://cran.r-project.org/doc/manuals/r-release/R-exts.pdf

explains how to write packages (python's modules, invoked with almost the same syntax library(zzz) ) . It confirms there is a function which stores a package skeleton where one wants, ready to be edited/ completed with sources (can build, through autoconf, C, C++ and Fortran shared objects, ready to be used by R); another function, called promptPAckage, helps in writing  documentation... (without forgetting any detail) Way documentation is/should be written takes 20 pages out of 184 in the manual; this makes a huge (infinite) contrast with Python packaging help in this respect.

 

Oh, by the way, I do not deduce (from a page count) people who write python packages produce zero lines...  (neither do I deduce that R packages documentation is always good -but it should be)

I only notice that, without guidelines, it is more difficult.... and they are likely to forget something.

 

Another feature of R is a kind of thematic index : as it has too many packages, it is difficult to choose between each of all who make maps, regressions...   A list of interesting subjects https://cran.r-project.org/web/v... helps in finding out the package(s) one needs... from a web browser or from a function call (I know that Python can use pyopencv, pyimaging, pySDL -useful for exotic, UTF8 text ocv does not handle-, but I guess I missed a lot for image processing, and never will know which....)

A last feature of R is .. it can call Python (and Excel, in the Windows world ; does Python do it?)

Last Edited: Tue. Aug 1, 2017 - 05:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bah, where's my magnetized needle?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mojo-chan wrote:

Bah, where's my magnetized needle?

I use butterflies.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

blush
 

Last Edited: Tue. Aug 1, 2017 - 05:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow! Dear professor. I have to save all the comments here and read several times, it is full of scientific and experimental information that is difficult to obtain.
Thank you very much for this topic

yesyesyes

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dbrion0606 wrote:
A last feature of R is .. it can call Python (and Excel, in the Windows world ; does Python do it?)

Haven't done it myself, but AFAIK any programming language that can call into a DLL/(D)COM-object can "call Excel". This would then include, at least C, C++, C#, Java (via JNI), VB.NET and I sudpect VB6 would also work. I'm sure a lot of other languages has provisions for calling DLL/COM-objects.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Excuse me, but **where** is ther a Python package linking with Excel?

with a documentation as good as https://cran.r-project.org/web/p... , with working (may be : tests are run on GNU linux machines and examples therefore cannot be tested)  examples....

 

And I know python is not any programming language  (and, as it can be linked with R... perhaps python developpers wisely decided **not** to link it with Excel -and  thus avoid having to debug and document-  : you see I am very fair.)

 

BTW what is a DLL ? is it contagious?

Last Edited: Tue. Aug 1, 2017 - 06:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dbrion0606 wrote:
BTW what is a DLL ? is it contagious?

 

Very. And they reproduce fast. My OS partition has 37777 dlls occupying 25.323.438.940 bytes.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dbrion0606 wrote:
Excuse me, but **where** is ther a Python package linking with Excel?
Have you heard of this thing called Google? I typed "python excel" into it and of the many hits perhaps the most interesting sounding is:

 

http://www.python-excel.org/

 

The very fact they called a whole website "python-excel" rather gives one hope! However all of that seems to be processing existing XLS files on disk (or creating new ones). If you want a dynamic link to Excel then Google says the thing to use is:

 

https://www.xlwings.org/

 

which allows for things like:

"""
Copyright (C) 2014-2016, Zoomer Analytics LLC.
All rights reserved.

License: BSD 3-clause (see LICENSE.txt for details)
"""
import xlwings as xw


def fibonacci(n):
    """
    Generates the first n Fibonacci numbers.
    Adopted from: https://docs.python.org/3/tutorial/modules.html
    """
    result = []
    a, b = 0, 1
    while len(result) < n:
        result.append(b)
        a, b = b, a + b
    return result


def xl_fibonacci():
    """
    This is a wrapper around fibonacci() to handle all the Excel stuff
    """
    # Create a reference to the calling Excel Workbook
    sht = xw.Book.caller().sheets[0]

    # Get the input from Excel and turn into integer
    n = sht.range('B1').options(numbers=int).value

    # Call the main function
    seq = fibonacci(n)

    # Clear output
    sht.range('C1').expand('vertical').clear_contents()

    # Return the output to Excel in column orientation
    sht.range('C1').options(transpose=True).value = seq

if __name__ == "__main__":
    # Used for frozen executable
    xl_fibonacci()

Which at the same time rather demonstrates the power of object orientation with the "sht" object that is created and to which methods are then applied.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the "sht" object that is created

I create one of them almost everyday....

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Have you heard of this thing called Google? "

 

No , because my PC does not have a speech synthetizer.

IS python excel's doc beginner -friendly? usable?

Was it -the docume,tation-  easy to write? for a skilled programmer? for a beginner?

(google seems very mute in this respect.....)

 

Edited : Are Pythons variable names limited in the number of chars(like Fortran, a century ago : users protested). Does Python only use consonents (like HEbrew and Arabic, the 2 official languages of Israel) -but I know Python (basic one : (py)opencv seems weird )  has better UTF support  than R (you see I m "honnête" - I do not know whether google can translate this adjective into Omericon).

 

Edited : some ambiguities removed.

Last Edited: Wed. Aug 2, 2017 - 09:37 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dbrion0606 wrote:
Are Pythons variable names limited in the number of chars(like Fortran, a century ago : users protested). Does Python only use consonents (like HEbrew and Arabic, the 2 official languages of Israel) -but I know Python (basic one : (py)opencv seems weird )  has better UTF support  than R (you see I m "honnête" - I do not know whether google can translate this adjective into Omericon).

An attribute name must only have underlines, digits and the letters (A through Z and a through z), and it must start with an underline or letter. Since almost invariably it will be a key in a dictionary, a name can have a billion characters if you like, if not more.

- John

Last Edited: Wed. Aug 2, 2017 - 10:25 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

why not use google?

 

https://docs.python.org/2/refere...

 

came up as the first hit

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is google? (and is it popular somewhere in the world? : suppose it is censured in some country : in this hypothesis,  your answer can  be seen, to be very kind, as a blunder).

 

From the context, it seems that  Python variable names can be made vowels ....   and can be longer than Fortran variables (Fortran  always accepted vowels), a century ago...

 

I do not think js -post 182- thought of a strange interpretation of a very short  variable name (this is unconsistent with his talents) . Any way, I could not understand such a weird interpretation : according to https://en.wikipedia.org/wiki/Pi... (Greman translation confirms it) , such a rude word cannot be heard, even in the fiercest battle. Victor Hugo http://www.gutenberg.org/files/1... VOL II Cosette, Book First -Waterloo- Chap 15 Cambronne disagrees, but courts confirmed...

 

 

Pages