POV-Ray : Newsgroups : povray.off-topic : Question to the programers here Server Time
1 Nov 2024 15:27:37 EDT (-0400)
  Question to the programers here (Message 1 to 10 of 17)  
Goto Latest 10 Messages Next 7 Messages >>>
From: H  Karsten
Subject: Question to the programers here
Date: 29 Jul 2011 18:50:00
Message: <web.4e3338349cac4d14a3bfeb720@news.povray.org>
He people,

I've just started to write little things, using Rebol. There are things I really
hate but a few things I really love, such as no need to initialise the size of
an array.

I just initialise an array with the size of zero an append something to it.

No other language I've used before can do so.

Now I like to know, if there are other languages, can do like Rebol does.

I'm thankful for any hint.

Best rgds,
Holger


Post a reply to this message

From: Jim Henderson
Subject: Re: Question to the programers here
Date: 29 Jul 2011 20:14:49
Message: <4e334cf9$1@news.povray.org>
On Fri, 29 Jul 2011 18:46:12 -0400, H. Karsten wrote:

> He people,
> 
> I've just started to write little things, using Rebol. There are things
> I really hate but a few things I really love, such as no need to
> initialise the size of an array.
> 
> I just initialise an array with the size of zero an append something to
> it.
> 
> No other language I've used before can do so.
> 
> Now I like to know, if there are other languages, can do like Rebol
> does.
> 
> I'm thankful for any hint.

You can kinda do this in C - you can initialize a variable as a pointer, 
and then allocate memory to the buffer as needed - but you have to 
allocate the memory or you can end up corrupting your data in memory (at 
best, at worst you could overwrite the program in memory if you're not 
careful).

But you can't just append data to it, you do have to allocate the memory 
yourself (as a programmer).

Jim


Post a reply to this message

From: Darren New
Subject: Re: Question to the programers here
Date: 29 Jul 2011 22:19:51
Message: <4e336a47$1@news.povray.org>
On 7/29/2011 15:46, H. Karsten wrote:
> I just initialise an array with the size of zero an append something to it.

There are a number of languages that do this. Most of the "scripting" 
languages let you do this or something very like it - Tcl, PHP, Python, etc.

C++ and Smalltalk have libraries that provide types that are standard and 
take care of making the array bigger for you when you fill it up.

So, yeah, it's not too uncommon. Only the really low-level languages like C 
or assembler or old Fortran or whatever makes that difficult.

All those languages also have "maps" either built in or as standard 
libraries, letting you essentially make an array that's indexed by anything 
you want, such as strings.

-- 
Darren New, San Diego CA, USA (PST)
   How come I never get only one kudo?


Post a reply to this message

From: H  Karsten
Subject: Re: Question to the programers here
Date: 29 Jul 2011 22:30:00
Message: <web.4e336becf2d3f33aa3bfeb720@news.povray.org>
ok, that doesn't sound to complicate, when writing a function to do so.

Do I need to do something with the number, using /to point/ onto the value?

like in PovRay this would look like something(number)=value, means the "number"
- when increasing the memory for the array it does not automatically give me the
option to use higher numbers - or does it?

For example saying something(345)=120, then increasing the memory for it and
after this saying something(346)=800? In this case I would estimate an error
message, saying, that I initialised the array only for 345 values. What says c
or c++ that there is now more space available?

Does it automatically check this every time?

(Hope this was not to confusing)

Holger


Post a reply to this message

From: H  Karsten
Subject: Re: Question to the programers here
Date: 29 Jul 2011 22:40:01
Message: <web.4e336ec7f2d3f33aa3bfeb720@news.povray.org>
Thanx to Darren as well. I didn't saw your post first.
My last post was an answer to Jim.

Well ok, that all sound very good.

Actually I've did a lot of little things, using Free-Basic. But that becomes to
buggy, so I moved to Rebol than.

Maybe I should give myself a push and move-one to c++.
As well I thought to go to Forth maybe, because of the stack, that makes it
possible to get lots and lots of results, coming from just one function.

Holger


Post a reply to this message

From: Jim Henderson
Subject: Re: Question to the programers here
Date: 29 Jul 2011 22:41:36
Message: <4e336f60$1@news.povray.org>
On Fri, 29 Jul 2011 19:19:50 -0700, Darren New wrote:

> There are a number of languages that do this. Most of the "scripting"
> languages let you do this or something very like it - Tcl, PHP, Python,
> etc.

Oh, yes, that's certainly true.  Trust me to pick the most complicated 
example rather than the simplest.  Even BASIC really allows this (most 
variations) without any complexity at all.

Jim


Post a reply to this message

From: H  Karsten
Subject: Re: Question to the programers here
Date: 29 Jul 2011 23:05:00
Message: <web.4e337366f2d3f33aa3bfeb720@news.povray.org>
Jim Henderson <nos### [at] nospamcom> wrote:

> Oh, yes, that's certainly true.  Trust me to pick the most complicated
> example rather than the simplest.  Even BASIC really allows this (most
> variations) without any complexity at all.
>
> Jim

Yes I can imagine that, when fiddling with the pointers. But I'm still sure,
that I need to manipulate a second thing, saying basic that my array is REALLY
bigger by now.

Before using Rebol, I would just never have come to the idea to do so ;)

The final reason to get rid of Basic was, that I loaded a file into the memory,
run through it, by assigning the content (byte by byte) to just another variable
(a byte as well, and so that the value coming from before was simply
overwritten)

.......The program crashed - not because of an error in the code (that thing was
just five lines or something). But it crashed when the parsed file was simply
big :C

After that I decided to use something more serious ;)

Holger


Post a reply to this message

From: Darren New
Subject: Re: Question to the programers here
Date: 29 Jul 2011 23:22:20
Message: <4e3378ec@news.povray.org>
On 7/29/2011 19:39, H. Karsten wrote:
> Maybe I should give myself a push and move-one to c++.
> As well I thought to go to Forth maybe, because of the stack, that makes it
> possible to get lots and lots of results, coming from just one function.

You know, as a novice programmer, I wouldn't go with either of those.

If you make a mistake in C++, it can be extremely confusing to figure out 
where the mistake is.  Just like C.  And, indeed, Forth is just as bad in 
that respect.(*) Both Forth and C++ are low-level powerful languages, full 
of amazing capabilities, but easy to screw up in hard-to-fix ways.

I would recommend that if you want to learn something powerful as a first 
step, you consider Python or perhaps Ruby. Once you're comfortable writing a 
few hundred lines of code, or getting 1000 lines of your own code working 
without giving up and tearing your hair out, you'll be in a much better 
position to learn things that sacrifice easiness for speed. *Then* decide 
whether you want to learn C++ so you can program system tools compatible 
with everyone else, or learn Forth so you can write your own custom computer 
languages easily, or whatever you want to do.

Smalltalk might also be a good choice, except that it's "strange" and 
therefore might make learning things that are more "normal" difficult. For 
example, Smalltalk pretends to be the entire operating system, so there's no 
real concept of a Smalltalk "program".


(*) In spite of having written two Forth interpreters in assembly language, 
I don't think I ever got a Forth procedure more than 5 lines long to work, 
regardless of how long I tried to debug.
-- 
Darren New, San Diego CA, USA (PST)
   How come I never get only one kudo?


Post a reply to this message

From: stbenge
Subject: Re: Question to the programers here
Date: 30 Jul 2011 14:30:09
Message: <4e344db1$1@news.povray.org>
On 7/29/2011 7:39 PM, H. Karsten wrote:
>
> Actually I've did a lot of little things, using Free-Basic. But that becomes to
> buggy, so I moved to Rebol than.

I myself have just started using FreeBASIC, because my brother might be 
programming again and I wanted to find him a good BASIC dialect. While 
it's great to just get a program up-and-running with gfx, input, etc., 
it's an absolutely horrible language in all other respects. It's been 
maybe a week since I got into it, and I'm beginning to realize that any 
advantages I thought it had over C are far outweighed by its manifold 
problems.

> Maybe I should give myself a push and move-one to c++.

The basics of C++ aren't so hard to learn, and it's nice to know 
exactly_what_data_types you are using. The code is much cleaner than any 
BASIC. Just make sure you free up any memory you allocate, as you don't 
need leaks.

With C's vector class, you can create easily-manipulated dynamic arrays. 
And if I'm not mistaken, it cleans up after itself so you don't need to 
call a destructor at the end of your code.

~Sam


Post a reply to this message

From: Warp
Subject: Re: Question to the programers here
Date: 30 Jul 2011 15:23:49
Message: <4e345a45@news.povray.org>
stbenge <"egnebts <-inverted"@hotmail.com> wrote:
> The basics of C++ aren't so hard to learn, and it's nice to know 
> exactly_what_data_types you are using. The code is much cleaner than any 
> BASIC. Just make sure you free up any memory you allocate, as you don't 
> need leaks.

  You can get pretty far without ever writing a single 'new' (or 'malloc').
And if you never write a single 'new', you never have to write a single
'delete' either.

  One of the major problems with people who start learning C++ for the
first time is that in many cases they come from either a C or a Java (or
similar) background, both of which have explicit dynamic allocation as a
central concept. People who have that kind of background often have a hard
time "unlearning" that. Hence the C++ code made by these people will be rife
with unneeded dynamic allocations (which make the whole program needlessly
complex and unsafe).

  (Of course using 'new' is not the only way to easily screw up memory
management by mistake. If you start using pointers, or even iterators,
chances are that you are going make a mistake sooner or later. C++ is a
bit complicated like that.)

  It can be difficult to teach/learn C++ in a way that the safe practices
are learnt first.

> With C's vector class, you can create easily-manipulated dynamic arrays. 

  Don't you mean C++'s?

-- 
                                                          - Warp


Post a reply to this message

Goto Latest 10 Messages Next 7 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.