210 likes | 347 Views
Welcome to SIGSoft. Who are we?. Chairs: Drew Cross Eric Parsons Treasurer: Dylan Nugent “Authorized Agents”: Ciara Proctor Sean Nicolay What SIGSoft was like last year. What to expect from us this year. Side note: Our meetings will become much more informal over time.
E N D
Who are we? • Chairs: • Drew Cross • Eric Parsons • Treasurer: • Dylan Nugent • “Authorized Agents”: • Ciara Proctor • Sean Nicolay • What SIGSoft was like last year. • What to expect from us this year. • Side note: Our meetings will become much more informal over time
Announcements • Permanent Room TBA via newsgroup eventually… • Today: “Random” examples of bad code • Next week: Possibly a GIT tutorial • Survey results
There is no -->operator • This is a misuse of white space • In this example, the -->is a combination of the decrement operator (--) and the greater than operator (>). • Note: the -> operator does exist in C/C++
Use appropriate control structures • On the previous slide, a while loop is performing an action typically performed by a for loop. • By switching to a for loop, the comparison and the decrement operation are isolated. This separation helps make the code easier to understand.
Two examples of scope brace placement Either is fine, just be consistent I prefer the latter because of screen real estate and putting the opening brace on a new line does not convey new information to me.
Coding conventions • On the previous slide I showed two examples of curly brace place placement. Either is fine if you are consistent about your usage. • This point is moot in Python as it uses whitespace (indentation) for indicating scope. • If you join a project and everyone is following a coding convention (variable names, indentation, etc) conform to their convention; don’t try to change conventions mid-project unless there is a really good reason to.
Key Point Managing Complexity "Everyone knows that debugging is twice as hard as writing a program in the first place. So if you’re as clever as you can be when you write it, how will you ever debug it?” --Brian Kernighan • The human brain can only handle so many tasks at once. (about 7) • Always strive for simplicity and clarity when designing your programs and when choosing names for classes, methods/ functions, and variables. • Write simple/clear code first and profile it. Only then perform optimizations. • “…premature optimization is the root of all evil.” –Donald Knuth
What is this java code doing? From Code Complete: Second Edition (pg 260)
Now with sane names… • Don’t be afraid to write longer names if needed (but be concise!) For example: numStudents is better than numberOfStudentsInTheClass • Learn the AutoComplete shortcuts for your editor • Vim: Ctrl-n Eclipse: Ctrl-Space, or Cmd-Space on Mac
A more real-world example… • Bad variable names: myInt, arr, thing1, returnVal, input, output, result, a, b, c • Short names can be ok but think before using them. • i.e. x,y,z for Cartesian coordinate system i,j,k for loop control I can’t stress the power of good names enough! Which is why the next talk I (Eric) do will be on naming conventions.
What is wrong here?(Aside from the fact that PHP is being mixed with HTML) • Hint: these are all different files and I could have picked any one of about 200 others for this example…
Repetition • In the previous slide, the PHP/HTML that generates the site’s overall layout is duplicated via copy/paste in a couple hundred files. • If you wanted to make a site wide change you would have to either: • Hope the relevant file was an include that all the pages used • Go through every file making your changes to each • Re-write the site to eliminate the repetition and separate logic from presentation • As a result, this site is inflexible and making changes is difficult and tedious
DRY (Don’t Repeat Yourself) • If you find yourself wanting to violate DRY by copy-pasting code, refactor instead • Benefits of not repeating code • Single place for change • Can give a name to the set of operations being performed (Reducing complexity) • Also: Don’t reinvent the wheel. Chances are that someone has had to solve the problem you are now facing. Maybe that solution uses a software license compatible with your code.
Next Talk • The GIT version control system
Projects • Engineering Open House (EOH) • Will be held March 9-10, 2012 • Sample Ideas: (Feel free to use them if you are stuck) • Where are my classes? http://goo.gl/jQZ0e • Hex Game w/AI opponent http://en.wikipedia.org/wiki/Hex_(board_game) • Import class schedule into Google Calendar • Continue working on IdeaMine
Projects • Break into groups based on interest • Work on just coming up with an idea or problem statement for now • However, if your group is set on an idea, let me know • Repository access • Share contact info • You can post to the newsgroup (please do) but if you have a set of specific people that you want to contact, please try to email each other.