In: Computer Science
P1. What is duplicated code? What problem will it cause?
Ans: Duplicate code is a computer programming term for a sequence of source code that occurs more than once, either within a program or across different programs owned or maintained by the same entity. Duplicate code is generally considered undesirable for a number of reasons. A minimum requirement is usually applied to the quantity of code that must appear in a sequence for it to be considered duplicate rather than coincidentally similar. Sequences of duplicate code are sometimes known as code clones or just clones, the automated process of finding duplications in source code is called clone detection.
Reasons for the Problem
Duplication usually occurs when multiple programmers are working on different parts of the same program at the same time. Since they’re working on different tasks, they may be unaware their colleague has already written similar code that could be repurposed for their own needs.There’s also more subtle duplication, when specific parts of code look different but actually perform the same job. This kind of duplication can be hard to find and fix.
Sometimes duplication is purposeful. When rushing to meet deadlines and the existing code is “almost right” for the job, novice programmers may not be able to resist the temptation of copying and pasting the relevant code. And in some cases, the programmer is simply too lazy to de-clutter.
P2. What is Feature Envy? What problem will it cause?
Ans: Feature envy is a problem because it is a coupling code smell. It couples two objects together inappropriately. This coupling introduces a larger surface area of change in the code when one of the two objects has to be modified. Less isolated changes then lead to an increase in the likelihood of introducing bugs.Feature envy refers to situations where a method is "in the wrong place", because it does not use many methods or variables of its own class, but uses a whole range of methods or variables from some other class.
Feature envy is a term used to describe a situation in which one
object gets at the fields of another object in order to perform
some sort of computation or make a decision, rather than asking the
object to do the computation itself. As a trivial example, consider
a class representing a rectangle. The user of the rectangle may
need to know its area. The programmer could expose
width
and height
fields and then do the
computation outside of the Rectangle
class.
Alternatively, Rectangle
could keep the
width
and height
fields private and
provide a getArea
method. This is arguably a better
approach. The problem with the first situation, and the reason it
is considered a code smell, is because it breaks encapsulation. As
a rule of thumb, whenever you find yourself making extensive use of
fields from another class to perform any sort of logic or
computation, consider moving that logic to a method on the class
itself.
P3. What is Long Method? What problem will it cause?
Ans: A method contains too many lines of code. Generally, any method longer than ten lines should make you start asking questions.
Reasons for the Problem
Like the Hotel California, something is always being added to a method but nothing is ever taken out. Since it’s easier to write code than to read it, this “smell” remains unnoticed until the method turns into an ugly, oversized beast. Mentally, it’s often harder to create a new method than to add to an existing one: “But it’s just two lines, there’s no use in creating a whole method just for that...” Which means that another line is added and then yet another, giving birth to a tangle of spaghetti code.
P4. What is Intimacy? What problem will it cause?
Ans: It is defined as. the degree of emotional intensity between face-to-face interactions, computer interactions with emoticons, and computer interactions without emoticons.Intimacy is a term which is often used, but difficult to define. One person’s idea of the concept of “intimacy” may be quite different than that of another person. A recent study concluded that intimacy contained four main components: selfdisclosure, love and affection, personal validation, and trust (Hook, Gerstein, Detterich & Gridley, 2003). In an earlier study subjects reported that positive feelings toward their partner, talking (especially about topics of an intimate nature) and sharing activities are associated with intimacy (Helgeson, Shaver & Dyer, 1987).
However, intimacy is not always viewed in the same way between the sexes. In one study, men directly associated sex and physical contact with intimacy, whereas women rarely mentioned sex and mentioned physical contact simply as a way of expressing other components of intimacy (Helgeson et al., 1987). In this study, it was found that for both men and women physical contact was rarely mentioned in same-sex intimate experiences, however, appreciation, happiness, talking, problem sharing and/or solving, experience sharing and activity sharing were all mentioned. Additionally, distant, non-intimate experiences were characterized with feeling awkward, feeling hurt, having arguments, a lack of communication, and disapproval. While there are many factors which may influence the level of intimacy experienced in an interaction, such as self-disclosure, body language, and expressiveness, it is unclear how the type of interaction between the individuals, whether face-to-face or on a computer, may effect this experience.
Fear of intimacy may cause one to withhold affection or put up barriers to emotional or sexual affection. If your partner doesn’t know about or understand this, they may feel unwanted and unloved.
Other effects are: