Author Topic: Learning to Code  (Read 8396 times)

0 Members and 1 Guest are viewing this topic.

Offline superdave

  • Too Much Spare Time
  • ********
  • Posts: 6235
Re: Learning to Code
« Reply #120 on: July 24, 2019, 09:34:28 AM »
learning C just to appreciate python is a totally reasonable reason to want to learn C.

For a similar reason, I recommend everyone use Linux at least sometimes.  It really helps you understand the choices that Windows and Mac make.
« Last Edit: July 24, 2019, 09:45:27 AM by superdave »
I disavow anyone in the movement involved in any illegal,unethical, sexist, or racist behavior. However, I don't have the energy or time to investigate each person and case, and a lack of individual disavowals for each incident should not be construed as condoning such behavior.

Offline stands2reason

  • Empiricist, Positivist, Militant Agnostic
  • Poster of Extraordinary Magnitude
  • **********
  • Posts: 10746
Re: Learning to Code
« Reply #121 on: July 24, 2019, 10:15:08 AM »
For a similar reason, I recommend everyone use Linux at least sometimes.  It really helps you understand the choices that Windows and Mac make.


Offline The Latinist

  • Cyber Greasemonkey
  • Technical Administrator
  • Reef Tank Owner
  • *****
  • Posts: 8043
Re: Learning to Code
« Reply #122 on: July 24, 2019, 01:44:50 PM »
I want to understand C, especially c pointers and arrays, before I start looking at C++.
I would like to propose...that...it is undesirable to believe in a proposition when there is no ground whatever for supposing it true. — Bertrand Russell

Online werecow

  • Cryptobovinologist
  • Stopped Going Outside
  • *******
  • Posts: 5032
  • mooh
Re: Learning to Code
« Reply #123 on: July 24, 2019, 08:21:11 PM »
I want to understand C, especially c pointers and arrays, before I start looking at C++.

Pointers are really not that difficult conceptually. They seem confusing at first, but you're basically just saying "whatever that guy says", only in computer.
Mooohn!

Offline stands2reason

  • Empiricist, Positivist, Militant Agnostic
  • Poster of Extraordinary Magnitude
  • **********
  • Posts: 10746
Re: Learning to Code
« Reply #124 on: July 25, 2019, 08:47:03 AM »
A pointer stores a memory address. Dereferencing it gives you the value stored at the memory address stored in the pointer.

In C, arrays are directly related to pointers. In C, arrays aren't a proper data type, an array always gets decayed to a pointer when it is passed into a function. An array is basically just a pointer to its first element. This is more obvious when you think about dynamically allocated memory blocks i.e. malloc(sizeof(ArrayElement) * arraySize), etc. One of the mistakes of C is that there is not a proper array datatype that stores its size, which is why number of elements has to be passed in as a separate argument, and buffer overflows.

In C, adding/subtracting from a pointer is equivalent to stepping forward or back that number times the number of bytes of the data type it refers to. It is part of the C standard that this is identical to array indexing:  a[i] is equivalent to *(a + i)

C++ iterators are inspired by array indexing & the corresponding for loops.
« Last Edit: July 25, 2019, 08:54:46 AM by stands2reason »

Offline brilligtove

  • Too Much Spare Time
  • ********
  • Posts: 7617
  • Ignorance can be cured. Stupidity, you deal with.
Re: Learning to Code
« Reply #125 on: July 25, 2019, 09:25:40 AM »
The basic idea of pointers is reasonably simple: it's like a street address, not the house. IIRC the implications of using pointers were a lot more challenging. I know I struggled (30+ years ago) to use them safely.
evidence trumps experience | performance over perfection | responsibility – authority = scapegoat | emotions motivate; data doesn't

Offline The Latinist

  • Cyber Greasemonkey
  • Technical Administrator
  • Reef Tank Owner
  • *****
  • Posts: 8043
Re: Learning to Code
« Reply #126 on: July 25, 2019, 11:57:21 AM »
Yeah, I get the concepts. And I’m using them. But it requires a shift in thinking from more abstract data types, which just takes time. It’s like learning a human language: one can have a handle on the syntax and vocabulary, but still struggle to translate an idiom.
« Last Edit: July 25, 2019, 12:00:11 PM by The Latinist »
I would like to propose...that...it is undesirable to believe in a proposition when there is no ground whatever for supposing it true. — Bertrand Russell

 

personate-rain