ENTRIES TAGGED "c"
How dabbling in a new language now can lead to innovation later
Being a polyglot programmer has its benefits; most of us have read or heard about those benefits from various respectable sources. I’d like to highlight the importance of being a polyglot learner before being a polyglot programmer.
You heard me right—learn a new language, but don’t rush to use it in production. At least not right away. I have used this approach and have realized two major benefits:
- Enhanced design skills, and
- The ability to adapt quickly to an evolving mainstream language
Most programmers currently code in one of the mainstream languages like Java, C#, and C++. On a typical enterprise project, chances are we’re using one of these languages. It might seem like a tall order for most of us to be able to intermix other languages. However, it’s becoming more critical that we do. Let’s discuss why.
Handle sensitive data, free memory, and more
It may seem that when dynamic memory has been deallocated, we are done with it. We have avoided a memory leak and can confidently move on to other issues. In some cases this may be the case. However, we may need to be concerned with issues such as how we handle sensitive data and whether we need to even worry about freeing memory if the application is about to terminate. In this discussion we will examine these issues and others.
The Heap and System Memory
The heap typically uses operating system functions to manage its memory. The heap’s size may be fixed when the program is created, or it may be allowed to grow. However, the heap manager does not necessarily return memory to the operating system when the
free function is called. The deallocated memory is simply made available for subsequent use by the application. Thus, when a program allocates and then frees up memory, the deallocation of memory is not normally reflected in the application’s memory usage as seen from the operating system perspective.
Memory is typically deallocated using the free function. One concern deals with what happens when we try to free the same memory twice. Freeing a block of memory twice is referred to as double free. The following illustrates how this can be done:
char *name = (char*)malloc(...); ... free(name); // First free ... free(name); // Double free
More subtle occurrences of double free occur when pointers are aliased:
char *name = (char*)malloc(...); char *tmp = name; ... free(name); // First free ... free(tmp); // Double free
In an earlier version of the zlib compression library, it was possible for a double-free operation to result in a denial of service attack or possibly to insert code into the program. However, this is extremely unlikely and the vulnerability has been addressed in newer releases of the library. More information about this vulnerability can be found at cert.org.
A simple technique to avoid this type of vulnerability is to always assign NULL to a pointer after it has been freed. Subsequent attempts to free a null pointer will be ignored by most heap managers.
char *name = (char*)malloc(...); ... free(name); name = NULL;
Effectively control Windows from the console
Here’s a slick PowerShell 3.0 one-liner. If you want to pull down an RSS feed from a blog, displaying only the title and publication date try:
Invoke-RestMethod "http://www.dougfinke.com/blog/index.php/feed/" | Select title, pubdate
It’s that simple. No looping, no checking end of stream, no XSLT to handle transforming the XML from the RSS feed, but wait, there’s more. This array of objects is now connected to the entire PowerShell ecosystem. PowerShell is based on .NET so you can use ADO.NET to insert it into a database, use
Invoke-RestMethod again and post it to another REST endpoint or spin up Microsoft Excel and control it via its COM API. And that my friends, is the two foot dive into the PowerShell ocean.
PowerShell is Microsoft’s task automation framework, consisting of a command-line shell, an integrated scripting environment (ISE), a scripting language built on .NET Framework, an API allowing you to host PowerShell in your .NET applications, and it is a distributed automation platform. This means if you have PowerShell running on another box, you can remotely execute PowerShell there, if you have the credentials.
What you need to do is launch the PowerShell console. On my Windows 8 box I press the Windows button, type “
powers“, and hit enter.
Great! I’ve got a blank blue screen. Now what?
Why C is a more practical and enticing programming language than you might think.
Choosing a programming language for that project you’re working on is a fairly straightforward decision: it needs to be fast, easy to use, and it must come with enough bells and whistles to keep you from re-inventing the wheel every time you want to do something.
Looking at this criteria, aside from the fast bit, the C language may not be the first one that pops into your head. After sitting down with Ben Klemens, the author of 21st Century C, I am now looking at C as a more practical and enticing alternative than I would have thought possible.
21st Century C sets a precedent in presenting C as a language that is a lot easier to use, and has more library support than many people think. If you are not up to date on the latest that C has to offer you may not be aware of the simplicity and elegance of the language. These strengths are backed by the C99 and C11 standards, but mainly they are built up on the development of libraries and modern tools for building and multi-threading in C. Read more…
Rob Pike on how Go fits into today's computing environment
The Go programming language was created by Rob Pike, Ken Thompson, and Robert Griesemer. Pike (@rob_pike) recently told me that Go was born while they were waiting a long while for some code to compile — too long.
C++ and Java have long been the go-to languages for big server or system programs, but they were created almost 30 and 20 years ago, respectively. They don’t address very well the issues programmers see today like use of concurrency and incorporating big data and they’re not optimal for the current programming environment.
One main reason that Go will succeed is how it deals with concurrency. It outpaces Java and C++ as well as Python, Ruby, and all the other scripting languages. It simply provides a better model, with Java a close second, that is able to work within the computing environment into which it was born.
David Griffiths on C's consistent popularity and what the language can do for you.
In this Code podcast, "Head First C" co-author David Griffith discusses C's continued popularity and why C and Arduino work well together.
Greg Shackles on using C# and .NET to build apps that work across mobile platforms.
Web developer and author Greg Shackles reveals the advantages of using C# over C++ for writing mobile apps. He also explains why Android and iOS developers should give C# a serious look.
Greg Shackles on why C# makes sense for mobile development.
Find out why using C# for cross-platform mobile development will take you less time and less code while bringing your apps to a wider audience.
Medical devices are remotely hacked, Google Maps get a price tag, and Linus Torvalds really doesn't like a certain language.
If you own an insulin pump, someone out there might have a hack with your name on it. Google decides to make high-volume Maps API users pony up some cash, and the creator of Linux goes after C++.
Steve Jobs and the App Store, goodbye to Dennis Ritchie, and an internal Google critique goes public.
Better late than never, a few thoughts on Steve Jobs. Also, a Unix pioneer leaves us, and Google's dirty laundry is accidentally hung out to dry.