Tuesday, July 27, 2010

About C / C++ / C#: A Week of Step Changes

If you can't see this email, click here

About.com

C / C++ / C#

Fundamentals

Tips & Tools

Going Pro



From David Bolton, your Guide to C / C++ / C#
Maybe I'm getting old but sometimes it would be nice not to keep on upgrading my software. I don't mean small incremental changes like upgrading software on a smart phone but major version changes like going from Office 2003 to Office 2010 (and Outlook Express to Outlook 2010), Visual Studio 2008 to 2010, a new distro of Ubuntu etc. It's probably just a programmer's state of mind; if I don't have the most current (and newest and perhaps buggy!) version, I just don't feel right. So I'll probably still be complaining about upgrading in 10 years time! Catch you next week...

What is Memoization?
A bit of a modern computing phrase this with recent popularity in some functional languages like Haskell. But it's not that complicated. Simply put memoization is an optimization technique used in functions so the first time the function is called for a given set of inputs, it calculates the result and caches it,, perhaps in an array. On subsequent calls of that function with the same inputs used earlier it returns the appropriate cached value. It's not actually new to C++ either. 12 years ago Paul McNamee at a computing facility of John Hopkins University extended automated memoization to C++. The idea being that some functional languages can provide automatic memoization without programmers writing an extra line of code. His code (it's C++ btw even though the file extensions are .c) does this.

C++ Optimization Question Revisited
Screen Dump of WordPress iPhone AppI've mentioned it before but WordPress on the iPhone/iPad has been continually improved and if you're into developing iPhone Apps is quite sophisticated. The same source code has been enhanced for the iPad as well. Study of the extensive source code (92 header files alone for the classes!) would probably teach more than a dozen books. With the Subversion client installed you can fetch the entire current source or view it online (same url) file by file. This is an App that lets you interact with a web server running WordPress and add new posts, edit comments etc to any WordPress blog, including photos. It has text management and editing, photo selection from the Camera Roll or using the Camera and resizing. Want to see how that's done? The code is all there.

How to Maintain Database Integrity
Here's the problem. Databases are stored in files and disks fail sooner or later. Either that or applications crash halfway through writing them. Without any assistance, databases would get corrupted very quickly. It was difficult enough but manageable working with single user random access files as I did in the past but when you get multi-user database servers where data is being written and read at the same time then it needs careful design to avoid this situation. One method used is a journal. Before changing the database, the record to be changed is copied into a journal which is a separate file. The change is held in memory until some time when say the memory buffer is full or the database is told to commit changes. These changes are then written to disk and once complete, the journal file(s) are deleted. If anything went wrong during the write, the journal files get rewritten thus leaving the database in a consistent state. This description is very simplified. If you want to know the nitty gritty, then read about journaling which is how SQLite does it. Interestingly SQLite is just introducing WAL (Write Ahead Logging), an alternative method in the latest SQLite version 3.7. This is generally quicker and works better in a multi-user situation.

Never Programmed Before? Start Here
Learn how to program computers as a living or just for recreational fun. Find out how to make a computer do what you want.

 


C / C++ / C# Ads
Featured Articles
Other Blogs You might find Interesting
Welcome to the C Area with Articles about C Programming
Welcome to the C++ Area with Articles about C++ Development
Welcome to the C Sharp Area with Articles about C Sharp Development
Learn about Commercial Software Development
All about Games Programming

 

More from About.com

Plan a Unique Vegas Wedding
The minister, music and champagne are just the beginning -- why not get married aboard a helicopter or have a pirate swing in to deliver your rings? Arrrr! More>



Join About.com's User Panel!
Share your opinions and help us make About.com more relevant, informative and enjoyable to use. More>




This newsletter is written by:
David Bolton
C / C++ / C# Guide
Email Me | My Blog | My Forum
 
Sign up for more free newsletters on your favorite topics
You are receiving this newsletter because you subscribed to the About C / C++ / C# newsletter. If you wish to change your email address or unsubscribe, please click here.

About respects your privacy: Our Privacy Policy

Contact Information:
249 West 17th Street
New York, NY, 10011

© 2010 About.com
 


Must Reads
Programming Challenges
About C, C++ and C#
C++ for Beginners
C++ Programming
Intro to OOP

Advertisement

Tuesday, July 20, 2010

About C / C++ / C#: Back on the iPhone

If you can't see this email, click here

About.com

C / C++ / C#

Fundamentals

Tips & Tools

Going Pro



From David Bolton, your Guide to C / C++ / C#
I'd been doing other non iPhone programming and it's worrying how quick I can forget simple things but after a couple of hours it came back. However there's all the new IOS 4 stuff to learn. it just never ends! In 15 months time I will have been working almost continuously programming for 30 years. I started on Apple hardware (Programming an Apple II in Basic) and here I am still on Apple! Have a great week!

Become a "Whys" Guy
I like to know why something fails. Successful code is boring because it just works but if it goes wrong then knowing why it went wrong is very instructive. Some of the most interesting problems have been from peering beneath the hood and finding out what went wrong. Think of it as less of a failure and more of an opportunity to learn. My favorite was a website that I worked on back in the Dot Com boom/bust of 2000. We had a COM component called in the web pages that talked to SQL Server 6. When the site traffic caused the CPU to hit a modest 5% then the component and the website crashed. It turned out that it was an older compiler to blame. I had a hunch and spent 30 minutes changing it to work with the next version of the compiler and that fixed the problem. The earlier compiler had incorrectly generated code that interacted with COM and this was fixed in the next version. One approach to solving problems is "the little kid" approach. Keep asking why, at least 5 times. Apparently Toyota do this to improve quality. Why did the website crash? Because the component crashed. Why did the component crash? Because the compiler generated bad code. Why didn't we use a different compiler? No one knew how to change the code. Why did no one know? Because it was a new compiler and no one was familiar with it. Why...

A Unique Way to Make Money
Unless someone derives a way of factorizing large numbers quickly, this should be cryptographically secure. BitCoin is a virtual digital currency. There's no central server to break into, it's all networked and uses cryptography to stop people duplicating money or spending it 2, 3 or more times. The idea is that people generate their own BitCoins using the open source software to do a lot of processing. However there will never be more than 21 million BitCoins in existence. If this sounds limiting, think of them as large virtual chunks of gold and each can be split into 100 million parts (each BitCoin fraction can go to 8 decimal places). Anyway I doubt if there are 21 million real gold bullion bars in existence. According to their website there are 16 companies accepting BitCoin including a MMO (game) and a casino. I'm not an economist so I don't know if this is viable but I do know that if there is a way to game the system and make money out of it there will be some very smart brains trying to do that. For instance doing arbitrage between FX rates, or using the power of super computers to generate a lot of BitCoins. The main thing that bothers me is that anyone with a computer can create BitCoins. It's not like everyone with a printer can print money! If you download the Linux Tar File from Sourceforge, it contains version 0.3 of the Coin generating software which is written in C++. Disclaimer I have no connection financial or otherwise with BitCoin and suggest you exercise caution in doing anything that could cost you money.

Back on the iPhone
I'm working on an App and during a moment of downtime took a look at iPhone open source projects in three online repositories. Note that while searching may produce hundreds of results, it's often a lot less, typically under 1/3rd of the results.
  • Sourceforge.net - 313 results but only 85 in Objective-C
  • Codeplex.com - 79 results but I think under 30
  • Code.Google.com - 1890 with label iPhone.
Realistically there is perhaps 500-750 across all three sites in varying states of activity. But if you're looking for source code examples, it's not a bad place to start. Not all open source is found in repositories; for instance the Sparrow Framework looks quite promising and is an open source OpenGL framework by an Austrian developers Incognitek. Sparrow is a library that lets you develop OpenGL iPhone / iPad applications without needing to use the OpenGL framework itself and is written completely in Objective-C.

Code Library for C, Objective-C, C++ and C#
This is the code library with all examples, free downloads for this topic.

 


C / C++ / C# Ads
Featured Articles
Development Projects from Initial Design to Completed Code
Reviews of Software - Tools, Compilers, Editors etc
Book Reviews
Top Tools, Utilities and Resources
Glossary of Programming Terms
Never Programmed Before? Start Here

 

More from About.com

Plan a Unique Vegas Wedding
The minister, music and champagne are just the beginning -- why not get married aboard a helicopter or have a pirate swing in to deliver your rings? Arrrr! More>



Join About.com's User Panel!
Share your opinions and help us make About.com more relevant, informative and enjoyable to use. More>




This newsletter is written by:
David Bolton
C / C++ / C# Guide
Email Me | My Blog | My Forum
 
Sign up for more free newsletters on your favorite topics
You are receiving this newsletter because you subscribed to the About C / C++ / C# newsletter. If you wish to change your email address or unsubscribe, please click here.

About respects your privacy: Our Privacy Policy

Contact Information:
249 West 17th Street
New York, NY, 10011

© 2010 About.com
 


Must Reads
Programming Challenges
About C, C++ and C#
C++ for Beginners
C++ Programming
Intro to OOP

Advertisement

Tuesday, July 13, 2010

About C / C++ / C#: Congrats to Stole

If you can't see this email, click here

About.com

C / C++ / C#

Fundamentals

Tips & Tools

Going Pro



From David Bolton, your Guide to C / C++ / C#
Who won Programming Contest 36 with less than a 10th of a second over the other entrant. Commiserations to a 3rd entrant who had to retire because his very fast code wasn't correct! Have a great week and keep sending your questions, requests etc in! I try to reply to everybody who writes to me.

xScreenSaver Collection for Mac/Linux
Most of my programming is Windows and iPhone but occasionally my Mac gets other uses such as compiling Mac code. A recent example is xScreenSaver; Jamie Zawinski has created and collected 200 screen savers in both binary and source form. Don't ask him for Windows versions as it won't happen ever! If you've got a Unix System running X11 then you may already have this collection.but if you can't be bothered compiling the Mac version just use the DMG to install the binaries.

Microsoft Tidies Up Web Programming
I'll give Microsoft their due, they don't stop trying to get the word across. Their latest initiative (still in Beta) is WebMatrix which is an easy to install free bundle of IIS Developer Express (a development Web server), ASP.NET, and SQL Server Compact (an embedded database). It uses the latest version of the Web Platform Installer that simplifies installation and makes sure everything is there. Curiously, they've also got a gallery of open source applications which includes well known PHP Apps such as WordPress. WebMatrix lets you code, test, and deploy both ASP.NET and PHP applications side by side. More importantly, if you've ever deployed an ASP.NET website to a live server you'll know the joy (not!) of moving the database, website config files etc. This is all handled by WebMatrix. It even helps improve your Search Engine Optimization by offering suggestions to improve it. If you have .NET 4 installed then WebMatrix only a 15 MB download. Otherwise it's 50MB. There's a very detailed overview of WebMatrix on Scott Guthrie's blog.

Make your .NET 4 Programs More Complex!
The System.Numerics namespace in .NET 4 supports Complex numbers. Complex numbers have two parts, both numbers, a real part and an imaginary part which is a multiple of the square root of -1. They can be very handy in some engineering and maths calculations, so long as the imaginary part eventually resolves to 0! Internally the two parts (real and imaginary) are stored as double precision numbers and operators provided to do basic maths (add, subtract, multiply and divide, unary negate) and square roots. To be honest, most people except a few electronics engineers will never have the need to use Complex numbers. The imaginary part is usually called i or j (in electronics as i is a notation for electrical current) and although the square root of minus one doesn't exist as a real number, it is a useful mathematical method for applying vectors in some situations. This page provides a couple of examples of uses of complex numbers. I promise I will never ever mention them again!

Never Programmed Before? Start Here
Learn how to program computers as a living or just for recreational fun. Find out how to make a computer do what you want.

 


C / C++ / C# Ads
Featured Articles
Other Blogs You might find Interesting
Welcome to the C Area with Articles about C Programming
Welcome to the C++ Area with Articles about C++ Development
Welcome to the C Sharp Area with Articles about C Sharp Development
Learn about Commercial Software Development
All about Games Programming

 

More from About.com

Plan a Unique Vegas Wedding
The minister, music and champagne are just the beginning -- why not get married aboard a helicopter or have a pirate swing in to deliver your rings? Arrrr! More>



Join About.com's User Panel!
Share your opinions and help us make About.com more relevant, informative and enjoyable to use. More>




This newsletter is written by:
David Bolton
C / C++ / C# Guide
Email Me | My Blog | My Forum
 
Sign up for more free newsletters on your favorite topics
You are receiving this newsletter because you subscribed to the About C / C++ / C# newsletter. If you wish to change your email address or unsubscribe, please click here.

About respects your privacy: Our Privacy Policy

Contact Information:
249 West 17th Street
New York, NY, 10011

© 2010 About.com
 


Must Reads
Programming Challenges
About C, C++ and C#
C++ for Beginners
C++ Programming
Intro to OOP

Advertisement