PDA

View Full Version : [SOLVED] does a program have to be written in totally one language?



-grubby
January 1st, 2008, 09:07 PM
so basically what I'm asking is does a program have to be written in 1 language or can different components be different languages? I heard that openoffice is written in C and C++

Peyton
January 1st, 2008, 09:09 PM
Yes, a program can be written in more than one language.

Wybiral
January 1st, 2008, 09:16 PM
People do it all the time, when you use a library in a language like C++ or even something higher like Python, it may very well be written in something lower like C. AJAX-based web applications often have Javascript communicating back and for with Python/Ruby/PHP so the application is a combination of Javascript and a server language. Speaking of Python, it's very common for larger applications to use small chunks of C or PyRex code to increase runtime efficiency.

-grubby
January 1st, 2008, 09:17 PM
ok thanks guys!

Sporkman
January 2nd, 2008, 01:53 AM
C and C++

Those are the same language, C++ just has extra fuctionality added.

LaRoza
January 2nd, 2008, 02:19 AM
Those are the same language, C++ just has extra fuctionality added.

They are not the same language at all.

C and C++, besides a common syntax, are not the same. In fact, the best way to be a poor C++ programmer is to think it is C.

By "extra functionality" add an entirely different way of programming.

slavik
January 2nd, 2008, 02:31 AM
even though you can write different pieces of a program in different languages, getting them to work together might be a PITA.

Sporkman
January 2nd, 2008, 02:37 AM
They are not the same language at all.

C and C++, besides a common syntax, are not the same. In fact, the best way to be a poor C++ programmer is to think it is C.

By "extra functionality" add an entirely different way of programming.

Meh - same syntax + compiles in the same compiler = same language in my book. The "way of programming" is the way you use the language, not the language itself. The extra functionality in C++ allows you to use the the Jedi OO way, but the underlying language is the same, IMO.

Semantics. My programs use OO to a degree, but I also use printf, fopen, etc. The compiler doesn't care. I guess my language is "C/C++".

Wybiral
January 2nd, 2008, 02:52 AM
Meh - same syntax + compiles in the same compiler = same language in my book. The "way of programming" is the way you use the language, not the language itself. The extra functionality in C++ allows you to use the the Jedi OO way, but the underlying language is the same, IMO.

Semantics. My programs use OO to a degree, but I also use printf, fopen, etc. The compiler doesn't care. I guess my language is "C/C++".

OO is not the only difference (but even if it were, that's a big enough difference to justify completely different design strategies). Don't forget about templates, passing by reference, memory allocation being built-in (not functions in a library like C), OO streams, safe strings, and the STL (that's a big one), function+operator overloading, RAII design pattern?

You can use the C++ compiler to compile C code, but that doesn't mean you're programming in C++. In a real C++ project, you'll get shot for using printf/fopen, there are streams for that kind of stuff!

LaRoza
January 2nd, 2008, 02:56 AM
Meh - same syntax + compiles in the same compiler = same language in my book. The "way of programming" is the way you use the language, not the language itself. The extra functionality in C++ allows you to use the the Jedi OO way, but the underlying language is the same, IMO.

Semantics. My programs use OO to a degree, but I also use printf, fopen, etc. The compiler doesn't care. I guess my language is "C/C++".

I use gcc to compile Fortran 77 programs....

You can write OO code in C, http://www.cs.rit.edu/~ats/books/ooc.pdf

If you get to the core of it, all languages are the same, but superficially, C, Fortran and C++ are different langauges.

Sporkman
January 2nd, 2008, 03:04 AM
OO is not the only difference (but even if it were, that's a big enough difference to justify completely different design strategies). Don't forget about templates, passing by reference, memory allocation being built-in (not functions in a library like C), OO streams, safe strings, and the STL (that's a big one), function+operator overloading, RAII design pattern?


Yeah that's true, there is a lot more. For me, at least in my personal programming, my programs are relatively small, so I just do stuff & don't worry about whether it's C or C++. For the big stuff at work, I'm doing mostly what you'd call C++, and the IO stuff is hidden behind various APIs, though reading through the code I or others have written, you might occasionally find some stuff you'd call "C".

When I learned the language(s), the books I used referred to it (them) as "C/C++", so I never really made the distinction, In fact, I've never heard of anybody considering them as different languages until this forum.

CptPicard
January 2nd, 2008, 04:08 AM
In fact, I've never heard of anybody considering them as different languages until this forum.

They have their own separate standards and definitions, grammars, compilers... try writing C++ with a C compiler and it's not going to work. A C++ compiler is going to like C more, but it will still complain at points as C is not a pure subset of C++.