Question

In: Computer Science

P1) Duplicated code P2) Feature Envy P3) Long Method P4) Intimacy (same questions for each) 1)...

P1) Duplicated code
P2) Feature Envy
P3) Long Method
P4) Intimacy
(same questions for each)
1) What is this ? What problem will it cause?
2) Can you show any example for this problem?
3) What is you solution? Show an example.

Solutions

Expert Solution

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.

  • Duplicate code makes your program lengthy and bulky : Many programmers feel that if the software is working properly there is no reason to fix code duplications. Each millisecond of delay will contribute to greater delay and greater space requirements at the user’s local machine as well as your servers. Having well-written code with least duplications will make sure that your program runs faster and occupy less space. Also, age has gone when people didn’t care to wait. Now everything needs to be fast and smooth
  • Duplication decreases your code quality: Having duplicate code will make your code smelly and increases technical debt associated with it. The cost of repair of this debt is the amount of capital and time required to pay to a developer to simplify or de-duplicate it. The interest is the decreased productivity of developers.
  • Shotgun Surgery: Suppose you write buggy code. You do a code review to find out the issue and then fix it. Now replace this scenario of buggy code with duplicate buggy code. You now have to fix every location that code is, losing your time, efficiency and sometimes temper. This situation is called inverse shotgun surgery and is pretty nasty for any developer.
  • Increases security risks: This is more of a copy and paste programming issue than duplicate code but like most times one produces repetitive code by using the copy-paste process it deserves a mention. When someone takes a code from somewhere and adds into their software they forget about the holes and endings that plagiarized code has. Duplicate codes leave an opening for attackers to exploit and get into your code making it vulnerable.

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:

  • social isolation
  • greater risk for depression and substance abuse
  • serial dating or having a lot of short-term relationships
  • sabotaging relationships by being difficult and overly critical

Related Solutions

1.) You are given 4 processes P1,P2, P3, P4 all ariving at the same time t=0,...
1.) You are given 4 processes P1,P2, P3, P4 all ariving at the same time t=0, in a dual-processor SMP. (The two CPUs are referred to as CPU-0 and CPU-1.) The service time for each process is 40s, 20s, 20s and 10s respectively (a) What are the possibilities for the turnaround time of the job that includes the execution of all 4 processes? You may assume that each service time is just CPU time and no process interferes with the...
Serial Problem Business Solutions LO P1, P2, P3, P4 [The following information applies to the questions...
Serial Problem Business Solutions LO P1, P2, P3, P4 [The following information applies to the questions displayed below.] Santana Rey created Business Solutions on October 1, 2015. The company has been successful, and its list of customers has grown. To accommodate the growth, the accounting system is modified to set up separate accounts for each customer. The following chart of accounts includes the account number used for each account and any balance as of December 31, 2015. Santana Rey decided...
A company produces and sells 4 types of products – P1, P2, P3, and P4. The...
A company produces and sells 4 types of products – P1, P2, P3, and P4. The table below summarizes the relevant data. Three types of raw materials – RM1, RM2, and RM3 are required for the manufacturing process. The availability and cost per unit for each raw material are specified under the columns Available and Cost per unit, respectively. The company is contractually obligated to produce at least a minimum quantity for each product; these are specified in the row...
Let pi = P(X = i) and suppose that p1 + p2 + p3 + p4...
Let pi = P(X = i) and suppose that p1 + p2 + p3 + p4 = 1. Suppose that E(X) = 2.5. (a) What values of p1, p2, p3, and p4 maximize Var(X)? (b) What values of p1, p2, p3, and p4 minimize Var(X)?
Suppose there are 4 processes P1, P2, P3 and P4 getting to ready queue in various...
Suppose there are 4 processes P1, P2, P3 and P4 getting to ready queue in various arrival times and with various bursts times as detailed in the table below. Using Shortest-remaining-time-first scheduling approach, find waiting time for each process and the average waiting time and provide detailed steps taken to find the answer. Using time quantum of milliseconds. Process Arrival time (ms) Burst Time (ms) P1 0 8 P2 2 3 P3 6 2 P4 9 7
Consider following four processes arriving in the order of P1, P2, P3 and P4. Process   Arrival...
Consider following four processes arriving in the order of P1, P2, P3 and P4. Process   Arrival Time CPU burst Time P1             0.0     6 P2    0.0                              8 P3              0.0                                7 P4              0.0                                 3 What is the average waiting time for RR scheduling (time quantum = 5)? What is the average waiting time for SJF scheduling? What is the average waiting time for FCFS scheduling?
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the company’s first two months, Santana Rey continues to operate Business Solutions. The November 30, 2019, unadjusted trial balance of Business Solutions (reflecting its transactions for October and November of 2019) follows. No. Account Title Debit Credit 101 Cash $ 38,264 106 Accounts receivable 12,618 126 Computer supplies 2,545 128 Prepaid insurance 2,220 131 Prepaid rent 3,300 163 Office equipment 8,000 164 Accumulated depreciation—Office equipment...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the company’s first two months, Santana Rey continues to operate Business Solutions. The November 30, 2019, unadjusted trial balance of Business Solutions (reflecting its transactions for October and November of 2019) follows. No. Account Title Debit Credit 101 Cash $ 38,264 106 Accounts receivable 12,618 126 Computer supplies 2,545 128 Prepaid insurance 2,220 131 Prepaid rent 3,300 163 Office equipment 8,000 164 Accumulated depreciation—Office equipment...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the company’s first two months, Santana Rey continues to operate Business Solutions. The November 30, 2019, unadjusted trial balance of Business Solutions (reflecting its transactions for October and November of 2019) follows. No. Account Title Debit Credit 101 Cash $ 38,564 106 Accounts receivable 12,818 126 Computer supplies 2,645 128 Prepaid insurance 1,860 131 Prepaid rent 3,200 163 Office equipment 8,700 164 Accumulated depreciation—Office equipment...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5 After the success of the company’s...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5 After the success of the company’s first two months, Santana Rey continues to operate Business Solutions. The November 30, 2016, unadjusted trial balance of Business Solutions (reflecting its transactions for October and November of 2016) follows. No. Account Title Debit Credit 101 Cash $ 38,664 106 Accounts receivable 12,718 126 Computer supplies 2,545 128 Prepaid insurance 2,160 131 Prepaid rent 3,020 163 Office equipment 8,400 164 Accumulated depreciation—Office equipment $...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT