Software Engineering: Crash Course Computer Science #16

Software Engineering: Crash Course Computer Science #16

CrashCourse

0:03 Hi, I’m Carrie Anne, and welcome to CrashCourse Computer Science!

0:05 So we’ve talked a lot about sorting in this series and often

0:08 code to sort a list of numbers might only be ten lines long,

0:11 which is easy enough for a single programmer to write.

0:13 Plus, it’s short enough that you don’t need

0:15 any special tools– you could do it in Notepad.

0:17 Really!

0:18 But, a sorting algorithm isn’t a program;

0:20 it’s likely only a small part of a much larger program.

0:23 For example, Microsoft Office has roughly 40 millions lines of code.

0:27 40 MILLION!

0:28 That’s way too big for any one person to figure out and write!

0:32 To build huge programs like this, programmers use a set of tools and practices.

0:36 Taken together, these form the discipline of Software

0:38 Engineering– a term coined by engineer Margaret Hamilton,

0:41 who helped NASA prevent serious problems during the Apollo missions to the moon.

0:45 She once explained it this way: “It’s kind of like a root canal:

0:48 you waited till the end, [but] there are things you could have done beforehand.

0:51 It’s like preventative healthcare,

0:53 but it’s preventative software.” INTRO As I mentioned in episode 12,

1:06 breaking big programs into smaller functions

1:07 allows many people to work simultaneously.

1:10 They don’t have to worry about the whole thing,

1:12 just the function they’re working on.

1:14 So, if you’re tasked with writing a sort algorithm,

1:16 you only need to make sure it sorts properly and efficiently.

1:19 However, even packing code up into functions isn’t enough.

1:22 Microsoft Office probably contains hundreds of thousands of them.

1:25 That’s better than dealing with 40 million lines of code,

1:27 but it’s still way too many “things” for one person or team to manage.

1:31 The solution is to package functions into hierarchies,

1:34 pulling related code together into “objects”.

1:36 For example, car’s software might have

1:38 several functions related to cruise control,

1:40 like setting speed, nudging speed up or down,

1:42 and stopping cruise control altogether.

1:44 Since they’re all related,

1:45 we can wrap them up into a unified cruise control object.

1:48 But, we don’t have to stop there,

1:50 cruise control is just one part of the engine’s software.

1:53 There might also be sets of functions that control spark plug ignition,

1:56 fuel pumps, and the radiator.

1:58 So we can create a “parent” Engine

1:59 Object that contains all of these “children” objects.

2:02 In addition to children *objects*,

2:03 the engine itself might have its *own* functions.

2:05 You want to be able to stop and start it, for example.

2:08 It’ll also have its own variables, like how many miles the car has traveled.

2:12 In general, objects can contain other objects, functions and variables.

2:15 And of course, the engine is just one part of a Car Object.

2:18 There’s also the transmission, wheels, doors, windows, and so on.

2:21 Now, as a programmer, if I want to set the cruise control,

2:24 I navigate down the object hierarchy,

2:26 from the outermost objects to more and more deeply nested ones.

2:29 Eventually, I reach the function I want to trigger: “Car,

2:32 then engine, then cruise control, then set cruise speed to 55”.

2:36 Programming languages often use something equivalent to the syntax shown here.

2:39 The idea of packing up functional units

2:42 into nested objects is called Object Oriented Programming.

2:44 This is very similar to what we’ve done all series long:

2:47 hide complexity by encapsulating low-level details in higher-order components.

2:52 Before we packed up things like

2:54 transistor circuits into higher-level boolean gates.

2:56 Now we’re doing the same thing with software.

2:57 Yet again, it’s a way to move up a new level of abstraction!

3:07 Breaking up a big program, like a car’s software,

3:10 into functional units is perfect for teams.

3:12 One team might be responsible for the cruise control system,

3:15 and a single programmer on that team tackles a handful of functions.

3:19 This is similar to how big, physical things are built, like skyscrapers.

3:22 You’ll have electricians running wires, plumbers fitting pipes, welders welding,

3:26 painters painting, and hundreds of other people teeming all over the hull.

3:29 They work together on different parts simultaneously,

3:32 leveraging their different skills.

3:34 Until one day, you’ve got a whole working building!

3:36 But, returning to our cruise control example… its code is going to have

3:39 to make use of functions in other parts of the engine’s software,

3:42 to, you know, keep the car at a constant speed.

3:45 That code isn’t part of the cruise control team’s responsibility.

3:48 It’s another team’s code.

3:49 Because the cruise control team didn’t write that, they’re going

3:52 to need good documentation about what each function in the code does,

3:55 and a well-defined Application Programming Interface— or API for short.

3:59 You can think of an API as the way

4:02 that collaborating programmers interact across various parts of the code.

4:04 For example, in the IgnitionControl object,

4:06 there might be functions to set the RPM of the engine,

4:09 check the spark plug voltage, as well as fire the individual spark plugs.

4:12 Being able to set the motor’s RPM is really useful,

4:15 the cruise control team is going to need to call that function.

4:18 But, they don’t know much about how the ignition system works.

4:21 It’s not a good idea to let them

4:23 call functions that fire the individual spark plugs.

4:25 Or the engine might explode!

4:26 Maybe.

4:27 The API allows the right people access to the right functions and data.

4:31 Object Oriented Programming languages do this by letting

4:33 you specify whether functions are public or private.

4:36 If a function is marked as “private”,

4:38 it means only functions inside that object can call it.

4:41 So, in this example, only other functions inside of IgnitionControl,

4:44 like the setRPM function, can fire the sparkplugs.

4:47 On the other hand, because the setRPM function is marked as public,

4:51 other objects can call it, like cruise control.

4:54 This ability to hide complexity, and selectively reveal it,

4:56 is the essence of Object Oriented Programming,

4:58 and it’s a powerful and popular way

5:01 to tackle building large and complex programs.

5:03 Pretty much every piece of software on your computer,

5:05 or game running on your console,

5:07 was built using an Object Oriented Programming Language,

5:10 like C++, C# or Objective-C.

5:12 Other popular “OO” languages you may have heard of are Python and Java.

5:15 It’s important to remember that code, before being compiled, is just text.

5:19 As I mentioned earlier,

5:20 you could write code in Notepad or any old word processor.

5:23 Some people do.

5:24 But generally, today’s software developers

5:26 use special-purpose applications for writing programs,

5:28 ones that integrate many useful tools for writing,

5:31 organizing, compiling and testing code.

5:34 Because they put everything you need in one place,

5:36 they’re called Integrated Development Environments, or IDEs for short.

5:39 All IDEs provide a text editor for writing code,

5:42 often with useful features like automatic color-coding to improve readability.

5:46 Many even check for syntax errors as you type, like spell check for code.

5:50 Big programs contain lots of individual source files,

5:52 so IDEs allow programmers to organize and efficiently navigate everything.

5:56 Also built right into the IDE is the ability to compile and run code.

6:00 And if your program crashes, because it’s still a work in progress,

6:03 the IDE can take you back to the line of code where it happened,

6:06 and often provide additional information to help you track down and fix the bug,

6:10 which is a process called debugging.

6:11 This is important because most programmers spend 70

6:14 to 80% of their time testing and debugging, not writing new code.

6:18 Good tools, contained in IDEs,

6:19 can go a long way when it comes to helping programmers prevent and find errors.

6:23 Many computer programmers can be pretty loyal

6:25 to their IDEs though- but let’s be honest.

6:27 VIM is where it’s at.

6:29 Providing you know how to quit.

6:30 In addition to coding and debugging,

6:31 another important part of a programmer's job is documenting their code.

6:35 This can be done in standalone files called “read-me’s” which

6:37 tell other programmers to read that help file before diving in.

6:40 It can also happen right in the code itself with comments.

6:43 These are specially-marked statements that the program

6:45 knows to ignore when the code is compiled.

6:47 They exist only to help programmers figure out what’s what in the source code.

6:51 Good documentation helps programmers when they

6:52 revisit code they haven’t seen for awhile,

6:54 but it’s also crucial for programmers who are totally new to it.

6:57 I just want to take a second here and reiterate that it’s THE WORST

7:01 when someone parachutes a load of uncommented

7:03 and undocumented code into your lap,

7:04 and you literally have to go line by line to understand what the code is doing.

7:08 Seriously.

7:09 Don’t be that person.

7:10 Documentation also promotes code reuse.

7:13 So, instead of having programmers constantly

7:14 write the same things over and over,

7:16 they can track down someone else’s code that does what they need.

7:19 Then, thanks to documentation, they can put it to work in their program,

7:23 without ever having to read through the code.

7:25 “Read the docs” as they say.

7:26 In addition to IDEs, another important piece of software that helps big teams

7:30 work collaboratively on big coding projects is called Source Control,

7:33 also known as version control or revision control.

7:36 Most often, at a big software company like Apple or Microsoft,

7:39 code for projects is stored on centralized servers, called a code repository.

7:43 When a programmer wants to work on a piece of code,

7:45 they can check it out, sort of like checking out a book out from a library.

7:48 Often, this can be done right in an IDE.

7:51 Then, they can edit this code all they want on their personal computer,

7:54 adding new features and testing if they work.

7:56 When the programmer is confident their changes

7:58 are working and there are no loose ends,

8:00 they can check the code back into the repository,

8:02 known as committing code, for everyone else to use.

8:05 While a piece of code is checked out,

8:07 and presumably getting updated or modified, other programmers leave it alone.

8:10 This prevents weird conflicts and duplicated work.

8:12 In this way, hundreds of programmers can be

8:15 simultaneously checking in and out pieces of code,

8:17 iteratively building up huge systems.

8:19 Critically, you don’t want someone committing buggy code,

8:22 because other people and teams may rely on it.

8:25 Their code could crash, creating confusion and lost time.

8:27 The master version of the code, stored on the server,

8:30 should always compile without errors and run with minimal bugs.

8:33 But sometimes bugs creep in.

8:34 Fortunately, source control software keeps track of all changes,

8:36 and if a bug is found, the whole code, or just a piece,

8:40 can be rolled back to an earlier, stable version.

8:42 It also keeps track of who made each change, so coworkers can send nasty,

8:46 I mean, helpful and encouraging emails to the offending person.

8:50 Debugging goes hand in hand with writing code,

8:52 and it’s most often done by an individual or small team.

8:55 The big picture version of debugging is Quality Assurance testing, or QA.

8:59 This is where a team rigorously tests out a piece of software,

9:01 attempting to create unforeseen conditions that might trip it up.

9:04 Basically, they elicit bugs.

9:06 Getting all the wrinkles out is a huge effort,

9:08 but vital in making sure the software works as intended

9:11 for as many users in as many situations as imaginable before it ships.

9:15 You’ve probably heard of beta software This is

9:18 a version of software that’s mostly complete, but not 100% fully tested.

9:21 Companies will sometimes release beta versions

9:23 to the public to help them identify issues,

9:25 it’s essentially like getting a free QA team.

9:28 What you don’t hear about as much is

9:30 the version that comes before the beta: the alpha version.

9:33 This is usually so rough and buggy, it’s only tested internally.

9:36 So, that’s the tip of the iceberg in terms of the tools,

9:38 tricks and techniques that allow software engineers to construct

9:41 the huge pieces of software that we know and love today,

9:44 like YouTube, Grand Theft Auto 5, and Powerpoint.

9:47 As you might expect, all those millions of lines of code needs

9:50 some serious processing power to run at useful speeds,

9:52 so next episode we’ll be talking about how computers got so incredibly fast.

9:56 See you then.

Study with Looplines Download Captions Watch on YouTube