1 / 46

Coding For People

Coding For People. Martyn Gigg , Tessella 9 th February 2012. About Me. MPhys : 2000 – 2004 PhD: 2004 – 2008 Tessella : 2008 - ? Mantid - Rutherford Appleton Laboratory UK & Oak Ridge National Lab US. About Tessella – www.tessella.com. Services based software company

jaser
Télécharger la présentation

Coding For People

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Coding For People MartynGigg, Tessella 9th February 2012

  2. About Me • MPhys: 2000 – 2004 • PhD: 2004 – 2008 • Tessella: 2008 - ? • Mantid - Rutherford Appleton Laboratory UK & Oak Ridge National Lab US

  3. About Tessella – www.tessella.com • Services based software company • HQ in Abingdon, Oxfordshire • Medium size ~ 300 people • Offices around UK, in the USA and Netherlands • Specialise in science and technology related products and services

  4. Tessella: Services • Consultancy • Ranges from advice on international or cross-functional direction-setting, e.g. creation of an agile technology or IT strategy, through to technical consulting on specific, hard-to-solve problem • Application Development & Systems integration • Projects range from customising and integrating standard off-the-shelf solutions, to using development platforms or drawing from our own extensive base of re-usable code. • Team Augmentation • From additional engineering resource, to supplying a skill-set that does not currently exist in your team. • Support and Maintenance • Extending life of legacy systems, insurance policy for business critical systems, provide expertise not available in-house

  5. Tessella: Sectors • Why write software professionally?

  6. Government Research - Mantid Project

  7. Software vs Hardware • Software is just as important as hardware • Tendency to skimp on software, i.e. post doc written • Good software requires processes • Software Engineering • Requires trained people just like other disciplines

  8. FUSION Research Project Building a fusion Tokamakin the South of France

  9. Pharmaceutical – Drug Development • Analysis of clinical trials data and adaptive dose allocation using Bayesian statistics

  10. So far … • Variety of Technologies • Variety of Domains • Lots of Different and Interesting Challenges

  11. Introducing Change • How does a business keep on making money? • Software changes to meet business needs • Further development → Change management • One side = ability to track change • Version control • “Management” issue • Another side = How easy is code to change?

  12. Making Changes

  13. Writing code for people

  14. Documentation

  15. Documents • Requirements • Design/Architecture • Test Scripts • Installation Guide • Manual • Maintenance Guide

  16. Comments // We need to check if the approver of the // document still has permission to see it Document doc = gateway.GetDocumentById(documentId); PermissionSet perm = new PermissionSet(user, doc); // Changed by John (August) return perm.CanView();

  17. Comments /* ********************************** * r23 21-Jan-2009 John * Created class * * r23 12-Feb-2009 Bob * Added Co-Author property * * r23 01-Mar-2009 Dave * Created class * * r23 21-June-2010 John * Implemented new Workflow * * **************************************/ public class Document {

  18. Comments publicclassWordLimitValidator{  public intwordLimit;  public boolIsWithinWordLimit(Document d)  {           return document.WordCount <= this.wordLimit;  }} publicclassClass1{// Declare the max integer Xpublicint x; // Checks the documentpublicbool Check(Document d)  {// Keeps a running count, start at 0int t = 0;// Loop over the sectionsfor (inti = 0; i < d.Sections.Count; i++)    {// Loop over the paragraphs in the sectionfor (int j = 0; j < d.Sections[i].Paras.Count; j++)      {// Increment the total count        t += d.Sections[i].Paras[j].Words.Count;      }    }// Check that t is less than or equal to xreturn t <= x;  }}

  19. Readability

  20. Re-Factoring

  21. Readability Do not use booleans as arguments! StringCreateFile(Stringfilename, BooleanoverwriteExisting, BooleankeepOpen); CreateFile("file.csv",true, false); CreateFile("file.csv",CreateMode.OverwriteExisting, LockMode.KeepOpen); StringCreateFile(Stringfilename,CreateModefileMode,LockModelockMode);

  22. Readability Does it fit on one screen? AndAlso (document.Author.Department.Head = currentUser.ManagerOrElse version.

  23. Readability Does your code describe the domain? Public Float Class String Document Integer Public DateTime Author String Version Class Document XmlDocument XmlDocument Signature

  24. Smells

  25. Smells • Duplicated code: identical or very similar code exists in more than one location. • Long method: a method, function, or procedure that has grown too large. • Large class: a class that has grown too large. See God object. • Feature envy: a class that uses methods of another class excessively. • Inappropriate intimacy: a class that has dependencies on implementation details of another class. • Refused bequest: a class that overrides a method of a base class in such a way that the contract of the base class is not honoured by the derived class. See Liskov substitution principle.

  26. Lazy class / Freeloader: a class that does too little. • Contrived complexity: forced usage of overly complicated design patterns where simpler design would suffice. • Excessively long identifiers: in particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture. • Excessive use of literals: these should be coded as named constants, to improve readability and to avoid programming errors.

  27. A small detour: Testing • Everyone tests their code • Refactoring should leave functionality intact • Good automated tests ensure this • One of the keys to continuing success is good test coverage and also good feedback from automated tests

  28. Patterns

  29. Null Object void NotifyDepartmentHead(IPerson person) { if (person.Section != null && person.Section.Division != null && person.Section.Division.Department != null && person.Section.Division.Department.Manager != null) { if (! string.IsNullOrEmpty( person.Section.Division.Department.Manager.EmailAddress)) { SendEmail(person.Section.Division.Department.Manager.EmailAddress); } } }

  30. Null Object public class NullDivision : IDivision { public IDepartment Department { get { return new NullDepartment(); } } public IPerson Manager { get { return new NullPerson() } } } public class NullSection : ISection { public IDivision Division { get { return new NullDivision(); } } public IPerson Manager { get { return new NullPerson(); } } }

  31. Null Object void NotifyDepartmentHead(IPerson person) { String address = person.Section.Division.Department.Manager.EmailAddress; if (!String.IsNullOrEmpty(address)) SendMail(address); }

  32. Factory Pattern

  33. Adapters and Decorators

  34. Conclusion Software needs to change, so it must be EASY to change The CODE is always right Write your code so it is easy to understand You can use patterns to solve common problems Agile methodologies embrace change

  35. Suggested Reading • 97 Things Every Programmer Should Know [O’Reilly] • Patterns of Enterprise Application Architecture, by Martin Fowler • Head First Design Patterns, by Eric T Freeman, Elisabeth Robson, Bert Bates, Kathy Sierra • Java Puzzlers: Traps, Pitfalls, and Corner Cases, by Joshua Bloch, Neal Gafter

  36. function GetPosString(position) { switch (position) { case 0: return "1st"; case 1: return "2nd"; case 2: return "3rd" ; default: return (position + 1) + "th"; } }

  37. if (!$email){ global $Email; $email=$Email; if (!$email){ global $Email_Address; $email=$Email_Address; if (!$email){ global $email_address; $email=$email_address; if (!$email){ global $EmailAddress; $email = $EmailAddress; if (!$email){ global $emailaddress; $email = $emailaddress; if (!$email){ global $EMailAddress; $email = $EMailAddress; } } } } } }

  38. public class Document { // Creates a new document object that is not yet in the database public Document(String id, int version) { // ... } // Loads a document object from the database public Document(int version, String id) { // ... }

  39. onreadystatechange = function(){ switch(httpReq.readyState){ case 0: if(httpReq.readyState == 0){ break; } case 1: if(httpReq.readyState == 1){ break; } case 2: if(httpReq.readyState == 2){ break; } case 3: if(httpReq.readyState == 3){ break; } case 4: if(httpReq.readyState == 4){ if(httpReq.status == 200){ varval = httpReq.responseText; alert(httpReq.responseText) dataInsert(val); break; } else{ alert("Error "+httpReq.status); break; } } } };

  40. // assign variables logFile.info("START: Assigning variables."); logFile.debug("Getting particular drug information."); // gets drugs brandNameDrugs = Utils.formatDrugList(dl.getDrugsByLabel(calculateBean.getDrugName())); logFile.debug("Getting major classifications."); // get all major classifications (usage) majorClassifications = cl.getMajorClassifications(); logFile.debug("Getting classifications."); // get all classifications classifications = cl.getClassifications(); logFile.debug("Getting all classifications."); // gets all the major classifications and classifications allClassifications = cl.getAllClassifications(); logFile.info("END: Assigning variables."); // assign variables to session for search.jsp logFile.info("START: Assigning variables to the session."); logFile.debug("Storing brandNameDrugs to the session."); request.setAttribute("brandNameDrugs", brandNameDrugs); logFile.debug("Storing majorClassifications to the session."); request.setAttribute("majorClassifications", majorClassifications); logFile.debug("Storing classifications to the session."); request.setAttribute("classifications", classifications); logFile.debug("Storing allClassifications to the session."); request.setAttribute("allClassifications", allClassifications); logFile.info("END: Assigning variables to the session.");

  41. // "true" or "false" public static string Bool2Str(bool b) { switch(b) { case true: return System.Boolean.TrueString; case false: return System.Boolean.FalseString; default: return "error"; } }

  42. Public Shared Sub isValidQuery(ByVal query As String) ‘… End Sub

  43. ‘'To Get date from SAP XMl as they are providing date like 20090330        Public Shared Function Getformateddate(ByValstrDate As String) As Date            Dim month As String = strDate.Substring(4, 2)            Dim year As String = strDate.Substring(0, 4)            Dim day As String = strDate.Substring(6, 2)            Dim tempdate As Date = Convert.ToDateTime(day + "/" + month + "/" + year)            Return CDate(tempdate.ToShortDateString)        End Function

  44. ''çatch exception in case the date is null not correct format.            Try                If strDate.Trim.Length = 8 AndAlsoIsNumeric(strDate) Then                    Dim month As String = strDate.Substring(4, 2)                    Dim year As String = strDate.Substring(0, 4)                    Dim day As String = strDate.Substring(6, 2)                    Dim tempdate As Date = New Date(CInt(year), CInt(month), CInt(day))                    Return CDate(tempdate.ToShortDateString)                End If            Catch ex As Exception                Return Nothing            End Try

  45. DimuserAsIPerson = icp.ContentDispatcher.userDimsuperAsBoolean= user.IsDBManageruser.setAsDbManager() ‘ Snip IfNotsuperThenuser.removeAsDbManager()EndIf

  46. PublicOverridesSubHandleAction(ByVal action AsIAction)DimctAsIContentType = Me.getContentType()SelectCaseaction.NameCaseEIDMActions.CoverPagehandleCoverPage()CaseEIDMActions.RemoveCoverPageRemoveCoverPage()CaseEActions.copyIficp.ContentDispatcher.UserIsNotNothingThen _TSQLDataAccessLayer.saveInterfaceValue(icp.ContentDispatcher.User.Uid & ButtonAction.Action_Copy, doc.uid)CaseEIDMActions.DocumentObsoleteMe.version_status = EVersion_status.version_obsoleteMe.save()doc.setCurrentVersion()CaseEIDMActions.DocumentSign''for sign actionsignDocument()CaseEIDMActions.DocumentRecommendHandleRecommendAction()CaseEIDMActions.DocumentApproved''for approve documentIfCheck_AllReviewersRecommended() ThenHandleApproveAction()ElseSystem.Web.HttpContext.Current.Response.Redirect("ApproveComment.aspx?uid=" & Me.uid & "&commenttype=" & EDocumentComments.ApproveComment)EndIf

More Related