 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Jim Henderson <nos### [at] nospam com> 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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 7/30/2011 12:23 PM, Warp wrote:
> stbenge<"egnebts<-inverted"@hotmail.com> wrote:
>
>> With C's vector class, you can create easily-manipulated dynamic arrays.
>
> Don't you mean C++'s?
Yes... I jumped straight to C++, which was probably a mistake since I
haven't clearly defined the differences between it and its predecessor
:| I'm guessing /the/ major difference is C++'s OOP capabilities,
without which the vector class couldn't be possible, right?
Despite having written a few programs, I'm still undereducated on the
whole subject. My biggest concern is to prevent memory leaks and
outright crashes. As for writing clean code... I still have yet to
finish one program that doesn't use global variables `:/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 7/30/2011 14:08, stbenge wrote:
> I'm guessing /the/ major difference is C++'s OOP capabilities, without which
> the vector class couldn't be possible, right?
That and templates. The vector class isn't a class as much as it is a template.
--
Darren New, San Diego CA, USA (PST)
How come I never get only one kudo?
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 7/30/2011 11:30, stbenge wrote:
> great to just get a program up-and-running with gfx, input, etc., it's an
> absolutely horrible language in all other respects.
On that front, you could look into Tcl, or Java, or C#. If you're just
learning, I'd say C# is an excellent introduction to the C-like languages.
It has powerful development tools, "visual" builders to make input and forms
easy, portable file I/O stuff, fairly portable (if older) windowing stuff,
etc etc etc. I.e., it has an excellent development environment, along with
being a quite powerful language in the C family.
Tcl is really easy and portable with good I/O and graphics and stuff, but
it's so unlike other languages that what you learn there isn't really going
to apply to other systems as much, so it's probably not a real good first
language.
I'd stay away from "Visual Basic" or "VB.NET" myself. That's a rapidly
decaying body that the worms are still feasting on.
> The basics of C++ aren't so hard to learn,
It's annoying, tho, for a beginner. There are a large number of fairly
senseless rules that just become frustrating fairly quickly, not even
counting ho hard it can be to debug a fairly simple mistake like using an
uninitialized variable. It's like someone's learning to drive, and you give
them an 18-wheeler and say "this'll do everything, as soon as you learn the
14 different gears, and as long as you remember to hook up the air brakes
before you drive." I'd never start a student learning on their own with an
unsafe language that doesn't tell them when they've made a mistake.
--
Darren New, San Diego CA, USA (PST)
How come I never get only one kudo?
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Darren New <dne### [at] san rr com> wrote:
> That and templates. The vector class isn't a class as much as it is a template.
It's both. (Being a class is important because of RAII.)
--
- Warp
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Darren New <dne### [at] san rr com> wrote:
> I'd never start a student learning on their own with an
> unsafe language that doesn't tell them when they've made a mistake.
Using a good compiler with a good debug mode helps a lot. For example
VC++ adds bounds and other checks to all STL operations in debug mode,
as well as many other things. (gcc also has support for this, but
unfortunately it's such an obscure flag that a newbie will never find
it unless someone tells him.)
--
- Warp
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 7/31/2011 0:12, Warp wrote:
> Darren New<dne### [at] san rr com> wrote:
>> I'd never start a student learning on their own with an
>> unsafe language that doesn't tell them when they've made a mistake.
>
> Using a good compiler with a good debug mode helps a lot.
That's probably true. The only time I've really been using C or C++ lately
is in environments that were so sucky that's the best they could manage. :-)
I guess if you get a compiler that detects stuff like uninitialized
variables and you stay away from the native types that are most dangerous,
it probably wouldn't be too hard. I'm not sure why you *would* want to
start with something like that, mind.
When you gaze into the void, the void gazes back. When you cast into the
void, you get a type error, which just means Nietzsche wasn't a C programmer.
--
Darren New, San Diego CA, USA (PST)
How come I never get only one kudo?
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Ok, sorry for the delay first, I was off over the last days.
Well, after all of this very good information, I guess I try Ruby and go on from
that. My experience with C was only, using PovMan's shading language and I tried
Prosessing as well before (nice toy... ;)
Thanx for all hints, folks :)
Best rgds,
Holger
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|
 |