Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a idea for a program and have began laying out the software design concept in a traditional SDLC model of charts and instructions for what I want all parts to achieve.

A quick explanation of my idea is this, I want to build a IDE for a tablet that is intended to run on mobile platforms but can also be ran on Windows, Macs, etc. This platform will have a couple very unique concepts in it for graphical programming interface and remote application server usage for compiling and project management like a GIT. I would like to achieve this without having to revamp the code for each system and believe C will allow me to stay close to my goal of no specific platform programming.

The Question

I would assume I want to avoid OS specific calls and (or) external libraries (stick to standard library much as possible) to a minimum. What would be the best practice of doing this while still completing a nearly finished program (until I make targeted platform adjustments)? Would C be my best option to achieve this?

Why I ask.

I have been really interested in using C because of its portability, ability to utilize memory, program sizes are smaller and more efficient, and integration in to nearly all mobile platform. I have done a fair amount of homework on C and am halfway through the “C Programming Guide, second edition” by Kernighan and Ritchie. I have even ordered some books on building compilers and OS design to assist in some fundamental concepts that I believe are relevant to my idea.

share|improve this question

closed as not a real question by Mark Trapp, BЈовић, gnat, Walter, ChrisF May 12 '12 at 11:33

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

You're kind of putting the cart before the horse here. Generally, if you have the liberty of picking the language then you pick based upon a strength of the language solving a particular problem within the project. Your question is kind of scattered, and honestly, I'm not sure what you're asking. I suspect there is merit in your Q, but it doesn't come across. And fwiw, I didn't down-vote you. Rather, I upvoted to give you a chance to revise your Q. –  GlenH7 May 10 '12 at 21:28
The C standard library exists to allow you (the coder) to write code portably across different systems, but under the hood it has to do platform-specific operations (like file access). If you are building something like an IDE, there will really be no avoiding platform-specific stuff, considering that C (the language and stdlib) has no concept of ideas like threading, graphics, GUIs, or networking. There are libraries that, just like libc, abstract away much of the platform-specific code, but you will not be able to use just naked C and libc if you are writing something like an IDE. –  birryree May 10 '12 at 22:02
@birryree Thank you. Very nice advice. So not to simply abandon the concept of using C. I could still utilize its portability by building in control classes for ideas that you mentioned or build them to be independently done by the program? –  user51762 May 10 '12 at 23:12
Yes, you can build abstractions around platform specific stuff and create a general use wrapper around GUI stuff, for example. You shouldn't start off thinking you will support all the mobile and desktop environments, though, as that will be very time-consuming very fast if you have to abstract 7 windowing systems and 7 threading models and 7 networking models...I strongly recommend picking something to do rapid prototyping in, to show that conceptually, your IDE ideas will work as you want. –  birryree May 10 '12 at 23:19
Yes, my point was that if you were going to be abstracting and creating your own wrappers, you would have to learn about each platform you're abstracting for. That means learning about the libraries for each platform, how to make a GUI in Windows, Mac, Linux, on mobiles devices. How networking and threading is done in each environment. C is a portable language, it's just unfortunate that many things are platform specific! There's a reason why frameworks like Qt and Gtk and Monotouch (and more) exist - people wanted to save others from having to write stuff that wasn't really related to work. –  birryree May 11 '12 at 2:02

3 Answers 3

up vote 4 down vote accepted

The only way to do this is to create an interface which will sit over all your OS-dependent code, such as rendering, and then write your portable components on top of that, then provide various OS-specific implementations.

However, it should be noted that C is not a good choice of language- for example, it's Standard library offers little functionality, and the language features do not scale well.

Edit: What do I mean by "Doesn't scale well"? Well, it's easy to write a toy C function that does not leak memory, or overflow it's buffers, but when you try that for a 1MLoc program, it's realistically impossible. Not to mention that C doesn't offer any useful generic language features or functions.

share|improve this answer
Do you you think you can further explain what you mean when say C does not scale well? Do you mean something like not able to update the program with significant changes or as regularly? Thank you for your advice it is well received. –  user51762 May 11 '12 at 4:21
I'm not sure anybody knows what they mean they say "doesn't scale well." –  Erik Reppen May 11 '12 at 7:25
In terms of SDLC, scalability means the ability to adapt to the existing program structure. –  user51762 May 11 '12 at 7:48
I do not think it impossible for a 1MLoc scenario, just 10 times unproductive because of the search on how to insert your changes you wish to implement. But I guess my real question is (which will be another thread.) even with all the extra effort of doing it in C would it pay off in versatility and speed? –  user51762 May 12 '12 at 19:39

Most likely, you're not going to get this right on the first go. That's fine; most great software has been rewritten several times (either from scratch, or through long and tedious evolution) before reaching greatness.

So don't make life too hard for yourself; pick a platform and write a prototype that exhibits the features you think are the most valuable. When it turns out your novel ideas are actually useful in practice, then, but only then, does cross-platformness become an issue.

share|improve this answer
Real good advice. Thank you for the encouragement. –  user51762 May 11 '12 at 4:12

There are two ways to go:

1) Either you write your platform-independent code so that it contains a number of functions to be called by the application.

2) Or you write a function library header file containing an abstract interface of function templates. Your platform-independent code calls these functions, but they are to be implemented by the specific platform port. In OO design terms, it is called inheritance from an abstract base class.

Example of 1):

// caller
#include "x.h" // your platform-independent module

x_init(); // from x.h
x_do_stuff(&variable); // from x.h

draw(variable); // some platform-specific code implemented by the application

Example of 2):

// x.h, your platform independent module

#include "gui.h" // your function definitons for the GUI to implement

void x_do_stuff (void)

// gui.h, your function definitions for the GUI to implement

void gui_draw (stuff_t stuff);

// gui_windows.c, a platform-specific port for a certain system
#include "gui.h"

void gui_draw (stuff_t stuff)

Advantages of 1) is that it is the quickest and easiest to implement, and also the most generic. Disadvantages is that the whole program flow is left to the caller to define, you would have to write a whole new program from scratch for each port. 1) could also possibly be more cumbersome to handle, because the user will be required to call functions in a certain order.

Advantages of 2) is that you have full control of the whole program yourself, and each platform port is only concerned with implementing the system-specific functions, so the porting will be quicker and easier. Disadvantages are that it is a very hard, delicate task to define generic function templates, especially without knowing the specifics of each and every port. If you define the function templates poorly, you will end up with lots of problems when porting. The problem is the same as the one you face when designing abstract base classes: it is almost impossible to pre-define an interface without having to change it several times during development.

share|improve this answer