Help on array pointers

Joe at bloow.edu Joe at bloow.edu
Fri Sep 22 22:32:50 UTC 2023


On Monday, 18 September 2023 at 02:49:37 UTC, vino wrote:
> On Sunday, 17 September 2023 at 18:28:36 UTC, Joe wrote:
>> On Friday, 15 September 2023 at 16:55:34 UTC, Vino wrote:
>>>> [...]
>>
>>> [...]
>>
>>
>> char[] invalid = (cast(char*)malloc(char.sizeof * 
>> len))[0..len];
>>
>> This is not the way to go about it. You are mixing "pointer 
>> arrays" with "arrays".
>>
>> [...]
>
> Thank you very much, I am still newbie for programming and 
> currently concentrating on Arrays/Struct/Pointers/Memory 
> management.

It will make more sense over time. It's actually really simple 
but it takes time to get used to thinking along the lines of the 
computer languages and such.

My suggestion is simply do a lot of examples. Just type them in. 
As you type you think about what you are typing and how it 
relates. Then you will start to notice the patterns and such.

I wouldn't try to create new programs from scratch because it's 
easy to make mistakes that can be very hard to debug.

D might not be the best language to start learning programming.

E.g., might be better to go with javascript, lua, or python and 
get a nice rapid development environment. Even though D is fast 
to compile it's not that fast.

Maybe use Repl which lets you code line by line essentially. All 
languages more or less are the same but just look different so it 
you want to find out one that has the most convenience. you don't 
want to bite off too much as it will slow you down.

Ultimately it's just like anything else though in that you are 
learning a language and all it's nuances. You ultimately have to 
learn how to translate your thoughts and desires in to the 
correct syntax so you can make the language useful and act as a 
tool. If you try to us it as a tool before you learn to mimic 
others it will be very slow and frustrating.


Because most languages are 99% the same with just different 
syntax(just about every major programming language can do what 
ever other one can, it's just some are better/easier at doing 
certain things than others).

You might try learning several languages at once as it can 
actually speed things up.

Learn how to write simple programs(hello worlds) then modify 
those to do more and then learn control 
structures(branching(if's), loops(for)), variables, etc. Build up 
slowly and everything will make sense. Build up fast and you'll 
get lost at some point and then spend a lot of time trying to 
figure out how to make sense of it.

Ideally you want an ide and language that gives you precise info 
on errors that you make else it can be hard to track down 
mistakes because sometimes errors can be hidden. D is not good 
for.

Even Q-basis might be better to start with or try to find Turbo 
Pascal if it still exists.

What makes D great is it's generic/template programming and that 
is a more complex topic that you probably won't get much in to 
for a few years(although it is not really hard it will seem like 
it at first).

D has a lot of features that hard core programmers like and so 
you are not going to be using those features for a while so it 
might not be worth using D to learn off of.

Not saying you can't do it but it might be slow. You could always 
do it in parallel. E.g., learn to write simple programs in many 
languages then build up.

E.g.,

for i=1:10 // Matlab
for(auto i = 1; i < 10; i++)  // D
for(int i = 1; i < 10; i++)  // C
for(var i = 1; i < 10; i++)  // JS
for i from 1 to 10 // maple
loop(50, ...) // JSFX
for i = 1,10 // lua

etc.

The underlying idea is that one wants a way to do the same thing 
over and over and so loops exist to handle that pattern. Each 
language uses different ways to express a loop. Just like 
languages, all languages uses nouns, verbs, etc but express them 
differently.




More information about the Digitalmars-d-learn mailing list