-1

I'm having a discussion with a coworker, who insists cp is declarative. To me, it seems very imperative. It's an instruction we are asking the computer to do, not a definition or declaration. For it to be declarative, instead of:

cp a.zip b.zip

you might have:

b.zip = a.zip

Does anyone have any opinions on this?

Dominic Bou-Samra
  • 14,799
  • 26
  • 100
  • 156

2 Answers2

1

It seems like you are using those terms at a level where the two have little distinction. For instance, if I were making a user interface for a program and had some file saying

Logo:
  Title: Cool UI
  Color: Green

That is a declarative representation of my ui. It is data that represents what I want the computer to do. If I were to instead make my ui by using code like

l = Logo()
l.add(Title('Cool UI'))
l.add(Color('Green'))
ui.render(l)

That would be an imperative representation of my ui. I am telling the computer what to do each step of the way. When we talk about the cp command, its worth thinking about what the difference between an "imperative" and "declarative" version would be. On the one hand, you cant get more imperative than telling the computer to

 cp a.zip b.zip

Which from a certain perspective is just like saying "hey increment this register" or "hey move whats at this memory address to this memory address", which in assembly is just

mov r0, r1

That being said, if you were to describe in data what you wanted to do you would say something like

copy-paste: a.zip b.zip

Which, take out the colon and shorten the name and you get

cp a.zip b.zip

TL;DR at this level of specification, there is basically no difference between imperative and declarative

Ethan McCue
  • 883
  • 1
  • 8
  • 17
0

The cp(1) syntax itself is declarative because you define what you want to accomplish without specifying how it needs to be done. Which, by the way, means your both examples are declarative.

You may also want to take a look to a wider discussion.

Mike Volokhov
  • 119
  • 1
  • 3
  • By that definition, can you name *anything* that wouldn't be declarative? When I'm writing in assembly language, I say that I want to take the number stored in one register, treat it as a memory address, and load the 8 bytes at that location into another register. That's *what* I want to happen. *How* the processor does that (through timing, control signals, etc) aren't in what I write. – Damien_The_Unbeliever Oct 25 '18 at 11:39
  • `cp a.zip b.zip` Being placed in the shell context the command shall be considered imperative. Which, of course, doesn't make it's syntax imperative either. – Mike Volokhov Oct 25 '18 at 11:55