Software Development with C++ Ben Morgan Tom Latham Mark Slater

advertisement
Software Development with C++
Ben Morgan
Tom Latham
Mark Slater
“48% were employed
in universities...”
- STFC PhD Careers
The bottom line is you’ve only got a 50% chance of staying in an STFC field.
That’s only the first year after graduation, let alone the draw down in subsequent
years.
Programming is in
top 5 most useful
skills gained by PhDs
Your focus naturally will be on “research”, but given previous
statistics, software development will stand you in good stead,
whatever you go on to do.
Graduates also wanted more training on programming, so here we
are!
“If builders built buildings
the way programmers wrote
programs, then the first
woodpecker that came along
would destroy civilization.”
– Gerald Weinberg
Image © 2012 BirdsFlight: http://birdsflight.com/terms/
It’s not just learning a language!
Just because you know the minutiae of a language standard/implementation does not mean you can write good programs!
The course also covers the tools and techniques you need to work towards this.
Don’t dismiss these tools and techniques because these will help you to become more productive - it all comes down to getting the computer to do the
lions
share of the work!
“A good worker is
known by their tools”
- English Proverb
Be warned that you will come across bad tools and practices, especially in scientific softare.
That’s not to say that this course presents the “perfect” solution or tools..
It does aim to demonstrate principles that can be applied generally
across many computing platforms and problem domains.
“The world is built on C and C++,
did you know that?”
- Herb Sutter
Short answer, it’s the de facto language for major development in HEP
now and for the foreseeable future…
Long answer, it’s also the basis for many of the big software systems out there,
plus, it’s close enough in dialect to C/Python that you can go
and pick these up without too much issue.
Why? See Herb Sutter’s Why C++ Talk! Note his pragmatism on
productivity versus performance though, and emphasis on
the right tool for the job.
Aside: He’s an excellent presenter, so don’t just watch his talks
for the C++ content!
lambdas
[]{foo();}
regex
constexpr
initializer lists
C++11
shared_ptr<T>,
unique_ptr<T>,
weak_ptr<T>
auto i = v.begin();
for(x : collection)
“Not your Father’s C++” - Herb Sutter
It could be said that it’s rather an unfortunate time to be learning C++.
The new standard brings many highly useful features, and it makes
C++ almost a whole new language. But...
nullptr
lambdas
[]{foo();}
regex
9
C++118
shared_ptr<T>,
unique_ptr<T>,
weak_ptr<T>
constexpr
initializer lists
nullptr
auto i = v.begin();
for(x : collection)
“Your Father’s C++” - Existing Code
Though C++11 is mature, time has prevented a comprehensive update to this course.
Our approach tries to be pragmatic - C++98 is still in use and completely compatible with C++11 and future standards. C++11 makes many techniques
easier, and for the techniques we cover it only really acts as syntactic sugar.
If you want to try C++11 in the exercises, that’s fine and we’ll cover how to enable it in Week 2.
Our Aim: Develop “pp6calculator”
A C++98 program you can run to perform a selection of
simple mathematical and data analysis tasks.
This will be a basic UNIX command line interpreter application. This allows most of the basic structures and features of C++ to be explored. It does
however focus on High Energy Physics problems.
Prerequisite Skills
We’ll be working in a UNIX (Linux/OS X/BSD) environment, so you need
to be comfortable with the terminal and command line tools.
A good text editor that can highlight syntax is essential.
It doesn’t matter which you use as long as you are productive
with it! Most have many useful extensions and features, e.g.
snippets, autoinsert, so learn these. This goes towards full IDEs,
which we don’t really cover, such as Eclipse, Xcode, Visual Studio.
They are worth learning!
You will run into errors and have questions - programming is a craft and can only truly be learned by doing. It might seem crazy
to emphasize research skills to you, but it’s incredible the number
of times we are asked about things a quick google would
have answered. This is not to frighten you off asking questions,
rather to highlight that many sources of information are there for you!
1. Version Control with Git
2. Build Automation with
CMake
3. Coding Style and
Documentation
4. Testing and Profiling
5. Software Design
Software Development Stream
We’ll introduce one new topic per week
Some we’ll work through in the exercises
Some are simply topics for discussion with
pointers to further resources
“Software Engineering” is a huge topic which we can only briefly cover in a short course
Developer Bookshelf
Of course, this is just a sampler of the many texts available.
Available from Warwick Library, probably in Birmingham!
If you’re going to purchase any, make sure you either get
the latest editions covering C++11, or in other cases the
cheapest second hand copy you can!
We mention Stroustrup for completeness, but not essential
if you’re a new programmer (though it is *the* reference!).
I would consider the Effective books essential for the
insights they provide and their conciseness.
We’ll highlight other texts as we go through the course.
Developer Q&A
Development Online Resources
One good thing about programming is the amount of online resources - if you have a question, problem, or need some code to do something, it’s almost
certainly out there on the web.
1. Procedural C++
2. Pointers, References and
Arrays
int main(int argc, const char *argv[])
{
int result = calculate_foo();
return 0;
}
3. Object Oriented C++ 1
4. Generic C++ and the
STL
5. Object Oriented C++ 2
C++ Programming Stream
We introduce C++ using the different paradigms it offers
This distinction may not seem obvious at first, as the concept
of a programming paradigm is quite abstract.
int main(int argc, const char *argv[])
{
FooCalculator foo;
int result = foo.calculate();
return 0;
}
C++ Bookshelf
Of course, this is just a sampler of the many texts available.
Available from Warwick Library, probably in Birmingham!
If you’re going to purchase any, make sure you either get
the latest editions covering C++11, or in other cases the
cheapest second hand copy you can!
We mention Stroustrup for completeness, but not essential
if you’re a new programmer (though it is *the* reference!).
I would consider the Effective books essential for the
insights they provide and their conciseness.
We’ll highlight other texts as we go through the course.
Programmers Q&A
C++ Online Resources
$ devcpp-course --help
> questions?
> comments?
Anything else you want to know about the course?
Any comments?
Let’s get a quick show of hands - have you programmed before?
Courses at undergraduate level?
Before/during university?
Since you began your PhD?
If you have, what languages have you used?
What do you want to get out of the course?
Download