Which language to use to implement multiple Linux shell commands (homework) - plain C or C ++?

I need to implement several Linux shell commands for my homework - 5 or 6 of them, including ls. I don't know much about what parameters should be performed for each of the commands ...
I was planning to use C ++, but when I asked my colleague for advice on which language to choose - just C or C ++, he said that the interpreter is not is a program of traditional meaning, it is a functional tool, and it absolutely needs to be implemented in C.
My arguments in C ++ are great code reuse, better separation of concerns, and actually I don't know C very well - in fact, I learned C ++ and enjoyed it.
So, what do you think about this? Thanks in advance. This is an individual assignment - I mean for each person in my group, so there is no collaboration.
I have low level programming experience, pointers are arithmetic, void *, etc.

+2


source to share


12 replies


First . Use what you know.

There is no reason to enter uncharted waters if you can get there with a familiar route.

C ++ is a very viable option in your circumstance anyway. So you are not wrong to just use it.



Second . Your friend is wrong. (I would use harsher words, but I'll be pleased.)

C ++ and C are compiled languages. A C ++ program is absolutely a program in the traditional sense. Both C and C ++ are statically typed as well.

PS: You can use the C ++ compiler to create C programs. You can do everything that is available in C with C ++.

+9


source


You know C ++, you like it, so use C ++.

Or you want a problem, you want to learn C, which makes your homework feel useful, so use C.



PS. "must be implemented in C" is complete crap. Don't fall into this trap.

+7


source


It really doesn't matter. What is the most convenient for you to use? You can get pretty well written code in any language.

  • C if you are comfortable with procedural / modular programming paradigms
  • C ++ if you want to use object oriented and / or generic programming tools

If you're just curious to do something, I would probably use python or another scripting language for this task.

+1


source


This does not directly answer your question, but it might answer your situation. I remember getting similar homework when ...

The original purpose, I believe, was to familiarize the student with section 3 of the C library routines for C programs, and to a lesser extent section 2, Unix and C system calls. I remember to ask the instructor if I could write my homework in C ++ and got no response for an answer - C was a requirement.

Anyway, my point is that I spent most of my time parsing command line arguments. The utilities themselves were trivial. And in hindsight, it was a shame that no one pointed out to me. I hope you become smarter than me.

+1


source


Since this is for homework, I have to check with an instructor or person evaluating your work. A good instructor should be able to understand a C ++ program as well as a C program unless it is written in crazy ways (but how can students know what crazy is?)

If your teacher doesn't care what language you use, use the language you like best if you want to get the job done faster. If you need a challenge, use a language you are less familiar with. School is a good time to make mistakes, but at the end of your term your grades are important.

Finally, don't try too hard to wrap your own API or reinvent it if the intent is to learn the API. If you can come up with an elegant wrapper that demonstrates that you understand the API, that's fine, but otherwise your instructor might be annoyed that your program is working against the API, not against it.

+1


source


If you know and are comfortable with C ++, I can't think of a reason not to use it for this purpose.

0


source


You friend have no idea what they are talking about. Both C and C ++ are usually compiled (interpreters exist, but normal use is to compile them). In the end, compiled C binaries and compiled C ++ binaries will behave the same. Use what you want to use is a matter of preference.

0


source


If you feel comfortable with C ++ ... use it. Boost Program Options can be used to control the input parameters .

0


source


About your first argument: More code use and better separation of concerns is achieved in C.

On your colleague's argument: I don't know what a program is in the traditional sense. There is no technical or legal issue that prevents the use of C ++ for the interpreter.

About your second argument: if you don't know C, don't program in C (if your goal is not to learn it, that's great). For a person whose only tool is a hammer, every problem looks like a nail. This may be a joke, but I think this is good advice.

0


source


Use whatever is more comfortable for you.

But with C you can cheat :)

Do not lie! The sources for the various utilities are not intended for general use.

0


source


Actually, you can use both. It depends on what commands you write.

C ++ has one drawback, the executable size. If you are actually executing shell commands, you want the executable to be small, and C will most likely create a smaller executable. Of course, this is not the only limitation. You want the code to be easy to work with. Thus, a blended approach can provide benefits. For a command like ls where there is little input handling, you can do all your output using the C library stdio.h so you don't have to include the much larger C ++ iostream library.

OTOH, this is homework, so I doubt you will get points for the large executable size, so on this particular instance, you should probably stick with what you know best.

0


source


If you are just running shell commands I would think the easiest way is to write a bash script. So you will already be using the shell and just have to learn the syntax, which is simple, and then wrap and redirect the commands.

0


source







All Articles