Skip to content

Commit ec40661

Browse files
bowbahdoefirasrg
andauthored
Sync (#30)
* more sections * First feedback round * Update prelude.md * ... * Spelling fix Co-Authored-By: Firas Regaieg <37019463+firasrg@users.noreply.github.com> * Arguments chapter * More Challenges * Run prettier * user input * October 14th, #1 * Array challenges * Delete challenges * Null * ... * Update null_as_absence.md * Delete out.json * Fix quotes * Add first no_runs * Fix number example * ... * Write more of the classes section * Constructors * Clean up getting started a little * Use a duke * Don't link anywhere yet * Increase lines needed to show a duke * Fix field access section * ... * ... * ... * ... * ... * switch and enums --------- Co-authored-by: Firas Regaieg <37019463+firasrg@users.noreply.github.com>
1 parent 6922baa commit ec40661

File tree

239 files changed

+5814
-1733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

239 files changed

+5814
-1733
lines changed

book.toml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,10 @@ additional-js = ["ferris.js"]
1616
enable = true # whether or not to enable section folding
1717
level = 0 # the depth to start folding
1818

19-
[preprocessor.features]
20-
command = "python3 features.py"
21-
# Going to start writing the rest of the book
22-
# Assuming this is true
23-
toplevel_anonymous_class = true
24-
# Not ready
25-
simple_io = false
26-
# Turn on when Java 21 released
27-
java_21 = false
28-
2919
[output.html.playground]
3020
editable = true
3121

3222
[output.html.code.hidelines]
3323
java = "~"
24+
[output.html.code.hidelines]
25+
java = "~"

features.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

ferris.js

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,65 @@
11
var ferrisTypes = [
2-
{
3-
attr: 'does_not_compile',
4-
title: 'This code does not compile!'
5-
},
6-
{
7-
attr: 'panics',
8-
title: 'This code will crash!'
9-
},
10-
{
11-
attr: 'not_desired_behavior',
12-
title: 'This code does not produce the desired behavior.'
13-
}
14-
]
15-
16-
document.addEventListener('DOMContentLoaded', () => {
17-
for (var ferrisType of ferrisTypes) {
18-
attachFerrises(ferrisType)
19-
}
20-
})
21-
22-
function attachFerrises(type) {
23-
var elements = document.getElementsByClassName(type.attr)
24-
25-
for (var codeBlock of elements) {
26-
var lines = codeBlock.innerText.replace(/\n$/, '').split(/\n/).length
27-
var size = 'large'
28-
if (lines < 4) {
29-
size = 'small'
30-
}
31-
32-
var container = prepareFerrisContainer(codeBlock, size == 'small')
33-
container.appendChild(createFerris(type, size))
34-
}
2+
{
3+
attr: 'does_not_compile',
4+
title: 'This code does not compile!'
5+
},
6+
{
7+
attr: 'panics',
8+
title: 'This code will crash!'
9+
},
10+
{
11+
attr: 'not_desired_behavior',
12+
title: 'This code does not produce the desired behavior.'
13+
}
14+
]
15+
16+
document.addEventListener('DOMContentLoaded', () => {
17+
for (var ferrisType of ferrisTypes) {
18+
attachFerrises(ferrisType)
3519
}
36-
37-
function prepareFerrisContainer(element, useButtons) {
38-
var foundButtons = element.parentElement.querySelector('.buttons')
39-
if (useButtons && foundButtons) {
40-
return foundButtons
20+
})
21+
22+
function attachFerrises(type) {
23+
var elements = document.getElementsByClassName(type.attr)
24+
25+
for (var codeBlock of elements) {
26+
var lines = codeBlock.innerText.replace(/\n$/, '').split(/\n/).length
27+
var size = 'large'
28+
if (lines < 5) {
29+
size = 'small'
4130
}
42-
43-
var div = document.createElement('div')
44-
div.classList.add('ferris-container')
45-
46-
element.parentElement.insertBefore(div, element)
47-
48-
return div
31+
32+
var container = prepareFerrisContainer(codeBlock, size == 'small')
33+
container.appendChild(createFerris(type, size))
4934
}
50-
51-
function createFerris(type, size) {
52-
var a = document.createElement('a')
53-
a.setAttribute('href', 'ch00-00-introduction.html#ferris')
54-
a.setAttribute('target', '_blank')
55-
56-
var img = document.createElement('img')
57-
img.setAttribute('src', '../img/' + type.attr + '.svg')
58-
img.setAttribute('title', type.title)
59-
img.classList.add('ferris')
60-
img.classList.add('ferris-' + size)
61-
62-
a.appendChild(img)
63-
64-
return a
35+
}
36+
37+
function prepareFerrisContainer(element, useButtons) {
38+
var foundButtons = element.parentElement.querySelector('.buttons')
39+
if (useButtons && foundButtons) {
40+
return foundButtons
6541
}
66-
42+
43+
var div = document.createElement('div')
44+
div.classList.add('ferris-container')
45+
46+
element.parentElement.insertBefore(div, element)
47+
48+
return div
49+
}
50+
51+
function createFerris(type, size) {
52+
var a = document.createElement('a')
53+
// a.setAttribute('href', 'ch00-00-introduction.html#ferris')
54+
a.setAttribute('target', '_blank')
55+
56+
var img = document.createElement('img')
57+
img.setAttribute('src', '../img/' + type.attr + '.svg')
58+
img.setAttribute('title', type.title)
59+
img.classList.add('ferris')
60+
img.classList.add('ferris-' + size)
61+
62+
a.appendChild(img)
63+
64+
return a
65+
}

src/SUMMARY.md

Lines changed: 92 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,16 @@
9999
- [If](./branching_logic/if.md)
100100
- [Nested Ifs](./branching_logic/nested_ifs.md)
101101
- [Else](./branching_logic/else.md)
102+
- [Else](./branching_logic/else.md)
102103
- [Else If](./branching_logic/else_if.md)
103104
- [Relation to Delayed Assignment](./branching_logic/relation_to_delayed_assignment.md)
104105
- [Scoped Variables](./branching_logic/scoped_variables.md)
106+
- [Scoped Variables](./branching_logic/scoped_variables.md)
105107
- [Conditional Operator](./branching_logic/conditional_operator.md)
106108
- [Boolean Expressions](./branching_logic/boolean_expressions.md)
107109
- [Challenges](./branching_logic/challenges.md)
108110

111+
109112
- [Loops](./loops.md)
110113
- [While](./loops/while.md)
111114
- [Endless Loops](./loops/endless_loops.md)
@@ -169,6 +172,7 @@
169172
- [Scope](./methods/scope.md)
170173
- [main](./methods/main.md)
171174
- [Challenges](./methods/challenges.md)
175+
172176
- [Arguments](./arguments.md)
173177

174178
- [Declaration](./arguments/declaration.md)
@@ -180,26 +184,23 @@
180184
- [Inferred Types](./arguments/inferred_types.md)
181185
- [Challenges](./arguments/challenges.md)
182186

183-
- [Return](./return_values.md)
184-
- [Return Values](./return_values/return_values.md)
185-
- [Conversion](./return_values/conversion.md)
187+
- [Return Values](./return_values.md)
188+
- [Declaration](./return_values/declaration.md)
189+
- [Return Statement](./return_values/return_statement.md)
190+
- [Exhaustiveness](./return_values/exhaustiveness.md)
186191
- [void](./return_values/void.md)
192+
- [Return in void methods](./return_values/return_in_void_methods.md)
193+
- [Conversion](./return_values/conversion.md)
187194
- [Unreachable Statements](./return_values/unreachable_statements.md)
188-
- [Pure Functions](./return_values/pure_functions.md)
189-
- [Impure Functions](./return_values/impure_functions.md)
190195

191196
# Data Types III
192197

193-
- [Identity Types](./identity_types.md)
194-
- [Comparison with ==](./identity_types/comparison_with_equalsequals.md)
195-
- [Primitive Types](./primitive_types.md)
196198
- [null](./null.md)
197199
- [Null as Absence](./null/null_as_absence.md)
200+
- [Null as Unknown](./null/null_as_unknown.md)
198201
- [Checking for null](./null/checking_for_null.md)
199-
- [Field Access](./null/field_access.md)
200-
- [Instance Methods](./null/instance_methods.md)
202+
- [NullPointerException](./null/null_pointer_exception.md)
201203
- [Boxed Primitives](./boxed_primitives.md)
202-
- [Primitive Types](./boxed_primitives/primitive_types.md)
203204
- [Integer](./boxed_primitives/integer.md)
204205
- [Double](./boxed_primitives/double.md)
205206
- [Character](./boxed_primitives/character.md)
@@ -208,39 +209,100 @@
208209
- [Boxing Conversion](./boxed_primitives/boxing_conversion.md)
209210
- [Arrays of Boxed Primitives](./boxed_primitives/arrays_of_boxed_primitives.md)
210211
- [Challenges](./boxed_primitives/challenges.md)
212+
- [Challenges](./boxed_primitives/challenges.md)
211213
- [Arrays II](./arrays_ii.md)
214+
- [Initializion with Size](./arrays_ii/initialization_with_size.md)
212215
- [Default Values](./arrays_ii/default_values.md)
213-
- [Populate Array]()
216+
- [Populate Arrays](./arrays_ii/populate_arrays.md)
214217

215218
# Code Structure II
216219

217220
- [Classes](./classes.md)
218-
221+
- [The meaning of the word Class](./classes/the_meaning_of_the_word_class.md)
219222
- [Class Declaration](./classes/class_declaration.md)
220-
- [User Defined Types](./classes/user_defined_types.md)
221-
- [Naming Classes](./classes/naming_classes.md)
222-
- [Field Declaration](./classes/field_declaration.md)
223-
- [Field Access](./classes/field_access)
224-
- [Naming Fields](./classes/naming_fields.md)
225-
- [new](./classes/new.md)
226-
- [Zero Values](./classes/zero_values.md)
223+
- [Naming](./classes/naming.md)
224+
- [Instances](./classes/instances.md)
225+
- [Fields](./classes/fields.md)
226+
- [Field Initialization](./classes/field_initialization.md)
227+
- [Field Access](./classes/field_access.md)
228+
- [Field Default Values](./classes/field_default_values.md)
227229
- [Aliasing](./classes/aliasing.md)
228-
- [null](./classes/null.md)
230+
- [Return Multiple Values](./classes/return_multiple_values.md)
229231

230-
- [Constructors](./constructors.md)
232+
- [Instance Methods](./instance_methods.md)
233+
- [Invocation](./instance_methods/invocation.md)
234+
- [Arguments](./instance_methods/arguments.md)
235+
- [Field Access](./instance_methods/field_access.md)
236+
- [Field Updates](./instance_methods/field_updates.md)
237+
- [Derived Values](./instance_methods/derived_values.md)
238+
- [Invoke Other Methods](./instance_methods/invoke_other_methods.md)
239+
- [this](./instance_methods/this.md)
240+
- [Disambiguation](./instance_methods/disambiguation.md)
241+
- [Clarity](./instance_methods/clarity.md)
242+
243+
# Data Types IV
244+
245+
- [Enums](./enums.md)
246+
- [Declaration](./enums/declaration.md)
247+
- [Variants](./enums/variants.md)
248+
- [Naming](./enums/naming.md)
249+
- [Usage](./enums/usage.md)
250+
- [Equality](./enums/equality.md)
251+
- [Comparison to boolean](./enums/comparison_to_boolean.md)
252+
253+
# Control Flow III
254+
255+
- [Exceptions](./exceptions.md)
256+
- [throw](./exceptions/throw.md)
257+
- [Messages](./exceptions/messages.md)
258+
- [Stack Traces](./exceptions/stack_traces.md)
259+
- [try/catch](./exceptions/try_catch.md)
260+
- [Switch](./switch.md)
261+
- [Case and Default](./switch/case_and_default.md)
262+
- [Strings](./switch/strings.md)
263+
- [ints](./switch/ints.md)
264+
- [Enums](./switch/enums.md)
265+
- [Omitted Default](./switch/omitted_default.md)
266+
- [Exhaustiveness](./switch/exhaustiveness.md)
267+
- [Combining Cases](./switch/combining_cases.md)
268+
- [null](./switch/null.md)
269+
270+
# Code Structure III
231271

232-
- [this](./constructors/this.md)
272+
- [Constructors](./constructors.md)
273+
- [Declaration](./constructors/declaration.md)
233274
- [The Default Constructor](./constructors/the_default_constructor.md)
275+
- [Arguments](./constructors/arguments.md)
234276
- [Final Fields](./constructors/final_fields.md)
235-
- [Multiple Constructors](./constructors/multiple_constructors.md)
277+
- [Invariants](./constructors/invariants.md)
278+
- [Overloads](./constructors/overloads.md)
279+
- [Delegation](./constructors/delegation.md)
280+
281+
282+
283+
<!--
284+
285+
- [Strings II](./strings_ii.md)
286+
- [length]()
287+
- [equals]()
288+
- [charAt]()
289+
- [equalsIgnoreCase]()
290+
291+
- [Multiple Source Files]()
292+
- [Why]()
293+
- [How]()
294+
- [Restrictions]()
295+
- [The Main Class]()
296+
- [The Implicit Main Class]()
297+
298+
299+
- [Multiple Files]()
300+
- [The Implicit Main Class]()
301+
- [Private]()
302+
303+
## Data Types IV
236304
237-
- [Instance Methods](./instance_methods.md)
238305
239-
- [Declaration](./instance_methods/declaration.md)
240-
- [Invocation](./instance_methods/invocation.md)
241-
- [this](./instance_methods/this.md)
242-
- [Aliasing](./instance_methods/aliasing.md)
243-
- [Derived Values](./instance_methods/derived_values.md)
244306
245307
- [Documentation]()
246308
- [Documentation Comments]()
@@ -253,7 +315,6 @@
253315
- [Primitive Classes](./classes/primitive_classes.md)
254316
- [Reference Classes](./classes/reference_classes.md)
255317
256-
<!--
257318
Arrays
258319
copy an array (System.arrayCopy, for loop)
259320
Generics

0 commit comments

Comments
 (0)