Feedback on Part 1 of the CSLP

24
Computer Science Large Practical: Feedback on Part 1 of the Practical Stephen Gilmore School of Informatics Friday 9th November, 2012 Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 1 / 24

description

Some feedback on Part 1 of the Computer Science Large Practical.

Transcript of Feedback on Part 1 of the CSLP

Page 1: Feedback on Part 1 of the CSLP

Computer Science Large Practical:

Feedback on Part 1 of the Practical

Stephen Gilmore

School of Informatics

Friday 9th November, 2012

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 1 / 24

Page 2: Feedback on Part 1 of the CSLP

Purpose of this lecture

To provide general feedback about Part 1 of the practical.

Give a general sense of how far people had got with Part 1, allowingyou to gauge your progress with respect to the rest of the class.

Identify some problems which people have been having.

Provide clarification on some questions which arose in Part 1.

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 2 / 24

Page 3: Feedback on Part 1 of the CSLP

Submissions for Part 1 of the practical

There are 27 people taking the Computer Science Large Practical.

There were 13 submissions for Part 1, and 14 non-submissions.

Of the 13 submissions,

4 people were developing on Ubuntu/Linux;6 people were developing on Mac OS X;2 people were developing on Windows 7; and1 person was developing on Windows 8.

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 3 / 24

Page 4: Feedback on Part 1 of the CSLP

About the submissions for Part 1

Please remember when submitting to submit your entire directory, notjust the Objective-C sources.

Your directory should contain Makefiles (if developing onLinux/Cygwin/Unix etc) or a .xcodeproj file (if developing on OS X).These files (and possibly others, if you created them) are used tocompile your code.

Please submit all such files, as in the instruction in the practicalhandout, otherwise I end up writing Makefiles to compile and runyour code :-(

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 4 / 24

Page 5: Feedback on Part 1 of the CSLP

Range of submissions for the practical

The submissions for Part 1 were obviously incomplete andwork-in-progress, as requested by the practical description.

Of the submissions for Part 1:

some were just a list of files showing the structure of the project;some failed to compile;some compiled but produced warnings;some compiled and produced no warnings;some read the simulation script file;some performed a simulation.

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 5 / 24

Page 6: Feedback on Part 1 of the CSLP

Uncertainties about the practical, and the marking

Comment

I used GNUstep on Windows 7 to run my simulator, and used theGCC compiler within GNUstep. I have attempted to compile mycode on the DICE machines, however it does not seem to like theObjective-C specific elements of my code. I don’t know if thereare problems with my code or with the compiler used on theDICE machines, but I could not get it to compile at all.

Reply

The version of GCC on DICE is an older version than most of us wouldhave on our laptops so some Objective-C features are not supported, andthere are other issues. As long as it compiles on your platform it is not aproblem if your code does not compile on DICE.

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 6 / 24

Page 7: Feedback on Part 1 of the CSLP

Uncertainties about the practical, and the marking

Comment

I am unsure of the fact that my application requires interactionwith the user to proceed, as I don’t know if testing of theapplication for marking will be done automatically. In that caseall command line output my application produces is, of course,useless.

Reply

Your application will not be tested automatically using a test harness; itwill be tested by a human. It is perfectly OK to ask questions of the user,or ask them to type in the name of a file, or something else.

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 7 / 24

Page 8: Feedback on Part 1 of the CSLP

Understanding the problem

I received a submission with the following structure of header files andclasses.

compound.h enzyme.h parser.h product.h substrate.h

compound.m enzyme.m parser.m product.m substrate.m

This isn’t the right structure for this application. The enzyme/substrateexample is one possible simulation script which could be simulated. Thereshould not be Objective-C code in the simulator specifically for thisexample. Please consider other example scripts available from the courseweb page.

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 8 / 24

Page 9: Feedback on Part 1 of the CSLP

Compiling and running under Ubuntu

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 9 / 24

Page 10: Feedback on Part 1 of the CSLP

Compile-time errors

Compile-time errors in programs start with syntax errors and typossuch as writing down the wrong identifier.

Xcode suggests an alternative which is lexicographically close, a bitlike a spelling checker does.

Not that, somewhat arrogantly, Xcode shows you how your line ofcode would look after you accept the suggested fix, not before.

That is, unlike Eclipse, it assumes that you’re going to accept itssuggestion(!).

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 10 / 24

Page 11: Feedback on Part 1 of the CSLP

Unfamiliar aspects of the language

One problem when learning a new programming language is that wemay bring expectations from the language which we know best.

For example, we may assume that variables are given a default initialvalue (such as zero), as they are in Java.

However, this isn’t the case in Objective-C. We need to initialisevariables ourselves. (“Fix-it” in Xcode will suggest this.)

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 11 / 24

Page 12: Feedback on Part 1 of the CSLP

Unfamiliar error messages“Duplicate symbols for architecture”

Another problem when learning a new programming language is thatthe compilation process is different to the one we are used to, anderror messages may be unhelpful.

One example would be “duplicate symbols for architecture” whichoccurs late in the compilation process.

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 12 / 24

Page 13: Feedback on Part 1 of the CSLP

StackOverflow wisdom“Duplicate symbols for architecture”

A StackOverflow post

Whenever I have “duplicate symbol” errors, it is almost alwaysbecause I have a circular #import in my headers. The solutionis quite simple, use forward declarations where possible, and#import .h files from .m files instead.

From http://stackoverflow.com/questions/11527439/i-am-having-all-the-time-this-issue-after-running-my-app

Author: Chris Trahey

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 13 / 24

Page 14: Feedback on Part 1 of the CSLP

Diagnosis of the problem“Duplicate symbols for architecture”

This was the problem in this case: we should import header files, notimplementation files. (That is, ”.h” files, not ”.m” files.)

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 14 / 24

Page 15: Feedback on Part 1 of the CSLP

Unfamiliar error messages“Incomplete implementation”

Another unfamiliar error message would be “incompleteimplementation”. This message has the disadvantage of being short,and not particularly helpful.

An implementation would be described as incomplete if methodsdeclared in the interface were not implemented in the implementation.

This applies even if the method was declared as a class method in theinterface (i.e. +isUppercase), but defined as an instance method inthe implementation (i.e. -isUppercase). This was the problem here.

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 15 / 24

Page 16: Feedback on Part 1 of the CSLP

Conversions and coercions

We use types in programming languages to discriminate values and toimprove run-time efficiency.

Often (e.g. with numeric types), a value of one type may beconverted to another type explicitly (e.g. “floor” converts a float toan integer) or coerced silently (e.g. integer to float).

In format strings we are also specifying the type of a value and shouldspecify whether we are dealing with a long or an int.

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 16 / 24

Page 17: Feedback on Part 1 of the CSLP

Conversions and coercions

Implicit coercions occur in other contexts as well, such as when wepass a parameter to a method.

In C, and languages descended from C, the problem is made slightlymore complex because we also have unsigned integer types, which wedo not have in Java.

A conversion from long to int would lose precision, as would unsignedint to int or, as below, unsigned long to int.

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 17 / 24

Page 18: Feedback on Part 1 of the CSLP

Incompatible pointer types“How do I convert NSMutableArray to NSArray?”

Again, as different from Java, Objective-C has two types of arrays,mutable and immutable.

NSMutableArray* and NSArray* are incompatible pointer types.

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 18 / 24

Page 19: Feedback on Part 1 of the CSLP

StackOverflow wisdom“How do I convert NSMutableArray to NSArray?”

A StackOverflow post

An NSMutableArray is a subclass of NSArray so you won’talways need to convert but if you want to make sure that thearray can’t be modified you can create a NSArray either of theseways depending on whether you want it autoreleased or not:

/* Not autoreleased */

NSArray *array = [[NSArray alloc] initWithArray:mutableArray];

/* Autoreleased array */

NSArray *array = [NSArray arrayWithArray:mutableArray];

From http://stackoverflow.com/questions/1768937/how-do-i-convert-nsmutablearray-to-nsarray

Author: M Hallendal

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 19 / 24

Page 20: Feedback on Part 1 of the CSLP

Other wisdom

An iPhoneDevSDK post

NSMutableArray *myMutableArray = [myArray mutableCopy];

NSArray *myArray = [myMutableArray copy];

There’s not much reason to do the second one sinceNSMutableArray does everything that NSArray does, unless youexpect the mutable array to change and you want a copy of itscurrent state. Two things to keep in mind: (1) both of thesemethods return an object with a retainCount of 1, just likealloc+init does. You own these objects and must release themsomewhere. And (2) neither method makes copies of the itemsthemselves, just the pointers.

From http://iphonedevsdk.com/forum/iphone-sdk-development/62801-nsmutablearray-to-nsarray.html

Author: smasherStephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 20 / 24

Page 21: Feedback on Part 1 of the CSLP

Learning to love static analysis

Sometimes static analysis will complain about parts of your codewhere you are sure that there is nothing wrong.

The way you see your code:

The way static analysis sees your code:

Think of static analysis as “your slightly less clever friend” and try tohelp it to see that your code will never produce a run-time error. (Youcan do this by, for example, initialising variables.)

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 21 / 24

Page 22: Feedback on Part 1 of the CSLP

Learning to love static analysis

It’s not always easy for you to see the problems in your code.Sometimes the definition site for a variable is many lines away fromthe use site.

Static analysis provides an over-approximation of your program’sbehaviour. It reports potential problems which might not occur inpractice (but “your slightly less clever friend” can’t see that).

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 22 / 24

Page 23: Feedback on Part 1 of the CSLP

Some run-time exceptions

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 23 / 24

Page 24: Feedback on Part 1 of the CSLP

Some run-time exceptions

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 9th November, 2012 24 / 24