Search code examples
pointersprogramming-languageslanguage-design

is this good to have pointers in programming languages such as golang,C or C++?


Most of the modern programming compilers such as JAVA etc does not have the support of pointers. But in golang google introduce pointers again. So, i just want to understand how pointer effects a programming language? is there any kind of security thread because of pointers?

if this is because of security then why we have world's most secured system on LINUX and UNIX(both are build in C)


Solution

  • Technically, all languages use pointers. When you create an instance of an object in Java or C# or Javascript and pass it to a method you are actually passing a pointer to the piece of memory that contains that object by which you will manipulate the data on that piece of memory. Imagine a language where you could not pass by reference. You wouldn't be able to do much, now would you? Whenever you pass by reference in any language, you're - in the most basic of terms - using glorified pointers.

    What you probably mean, however, is "why expose pointers to people; they are so much more complicated", or something of that sort... And the answer is probably speed and tradition. Some of the fastest languages we have are C and C++... They've been around for a relatively long time. They are tried and true, and people know how to use them. Most software is based off of them in one way or another. Most operating systems are written in C or some variation thereof. Even other programming languages.

    As for your Go example, we have already had a question on that..