Is unix's 'cp' command declarative or imperative? [closed] - imperative-programming

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 years ago.
Improve this question
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?

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

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.

Related

is this good to have pointers in programming languages such as golang,C or C++? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Most of the modern programming compilers such as JAVA etc does not have the support of pointers.
But in golang google introduce pointers again.
So, i just want to understand how pointer effects a programming language?
is there any kind of security thread because of pointers?
if this is because of security then why we have world's most secured system on LINUX and UNIX(both are build in C)
Technically, all languages use pointers. When you create an instance of an object in Java or C# or Javascript and pass it to a method you are actually passing a pointer to the piece of memory that contains that object by which you will manipulate the data on that piece of memory. Imagine a language where you could not pass by reference. You wouldn't be able to do much, now would you? Whenever you pass by reference in any language, you're - in the most basic of terms - using glorified pointers.
What you probably mean, however, is "why expose pointers to people; they are so much more complicated", or something of that sort... And the answer is probably speed and tradition. Some of the fastest languages we have are C and C++... They've been around for a relatively long time. They are tried and true, and people know how to use them. Most software is based off of them in one way or another. Most operating systems are written in C or some variation thereof. Even other programming languages.
As for your Go example, we have already had a question on that..
C/C++ pointer is operational.
Example
void f(int* a) {
a++
Direct operation is danger.
But, Golang pointer is not operational.
So, same name and same mean "pointer".
But, there are difference how to use.
The 'modern' comparison of JAVA and C# to C++ is the worst thing a programmer can make. JAVA and C# are managed languages and that means that the memory is not managed by the programmer at all (that is the main function of pointers).C++ is an unmanaged language and that is why C++ is so much faster than any managed language. Almost every modern PC game you will ever see is made using C++ because it runs faster than any managed language.
Pointers makes call-by-reference easier, but are more vulnerable to breach, because through pointers we can directly access to the memory location, and thus can be a security concern.
Those problems can be defensively coded to prevent but that requires users to be knowledgeable and diligent.

What do I need to know about Common Lisp? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am currently trying to pick up the frustrating world of common lisp. Before I get too deep into this and get too angry at the computer could anyone give me pointers on what to expect and general tips/tricks.
Thanks
Great question. Since I am quite new to lisp too, and the hurdles are still fresh I think I can offer some help. Here a few tips in no particular order. I might add more if I think of them.
1) Understand how lists are implemented in lisp.
2) Read Land of Lisp by Conrad Barski.
3) Understand the difference between read time, compile time and run time. (If you don't you will never "get" macros)
4) Symbols and packages. Packages are all about namespacing/exporting/shadowing symbols. (At least for me). Check this out. (I know, the title sucks, but the content is good.) You can think of symbols as identifiers for functions and variables. Common lisp is a Lisp 2. Read about that. If the symbol is inside parenthesis common lisp will look for the function definition of the symbol and if it is not - for the variable definition. Look up how symbols are implemented internally. (ANSI common lisp by Paul Graham has a great chapter on that)
5) Macros operate on code. Read On Lisp by Paul Graham when you feel ready. It is considered the seminal work on macros.
6) For truly beautiful lisp code I suggest Paradigms of Artificial Intelligence Programming
7) CLOS is the Common Lisp Object System. The book that really helped me "get" CLOS is Object-Oriented Programming in Common Lisp. It is old (older than myself in fact) but totally relevant and worth it. Read about dynamic dispatch. The Meta Object Protocol is still something I am trying to figure out so I cannot give you a lot of tips there :(
8) An "Alist" or "associative list" is just a list of lists. However common lisp has build-in operators for it like assoc (for finding an item in the list) There are also proper list, dotted list, property list (or plist). There are also operators like union that will treat an ordinary list like a set. Lisp is all about this sorts of abstraction. If you have an idea that a particular list will behave like a set then you don't need to implement a set data structure. When you start developing with lisp you will find yourself cutting corners like that all the time.
9) setf is a "generic setter". It is nice to have one operator for setting the values in arrays, lists (or alists, etc...), slots (the word for fields in an object) etc... we can use the same command.
The best advice is just read read read. It is not that hard of a language really.
And just a tip for when you are delving in a new technology: Create a file research.md where you write everything new that you learn. Like a journal. Works great for me.
And don't get frustrated :) Google the error messages or ask for advice in #clnoobs

Create a "Did You Mean...?" type of search in ASP.NET with VB.NET and SQL? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
So, I have a website with a search bar.
I have only figured out how to get results when they match (at least in part using Like %searchterm%) and it works.
Obviously, this does not help me if the user misspells something.
We have discovered through HeatMapping that we are losing people on this.
How can I implement a "smarter" search feature?
Thanks,
Yoni
The "real" solution that you are looking for might be more complicated than you think. You could use simpler solution that will work fine like using the DIFFERENCE function.
I am trying to leave a comment, but not able to. So i have to leave it here, and it might not be the ideal answer Yoni is expecting. I can think of two ways of doing it.
use asp.net autocomplete function. It will query the db, and feed the user back with suggested search results dynamically when users are typing which will prevent users mistyping somehow. many search engines use it frequently like Google, Yahoo. In asp.net, its very easy to wire it up.
ASP.NET Auto Complete
This is how Auto complete looks like
add a class to re-process the search terms before querying the database, so you wont get 0 hit if users mis-spell or mis-type something. This is very broad, and it varies a lot depending on your business model concept.
Hope it helps. :)
This is quite a complex matter, impacting on both coding complexity and query performances.
Of course there may be a lot of approaches to achieve the results you ask for.
Personally, I would start by working with aliases: for each word that user may search for, I would create a set of aliases, that may be related to word semantic value or to mistyping of the word itself, eg:
Word: sheet
Aliases: paper, shet, shee ...
So, each single word must be indexed (and this could be a cumbersome aspect to deal with, depending on your contents), and for each woed there may be many aliases.
Then apply a sequential logic like the following:
1 - standard search, as the one you already did
-> if nothing matches
2 - alias search
-> if nothing matches
3 - start "playing" with wildcard characters (this could definitely kill your db however)
I understand this is a quite generic answer, but I don't think there may be an absolutely good approach - performance wise - to your question.

Analyze partial or corrupted QR codes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
How can I analyze broken/partial QR codes? Normally a QR decoder will just tell you that the data can not be read. This is not very useful. Even though the code is not readable, some information can, presumably, be extracted!
Is the finder patterns found?
Is the timing pattern found?
What is the version?
What is the error level?
What is the mask?
Is the format intact?
What is the mode?
Is the stop pattern found after the correct length?
Is there any meaningful data?
How can I extract this information from broken/partial QR codes?
This is a question that comes up in many ways; some easier than others.
To answer your direct question: The tool you need: Your brain.
Software can help but to decode partial or misprinted codes takes some work. It is like detective work. You need to take what you have and fill in what you know about the way they are created in the first place, then make educated guesses for the win.
Here is a tour of the concept. By looking at these articles most of the items on your bullet-point list will be answered.
This article explains the overall format in good detail:
Wounded QR Codes
For instance, here is the first image in the article about formatting:
Here is a real-world example of the process of decoding a partial image:
Decoding a partial QR code
It begins with the challenge image
Then shows you the order of bits that are encoded:
Then through the process of detective work to produce the final image:
Here is a different problem. You have a full image but it won't scan properly so you have to decode it by hand:
Decoding small QR codes by hand
It starts out with a tattoo:
Which is in the wrong orientation, and also won't scan properly.
So you work through the decoding process:
Yielding the final result: Maci Clare Peltz
Have fun detecting!
You can simply hack some open source code like zxing to print out its progress on a command line during decoding and in that way see how far it got. Just sprinke in a few System.out.println() statements.
The problem is false positives. It will almost always find at least 3 regions that look like a QR code's finder patterns; it always takes the 3 most likely candidates. They usually are phantoms since you're usually not looking at a QR code. The next step would then fail, finding valid version info. (In a very unlikely case it would even find phantom version info.)
Some of these aspects you mention aren't necessarily detected by a library since they don't have to be, like timing pattern and stop pattern (which isn't required for short data).
Aside from those caveats, should be easy.

Who modifies affected components in an agile environment? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
In a continuous integration, agile environment, if I make a change in class A (e.g. change attribute names) which I have created and have been working on, that affects class B, which "belongs" to someone else, who modifies class B whenever I want to check in my change? Me or the class' B owner?
I suppose is more agile if I modify it, so that I don't have to notify other people, but at the same time, people working on it are more aware of the impact of modifying it...
In an agile environment, class B (like all classes) belongs to the team. We call this Shared Code Ownership. You should check in working code; if that means you need to adjust class B to conform to the changes you make to class A - adjust! Better yet, pair.
"Individuals and interactions over process and tools." Communicate the change upfront with the other people impacted. Unless the code is trivial, you may not understand the full impact of the change. Even if you do, you owe it to your other teammates to keep them informed.
"Don't break the build." Checking code in that you know will break the build is not a good idea. Once you have communicated with the others that are impacted, work with them to get the code changes completed. Attempt to get the code changes checked in so at least the nightly build is not broken.
Just my opinion....
Bob
who modifies class B whenever I want to check in my change? Me or the class' B owner?
With no disrespect, I think your question is so basic that it clearly suggests that you do not have even basic understanding of what being Agile means. Well, maybe that's why you asked this question.
Here are my suggestions:
In this kind of situation you really should walk up to the other developer who might be impacted by your change and have a quick face to face conversation about this, this quick conversation may lead to you guys pair programming to make sure the build does not break, and no one gets affected.
Please read all the Agile Principles again, and write down what you understand from each one of it. Implement those principles in your day to day development life. This is the only way to become Agile. There is no certification or book to refer to, to make someone Agile magically. Being Agile has to be self realized, hence practice them daily till they become a habit.
So the "Information" is conveyed using the most effective method i.e. f2f conversation. The problem is solved on the basis of the collective responsibility principle, most ideal way to fix it is pair programming.
Reference:
Agile principle
"The most efficient and effective method of
conveying information to and within a development
team is face-to-face conversation."
Also a general Agile Guideline from the manifesto:
"Responding to change over following a plan"
Agile includes team code ownership, communication
As #Carl Manaster said, the code belongs to the team. And as #rcravens suggests, agile is about communication. Have a quick meeting with the author of B and let them know your proposed changed to be sure you understand your impact. If it's complex, pair with B's author on the change. When the change is complete, if you think it might affect other developers on the team, call a brief team meeting and let them know of the change.
By the way, how's your design?
Your question may aslo be revealing a design issue - A and B might be too tightly coupled. After your tests work and you've implemented the change, I suggest that you examine your code and see if something needs refactoring. (Remember, TDD is Red/Green/Refactor) In particular, if changing class A means you have to change class B, then you might not be following the Single Responsibility Principle (SRP) arm of SOLID practice.

Resources