Pointers
Pointers
I wonder why pointers introduced into the language? Pointers lead to memory leaks and buffer owerflows. Safety was one of the advantages of Basic over other languages.
Most flaws in C code are direct consequences of incorrect pointer usage. It makes C one of the most unsafe and buggy languages in the world.
Most flaws in C code are direct consequences of incorrect pointer usage. It makes C one of the most unsafe and buggy languages in the world.
-
- Posts: 5494
- Joined: Sep 12, 2005 20:06
- Location: California
Pointers allow for dynamic memory and better control over it... Pointers are very important. To be compatible with C and C++ libraries, we also need pointers.
Incorrect pointer usage will in fact cause memory leaks, but pointers are very powerful tools and are necessary for features such as Object Orientation, for example. NEW and DELETE also help make pointer usage easier.
Pointers are very much so a good thing. Even Java has pointers - It just will manage the reference count for you. The question becomes then, given all of the uses of pointers: Why *wouldn't* we allow pointers? I'd be upset, personally, if FreeBASIC limited me like that.
Incorrect pointer usage will in fact cause memory leaks, but pointers are very powerful tools and are necessary for features such as Object Orientation, for example. NEW and DELETE also help make pointer usage easier.
Pointers are very much so a good thing. Even Java has pointers - It just will manage the reference count for you. The question becomes then, given all of the uses of pointers: Why *wouldn't* we allow pointers? I'd be upset, personally, if FreeBASIC limited me like that.
Bad code in any language is bad. You are in fact correct - C really isn't all that safe. C++ was a lot safer, but could have still been improved. I believe FreeBASIC makes things about as safe as C++ does, or more :-)It makes C one of the most unsafe and buggy languages in the world.
Last edited by anonymous1337 on Jan 05, 2008 5:28, edited 2 times in total.
Nobody is forcing you to use pointers but Visual Basic didn't have pointers and you could still produce memory leaks by not properly disposing of objects.
I myself rely heavily on pointers both to add speed and scalability to my applications. I would highly recommend learning how to use them.
-Vince
I myself rely heavily on pointers both to add speed and scalability to my applications. I would highly recommend learning how to use them.
-Vince
VB has hidden pointers. It does not allow pointer arithmetic, but you indeed can produce a memory leak (although it would be rather difficult and needs special effort).vdecampo wrote:Nobody is forcing you to use pointers but Visual Basic didn't have pointers and you could still produce memory leaks by not properly disposing of objects.
What I want to point out is that pointers concept is unnatural for Basic. It has other features that make pointer usage not necessary such as arguments' transfere oprions ByVal and ByRef etc. It pointers introduced they create complete mess with it and break even syntax compatibility with other Basic dialects.
Still no large project that uses C language could avoid these flaws. MS Windows has dozens of buffer overflow bugs, just the same UNIX, Mozilla has numerous memory leaks etc. These flaws are inherent for C and especially because of pointer arithmetic.LukeL wrote:If you google the pros of pointers in high level programming you'll see they far outweigh the cons.
Especially memory leaks and buffer overflows which can be easily avoided by good programming practice.
Which BASIC? BasicA, GWBASIC, PowerBASIC, FreeBASIC, PureBasic, QuickBASIC, DarkBASIC, Visual Basic, VB.NET, CDBasic, SXWIZ...Nxx wrote:What I want to point out is that pointers concept is unnatural for Basic.
The list goes on and on. Some use pointers. Some don't. Find the one that works for you and use it. Some of us like pointers. Why should we be penalized because you don't know, or don't want to know how to use them?
-Vince
Last edited by vdecampo on Dec 23, 2007 21:35, edited 1 time in total.
Pointers are a powerful tool, and as with any powerful tool, it's quite possible to do both great good and great harm. That does not make a powerful tool inherently bad. If you prefer to use a handsaw, feel free to do so, but don't deny those of us who know how to safely use a chainsaw that possibility.
Which of them except FreeBasic use pointers? None. Basic language has other tools that make pointers unnecessary.vdecampo wrote:Which BASIC? BasicA, GWBASIC, PowerBASIC, FreeBASIC, PureBasic, QuickBASIC, DarkBASIC, Visual Basic, VB.NET, CDBasic, SXWIZ...Nxx wrote:What I want to point out is that pointers concept is unnatural for Basic.
The list goes on and on. Some use pointers. Some don't. Find the one that works for you and use it. Some of us like pointers. Why should we be penalized because you don't know, or don't want to know how to use them?
-Vince
Last edited by Nxx on Dec 23, 2007 22:03, edited 2 times in total.
If to compare, it would be pointers to correspond to handsaw. Why use handsaw when there is safe certified machine that would saw anything you want according a program without any risk to damage yourself? This "powerful tool" is too costly for developers and the industry overall. Companies spent billions to find bugs caused by incorrect pointer use. Security flaws in operating systems, browsers etc due to pointers cost even more.DrV wrote:Pointers are a powerful tool, and as with any powerful tool, it's quite possible to do both great good and great harm. That does not make a powerful tool inherently bad. If you prefer to use a handsaw, feel free to do so, but don't deny those of us who know how to safely use a chainsaw that possibility.
Can you please specify what you need pointers for? What thing you cannot make without pointers? In fact any code that uses pointers can be rewritten with safe Basic-specific constructs such as arrays.
Visual Basic can use any API existing in the system regardless which language it is written in. I do not realize about which libraries do you speak. Possibly it is UNIX-specific ones?DrV wrote:There are plenty of external C libraries that require the use of pointers, and these uses cannot be replaced by any FB-only magical array. There is no way around this unless you don't want to use any C libraries or want to write wrappers for all of them.
I'll be the first to agree that 'pointers' was something my brain had to struggle with understanding (already knowing some basic).
But...
Can anyone here afford the amount of time it would take to wrap all those libs' - are there enough people *here*, who, because they only understand basic, are capable to take any real amount of the load to do this (ie: distribute the burden) ? - most likely not.
My take on it is: pointers just makes a lot of things easier to do with FB.
This seems to be turning into a PC vs Mac debate... ??
How many people die in a car each year, when; we can walk; ride horses/bicycles - but we don't. why? Because a car is much more convenient despite their obvious dangers to society.
But, yes, there are those who choose to wait for the bus, I pass by them all the time.
But...
Can anyone here afford the amount of time it would take to wrap all those libs' - are there enough people *here*, who, because they only understand basic, are capable to take any real amount of the load to do this (ie: distribute the burden) ? - most likely not.
the answer is obvious - if you don't like pointers - don't use them.What thing you cannot make without pointers?
My take on it is: pointers just makes a lot of things easier to do with FB.
This seems to be turning into a PC vs Mac debate... ??
How about the 'car' analogy?If to compare, it would be pointers to correspond to handsaw.
How many people die in a car each year, when; we can walk; ride horses/bicycles - but we don't. why? Because a car is much more convenient despite their obvious dangers to society.
But, yes, there are those who choose to wait for the bus, I pass by them all the time.
http://www.freebasic.net/forum/viewtopic.php?t=788I do not realize about which libraries do you speak. Possibly it is UNIX-specific ones?
*most* are cross platform