![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Programmer
|
Why shouldn't we use System();
Quote:
1) its commands are totally platform dependent. So you wont be able to use your sources on other OSs 2)a shell is started which could do a lot.. for example stop the programm, or do smth else (depends on the kind of shell) 3)Everytime you use system u start a shell, this means that code isnt fast at all , and since the shell will be exited after the system-independent function call , you are not able to change environment vars, because the changes will be undone when exiting the shell... 4) a real important thing is the risk ,while programming cgi-codes with system ... if some user for example can make some input in a stream or string and you call system(input.c_str()) or system(input.str().c_str()) he will be able to use meta signs ( which every shell has) to execute it with other permissions or something else.. ( something like "; command_to_do;other_command i could imagine on *nixesbut dont say u will parse the input, in my opinion >>Instead of checking input for shell characters, stop using a shell<< if the system()-shell is started with root permissions and it fails to terminate in a cgi programm this would be another bad thing too. 5) U dont need a shell in most of the cases ( indeed,i know that there are some)one example where you dont need it is system("Pause");6) In most of the cases you can read system() the job it does isnt worth the costs of starting and exiting a shell!. i hope nobody is mad about this post... well i just want to list the facts for people who are interested or maybe start programming in c or c++. They cant know that, so its a fine thing to start coding without such things..... well, thats my opinion... so far...
__________________
of all the things he has lost, i think he misses his mind the most typedef typename pizza_t<oven_policy<225,12.5>,ingredient_policy<salami,mushroom,cheese> > Pizza; |
|
|
|
|
|
|
#2 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 600
Rep Power: 4
![]() |
I would agree to stay clear of system() when alternatives are available in final, completed projects. I have no objection to it when writing small test programs for yourself just to find out how something works -- if I'm the only one going to see the program, what difference does it make? If you're going to turn the code in to your instructor at school then you should find out from him/her about coding standards.
|
|
|
|
|
|
#3 |
|
Programmer
|
well, system is a standart functions, thats not the catch...
I do belive that its always good to write source code as good as possible, in large projects, libs , in apps or just in test modules or while learning a language. Using non-standart or such... "dangerous" or specific functions should be avoided from the beginning, otherwise it could become a bad habit. if there is an alternative way there is no reason to use it... and in case of a little test code or module for anything... i think I would be really angry to realize that my code doesnt run on another machine because of such a little thing... and another thing.. i was talking about recommending or telling about it , I know that the default (hello world )project on DevCpp uses System. and of course i can understand that thats not an important thing while you are learing the basics... but its never wrong to know ( even in the early times ) that there are alternatives... but I have to admit that you are right, the dangers i told about are not important ( wont appear) in little "hello world" sources or smth similar. I wasnt just talking about System("Pause"); i was talking about it in gerneral, ( for example in cgi apps/libs) so far
__________________
of all the things he has lost, i think he misses his mind the most typedef typename pizza_t<oven_policy<225,12.5>,ingredient_policy<salami,mushroom,cheese> > Pizza; |
|
|
|
|
|
#4 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 600
Rep Power: 4
![]() |
I don't really have any object to what you are saying -- except maybe that it is "dangerous". College and university profs often teach non-standard C with ancient compilers. Take for example use of Turbo C compiler in the classrooms. That is a horrible way to teach anybody how to write c programs because most 32-bit compilers today don't support any of the old 16-bit Turbo C functions. Then students complain biterly because their old Turbo C programs can not be compiled by those "stupid" Dev-C++ and similar compilers. Turbo C should be permanently banned from all colleges and universities around the world! Any prof teaching it should have his toung cut out!
system() and other similar functions are really intended to execute other programs and scripts and should not be used instead of standard C or C++ library functions or os api functions. |
|
|
|
|
|
#5 |
|
Programmer
|
Well:
full ack! i know what you are talking about. unfortunately a lot of profs from many universities teach the way you
__________________
of all the things he has lost, i think he misses his mind the most typedef typename pizza_t<oven_policy<225,12.5>,ingredient_policy<salami,mushroom,cheese> > Pizza; |
|
|
|
|
|
#6 | ||||
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
Quote:
system("pause") is, however, non-standard (or, more accurately, there is no guarantee that system("pause") will do anything). It just happens to work under Microsoft operating systems, but it doesn't under others. Quote:
Quote:
C and C++ are actually fairly limited on their own. In practice, it is often mandatory to use system or compiler specific functions. If one could not do that, one would be limited in many ways: no GUI, no direct keyboard input, no threads, no networking, no directory listings, etc etc. Accordingly, a better rule is to be portable where possible, but accept the need to do non-portable things at times in the interests of getting things done. Quote:
One part of professional software engineering is to be explicit when you do things non-portably. A lot of effort goes into defining higher level functionality which (for example) may be implemented using one approach on system A (eg a windows box) but is implemented using a different approach on system B (eg a unix box). |
||||
|
|
|
|
|
#7 | |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#8 | |
|
Programmer
|
thanks ,Cerulean
anotherone is getchar(); and even if u dont feel like usuing a standart function use getch(); from conio.h instread of system Quote:
my current job uses the platform (well designed ) gui lib wxWidgets and the whole project is going later run on linux and windows. i know that there are a lot of situations the customer just wants a specific solution. and ,of course, then platform independency isnt interesting. but i spend my time with writing little libs or smth and so i want to be as independent as possible. and if someone begins programming i think its good to learn the independent things first ...and later the os-dependent. but if there is no independent way , then use the os-apis ..
__________________
of all the things he has lost, i think he misses his mind the most typedef typename pizza_t<oven_policy<225,12.5>,ingredient_policy<salami,mushroom,cheese> > Pizza; |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|