Skip to content

Commit bdf8bbe

Browse files
committed
Rewrite chapter 6
1 parent 87e6e98 commit bdf8bbe

27 files changed

+135
-20
lines changed

06-Integrated-Development-Environments.md

Lines changed: 135 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,55 +29,172 @@ We know, we know.
2929
You're *really* going to miss `g++`.
3030

3131
Just bear with us for this lab.
32-
Then you can travel back to 1980 when things were actually good[^reagan].
32+
Then you can travel back to 1980 when things were actually good.[^reagan]
3333

3434
### Takeaways
3535

36-
- Gain experience with Integrated Development Environments (IDEs)
37-
- Explore editor features
38-
- Try build (compilation) features
39-
- Experiment with built-in debugging tools
36+
- Explore editor features
37+
- Try build (compilation) features
38+
- Experiment with built-in debugging tools
4039

4140
## Walkthrough
4241

4342
Usually when we connect to a remote Linux machine, all we need is a shell, and PuTTY does everything we need.
4443
For this lab, we're going to need to setup X-forwarding as well.
45-
If you haven't already, be sure to reference the appendix on [X-forwarding].
44+
If you haven't already, be sure to reference the appendix on X-forwarding.
45+
Make sure you start Xming before you try to forward any X11 windows!
46+
You won't be able to use bash within the shell that's running `codeblocks`.
47+
You may find it useful to keep a couple of PuTTY windows open while you work.
4648

49+
We'll be using the Code::Blocks IDE.
50+
To open this IDE, run the `codeblocks` command in a shell.
51+
Hopefully, after a while of thinking about it, the system will deign to display a window somewhat like the following:
52+
53+
![Code::Blocks](06/open.png)
54+
55+
Look! Buttons! Windows! Tabs!
56+
57+
### Getting started
58+
59+
Code::Blocks organizes your code into projects.
60+
It's best to make one project per program.
61+
Each project has an associated project file that ends in `.cbp`; this file keeps track of the code files in your project, how to build them, and various other
62+
sundries.
63+
64+
To create a new project, click any of the numerous "new project" buttons.
65+
Code::Blocks knows how to make a bunch of different kinds of software, but if you want to make a plain 'ol terminal application in C++, you'll want
66+
to choose the "Console application" option:
67+
68+
![New project dialog](06/new-console-application.png){width=80%}
69+
70+
Code::Blocks will ask you for a name and a location to store the project in.
71+
It will also ask you about compilers and targets --- the default values are fine; we'll talk about them later.
72+
73+
Once you've created a project, you can add new files to it via any of the "new" buttons.
74+
Or, you may have some files that you'd like to add to your project --- maybe you have some starter code for an assignment,
75+
or you're making a project for something you were already working on.
76+
To do this, first put your files where you want them (usually in the project directory --- or you can make the project directory be the location of your files),
77+
then right-click the project and click "Add files":
78+
79+
![Adding files](06/add-files.png){width=50%}
80+
81+
### Building
82+
83+
Once you've created a project and put some files in it, you'll probably want to compile your code!
84+
Below you can see the various compilation options Code::Blocks offers --- you can build your code and run it in one step!
85+
86+
![The Build menu](06/build-actions.png){width=50%}
87+
88+
When you click "build", Code::Blocks only compiles the files that have changed since you last built the project.
89+
Typically this works fine, but sometimes you'll want to recompile everything; for this task, the "rebuild" button is what you want.
90+
91+
Projects have one or more "build targets" --- by default, a "debug" target and a "release" target.
92+
These targets primarily change the flags passed to the compiler; the debug target usually builds faster and includes debugging symbols,
93+
but the code produced by the release target is more efficient.
94+
If you are planning to use a debugger or Valgrind, you should use the "debug" target.
95+
96+
You can see your project's target configurations in the project build options (right-click on the project and choose "Build options").
97+
For now, the options Code::Blocks chooses for you should be sufficient; later on in this book we'll discuss some additional flags that you might want to add.
98+
99+
<!-- ![Build options for the Debug target](06/build-options.png){width=80%} -->
100+
101+
### Navigation and Editing
102+
103+
One big draw of using an IDE is the out-of-the-box editing and navigation features.
104+
Since Code::Blocks is primarily designed for writing C++ programs, it offers special features for editing C++ code.
105+
106+
If you type a class instance name followed by a `.`, Code::Blocks will show a list of potential member functions and variables you may want:
107+
108+
![Class member completion list](06/completion-list.png){width=80%}
109+
110+
You can type the first few letters of the desired method or variable to narrow the list down,
111+
then press \keys{\tab} to have Code::Blocks complete the name for you.
112+
113+
Once you've typed out a complete function name, Code::Blocks will show you the type signature, so you know what parameters it takes:
114+
115+
![Type signature hint](06/completion-parameter-hint.png){width=80%}
116+
117+
You can also access the "Open Declaration" and "Open Implementation" features of the tab completion window by right-clicking on any function or variable name:
118+
119+
![The result of right-clicking on `append`](06/find-symbol.png){width=70%}
120+
121+
In the same menu, under the "Code refactoring" submenu, you can rename a variable or function across all files in your project:
122+
123+
![Renaming a symbol](06/rename-symbol.png){width=80%}
124+
125+
If you are navigating through a large file, you can jump to function implementations with the "Code Completion" toolbar.
126+
First, select the scope your function is declared in (typically either `<global>` or the name of the class your function is a member of):
127+
128+
![Selecting a scope](06/navigating-scope.png)
129+
130+
Then select your function from the next drop-down, and Code::Blocks will jump you to that point in the file!
131+
132+
![Selecting a function](06/navigating-members.png){width=80%}
133+
134+
You can collapse (or 'fold') code between braces by clicking the `-` button in the margin by the line number.
135+
This is particularly handy when working with long functions that are hard to fit all on one screen.
136+
137+
![Folding the definition of the `Cell` class](06/folding.png){width=80%}
138+
139+
### Debugging
140+
141+
Code::Blocks integrates with the GNU debugger (`gdb`) to make debugging code easier for you.
142+
We'll talk more about `gdb` in a future chapter, but for now we'll introduce the features Code::Blocks integrates with.
143+
144+
In short, a debugger allows you to pause the execution of your program, inspect variables, and step through your code line-by-line.
145+
You can tell the debugger to stop execution at a specific line by setting a breakpoint on that line: click to the right of the line number,
146+
and a little stop sign will appear:
147+
148+
![Setting a breakpoint](06/set-breakpoint.png){width=60%}
149+
150+
Once you've set one or more breakpoints, you can click the red arrow on the debugger toolbar to run your program and have it stop at that breakpoint.
151+
152+
![The debugger toolbar](06/debugger-toolbar.png){width=70%}
153+
154+
Other buttons on the toolbar allow you to step your code by line, or by CPU instruction.
155+
156+
When you are running a program in the debugger, you can right-click on variables and "watch" them---this will open a new window that displays that variable
157+
and its value, along with function argument values and local variable values.
158+
Once you're watching a variable, you can edit its value while the program is running!
159+
160+
![Watching a new variable](06/watch-variable.png){width=45%}
161+
162+
![The "Watches" window](06/watch-window.png){width=35%}
163+
164+
Code::Blocks also opens a tab at the bottom of the window that allows you to send commands to `gdb`, just as you would when using `gdb` from the command line.
165+
While Code::Blocks doesn't add any new functionality to `gdb`, it does make some common debugging tasks a lot easier!
166+
167+
![The `gdb` tab](06/gdb-window.png){width=90%}
47168

48169
\newpage
49170
## Questions
171+
Name: `______________________________`
50172

173+
1. In your own words, list three features of an IDE.
51174
\vspace{10em}
175+
176+
2. Think back to chapter 1. How do IDEs and text editors differ?
52177
\newpage
53178

54179

55180
## Quick Reference
56181

57-
### General Tips
58-
59-
- Make sure you start Xming before you try to forward any X11 windows!
60-
- You won't be able to use bash within the shell that's running `codeblocks`.
61-
You may find it useful to keep a couple of PuTTY windows open while you work.
62-
63-
### Code::Blocks
64-
65-
#### Troubleshooting
182+
### Troubleshooting
66183

67184
- Don't start Code::Blocks if your `pwd` is in your `SDRIVE`.
68185
Try changing to your linuxhome directory (i.e., `cd ~`).
69186
Otherwise you’ll be waiting *all day* for Code::Blocks to open up.
70187
- If Code::Blocks doesn't let you navigate to your cloned repository, you can find it by going the long way.
71188
You can find your SDRIVE by going to its absolute path: `/nethome/users/<username>/cs1001/lab06/` (or whatever you call your repository.)
72189

73-
#### Building with Code::Blocks
190+
### Building with Code::Blocks
74191

75192
- \keys{F9} -- Build and run
76193
- \keys{\ctrl + F9} -- Build
77194
- \keys{\ctrl + F10} -- Run
78195
- Enable `-Wall` in \menu{Project > Build Options}
79196

80-
#### Writing code with Code::Blocks
197+
### Writing code with Code::Blocks
81198

82199
- \keys{\ctrl + .} -- Go to function implementation.
83200
- \keys{\ctrl + \shift + .} -- Go to function declaration.
@@ -86,16 +203,14 @@ If you haven't already, be sure to reference the appendix on [X-forwarding].
86203

87204
## Further Reading
88205

89-
### Code::Blocks
90-
91206
- Code::Blocks Project Homepage: [http://www.codeblocks.org](http://www.codeblocks.org)
92207
- Tutorial from cplusplus.com: [http://www.cplusplus.com/doc/tutorial/introduction/codeblocks/](http://www.cplusplus.com/doc/tutorial/introduction/codeblocks/)
93208

94209
### Other IDEs
95210

96211
There are a bunch of other IDEs out there.
97212
Some are free; some are not.
98-
If you like the IDEa of an IDE, but you don't like Geany or Code::Blocks, you may give one of these guys a try.
213+
If you like the IDEa of an IDE, but you don't like Code::Blocks, you may give one of these guys a try.
99214

100215
- Visual Studio Code: [https://code.visualstudio.com/](https://code.visualstudio.com/)
101216
- CLion: [https://www.jetbrains.com/clion/](https://www.jetbrains.com/clion/)

06/add-files.png

13.1 KB
Loading

06/build-actions.png

14.8 KB
Loading

06/build-log.png

115 KB
Loading

06/build-options-menu.png

36 KB
Loading

06/build-options.png

79.8 KB
Loading

06/compiler-error.png

107 KB
Loading

06/completion-list.png

34.8 KB
Loading

06/completion-parameter-hint.png

11.2 KB
Loading

06/debug-window-list.png

133 KB
Loading

0 commit comments

Comments
 (0)