Tuesday, October 26, 2010

About C / C++ / C#: A Week of C Posts

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 don't plan these, but I just noticed that the bulk of these week's blog entries were C related and this newsletter will thus be a C special. Normal service next week, honest! It's been one of those weekends. I had to go into work on Saturday, got nothing done after 5 hours because the database wasn't ready and left my keys there by mistake. I couldn't remotely log in (the security device is on the keyring) and finish testing a release. So I had to go in again on Sunday... doh! Have a great week!

Crossword Maker in C
Screen shot of online crosswordRobert Morris at Harvard (I don't know when or if he is still there but the source files are dated from 1995-2004) published a crossword maker. It's written in C and he has made the source code available as well as providing an online version. It uses pattern files to get the black squares and there are a couple of example files so easy to create your own. The links he published for word lists in the readme file have alas rotted away but there are plenty of word lists on the web, for instance Scrabble word lists on Mike Wolfberg's site. I'm tempted to convert this to C#, unless anyone else wants to have a go. As this seems to be platform independent code, I've added it as a permanent link in the C Games code library.

C Style Guide As used in Linux
This follows on from the earlier post about typedefs. If you are au fait with the Linux Kernel Source distribution tarball then you'll know that Linus Torvalds wrote a C programming style guide that is included with it. It's also available in various places on the web. It has a few nuggets of wisdom, many from Kernighan & Richie, so I recommend it as a must read if you are a C programmer. Interesting points worth perusing are:
  • Indentation 8 chars.
  • Break long lines and right justify
  • Spaces, use of
There's the odd joke about Microsoft and Pascal programmers in there as well so it makes interesting reading!

Caucus - A Classroom Application Server in C
This is a different way of doing things but I suspect it could work for other uses. Caucus is an application server that runs on a Linux/Unix server and implements a classroom through a web server like Apache. It provides:
  • A "room", with a class list. Only members can attend, and teachers and assistants have special privileges.
  • Assignments, with scheduled start (visible) and stop dates, and due dates.
  • Lessons and content -- anything that can be put on (or linked from) the web.
  • A gradebook. Students can always (and only) see their own grades.
  • Quizzes -- with automatic scoring
  • Conversations that are highly structured, yet easy to follow and participate in.
In technology terms this is old- a mid 90s way of designing web solutions before scripting languages like PHP/ASP.NET existed and probably before Java application servers as well. However it is still a very good example of a solution to a problem and a major piece of work.

Development Projects from Initial Design to Completed Code
Each project is a complete application with notes on the requirements, the design, the architecture, code and final project review. With full source code in C, C++ or C#.

 


C / C++ / C# Ads
Featured Articles
Reviews of Software - Tools, Compilers, Editors etc
Book Reviews
Top Tools, Utilities and Resources
Glossary of Programming Terms
Welcome to the C++ Area with Articles about C++ Development
Other Blogs You might find Interesting

 

More from About.com

Is it a Cold or the Flu?
Knowing whether you have a cold or the flu can help you treat your symptoms more effectively. More >



Concerned About Your Drinking?
This short quiz can help you identify whether or not you have a drinking problem. Take the quiz now >




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, October 19, 2010

About C / C++ / C#: URL Shorteners - The Maths

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#
Last week at the codeface was rudely interrupted for a couple of days by by a stinking head cold that thankfully has moved on. We've had more entries for Contest 40, which should be marked again by the time you read this (four entrants now) and Contest 41 will appear by Wednesday or Thursday. As a heads up for that, take two list of 500,000 numbers and just output the numbers that are different as fast as possible. Simple! Make it a good week!

Comm100-Open Source Web Forum Software
Comm100 Forum SoftwarePHP has the advantage over ASP.NET of having being around longer, easier to get into cheaper hosting and consequently there are many more packages around. However ASP.NET open source does exist and Comm100 Forum Software is an excellent example of it. It's an ASP.NET forum web application written by Comm100, a Canadian company. They also provide free forum hosting if you don't want to host this yourself, but otherwise you will need SQL Server. With separate control panels for admins, moderators and users, fine grained permissions, configurable look via template, sticky topics, and unlimited forums and much more it's pretty much what you want from a web forum. I think you'd need either Full Visual Studio or possibly the Visual Web Developer and Visual C# Express to make changes and rebuild it. I installed it on my PC and have spent all morning arguing with myself in my own forums! It ended badly, I banned myself!

URL Shorteners - The maths
My computer science degree was about 75% maths, back in the dark ages before the Internet and personal computers existed so I still have a fondness for a bit of maths. A URL Shortenening site like goo.gl, tinyurl.com, bit.ly etc provides an indexing mechanism. A long url is stored in a database table and the index of that row or some key for it is converted into a short alphabetic code. As the alphabetic code shouldn't be too cryptic or difficult to type it's often restricted to letters, digits plus a few easy to recognize characters such as +-. A-Z and a-z is 52 characters, 0-9 adds another 10 and +- makes 64 in total. If we choose a 5 character code (e.g. A6gR4) then that gives us 64*64*64*64*64= 645 which is 1,073,741,824 aka one billion! Add a 6th digit and it increase to 64 billion or stick with 5 characters but use two extra characters like * and / and it increases to 1,252,332,576 which is another 250 million. This technique can be used elsewhere. Many messages can be written using a small subset of words in the English languages- says 2,000- 5,000 words. If each word is stored in a table then communication is possible between two people holding a copy of the table by just sending the index of each word in the message. Better still, this can be used as a one time pad by by adding a level of indirection and changing the indirection each time messages are sent. Consider the message "Steal red car Plate abc" where steal is stored in the database at index 501, the is index 5, red is index 72, plate is index 41, a is index 1245, b is index 865, c is index 1204. A one time pad might add 6 to each index or some other reversible method. So the message is first converted to the indices then modified by the one time pad, sent to the recipient and then reversed. Yes there is a URL shortener, in C#. It's actually in ASP.NET MVC 2 and by François Karman. JobPing is an MVC 2 web app and powers the Job search website jobping.com.

Program Your Mac in C#
It's been a good week for C# what with the Windows phones being launched (No I don't have one!) and now MonoMac which is a new foundation for building Cocoa Apps on OSX using Mono.< It's provided as an add-in to MonoDevelop, the IDE for developing desktop and ASP.NET Applications on Linux, Windows and Max OSX. The purpose of the framework is to provide bindings of the Objective-C Apis in OSX so they can be used by .NET. It helps that .NET was designed to be an interoperable framework. MonoMac isn't complete yet but enough bindings have been done to start creating C# Apps that run on Mac OSX. specifically these:
  • AddressBook (done)
  • AudioToolbox (done)
  • AppKit (About 10% left to be done)
  • CoreAnimation (done)
  • CoreFoundation (the parts that are needed, see the design principles)
  • CoreText (done)
  • CoreLocation (done)
  • CoreData (done)
  • CoreGraphics (done)
  • Foundation (the parts that are needed, and helper tools to support the rest)
  • WebKit (Missing DOM code)
Course they'd love to have contributors helping to bind the other frameworks and do other tasks. Scroll to the bottom of the MonoMac page for details if you're interested.

Other Blogs You might find Interesting
This is a list of Blogs that you might find interesting.

 


C / C++ / C# Ads
Featured Articles
Never Programmed Before? Start Here
Welcome to the C Area with Articles about C Programming
Welcome to the C Sharp Area with Articles about C Sharp Development
Learn about Commercial Software Development
All about Games Programming
Code Library for C, Objective-C, C++ and C#

 

More from About.com

Is it a Cold or the Flu?
Knowing whether you have a cold or the flu can help you treat your symptoms more effectively. More >



Concerned About Your Drinking?
This short quiz can help you identify whether or not you have a drinking problem. Take the quiz now >




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, October 12, 2010

About C / C++ / C#: A Fun Week - Not!

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#
Last week saw me maintaining some existing bad code and trying to cope with a number range that was sparsely populated and yet had to be extended. It was a thorny problem but one I eventually cracked. Details below under Evils of Number ranges. Congrats to Pedro for his superbly fast answer to Contest 39. It was nice to have 13 entries. We've already got two for Contest 40. Back next week!

Final Positions for Contest 39
Congrats to Pedro Graca whose ultra fast time was never going to be beaten. Thank you to everyone who entered. For once I got all entries built and run without any problems after the resubmitted C. Thanks Dinh! It's quite remarkable that the timing difference between 4th and 9th positions was only 0.0000207027 of a second. There were 6 entries all in that time scale. As usual, all were built for release and run from the command line. The source code files for all 13 are now live as well.

The Evils of Number ranges
I've been maintaining an application that uses a particular database table. Each day some new rows are created and a few older ones deleted. Unfortunately the index for the table is made up of several different types of entities and each has a different possible range of integer values; it's possible that even though they're not all currently used they could be. Type a has 0-78,000, type b has 100,000- 90 million and type c has 100-999 million. To unify these easily, a previous developer came up with a scheme where an abstract member function GetNum(), was overridden for each of three types. Effectively these added a billion so the range of values was 1 billion up to 1.999 billion (with lots of gaps). There was a reason for doing this, because entities of the three types could be mixed in with this combined type. Messy? Yes. Difficult to maintain? Extremely. Now it's been proposed to add a new type based upon the combined type but with another offset, however, it's not just a case of adding another billion. In theory it could be done as the unsigned range of 32 bit indexes is 0 to 4 billion. But even though there are no negative values, the code was written using int as the fundamental type so only the available values are 0-2 billion and the third type would push past the 2 billion max int value (INT_MAX in limits.h) code and database table and add another column to indicate the underlying type but managed to get past this limit by passing a string instead! Yuck! Using number ranges to classify types, while in theory a good idea is a time bomb. It's much better and generally more efficient to use a distinct value. Then all you need are a couple of mapping member functions between the range and the entity values.

List of Online Repositories and Pastebins
There seems to be so many such sites and paste bins that I thought I'd list them on a page and update as I go along. Interestingly some of them let you compile the code, one in over 40 languages! If you know of others that should be listed here, please email me at cplus.guide@about.com and I'll keep the page updated.

Development Projects from Initial Design to Completed Code
Each project is a complete application with notes on the requirements, the design, the architecture, code and final project review. With full source code in C, C++ or C#.

 


C / C++ / C# Ads
Featured Articles
Reviews of Software - Tools, Compilers, Editors etc
Book Reviews
Top Tools, Utilities and Resources
Glossary of Programming Terms
Welcome to the C++ Area with Articles about C++ Development
Other Blogs You might find Interesting

 

More from About.com

Is it a Cold or the Flu?
Knowing whether you have a cold or the flu can help you treat your symptoms more effectively. More >



Concerned About Your Drinking?
This short quiz can help you identify whether or not you have a drinking problem. Take the quiz now >




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