Skip to content

Commit

Permalink
Minor refactorings
Browse files Browse the repository at this point in the history
Co-authored-by: Ennio <ennio.strohauer@student.hpi.de>
  • Loading branch information
ekrebs5 and Ennio committed Jun 14, 2023
1 parent a1b798c commit f031d1f
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
tests
test03theLastStatementReturns
"This is part of the buggy way of the art of Smalltalk.
The value of the last statement of a block is returned.
Always the last!"

| processing |

self assert: xx equals: [123 . 456 . 789] value.
self assert: xx equals: ['first' . 'second'] value
self assert: xx equals: ['first' . 'second'] value.

processing := [:a :b | a. b].
self assert: xx equals: (processing value: true value: false).
self assert: xx equals: (processing value: false value: true)
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
tests
test05passParametersToBlocksButPassTheRight
"Remember the ancient button of 'debug'.
You can also select and do it / print it code in all text windows, including the Workspace and this one (But keep self in mind in this case)"

| multiply |
multiply := [:a :b | a * b].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests
test08blocksAndConditions
test07blocksAndConditions
"You might have noticed that we use blocks for and: and or:.
Maybe you might want to take a moment to reflect on the reasons for that."

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
"instance" : {
"test01whatIsABlock" : "rhi 10/12/2017 08:56",
"test02aBlockCanBeExecuted" : "rhi 10/12/2017 09:22",
"test03theLastStatementReturns" : "rhi 10/12/2017 09:22",
"test03theLastStatementReturns" : "ek 6/14/2023 11:25",
"test04blocksCanBeStored" : "rhi 10/12/2017 08:57",
"test05passParametersToBlocksButPassTheRight" : "rhi 10/12/2017 08:57",
"test05passParametersToBlocksButPassTheRight" : "ek 6/14/2023 11:23",
"test06blocksWithTempVariables" : "rhi 10/12/2017 09:36",
"test07rememberTheFinalStatement" : "rhi 10/12/2017 11:09",
"test08blocksAndConditions" : "rhi 10/12/2017 11:09" } }
"test07blocksAndConditions" : "ek 6/14/2023 11:25" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
as yet unclassified
koan05whoIAmTellsYouClassSuccess

^ 'Success! Remember to only use meta programming if absolutely required for the situation.'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
as yet unclassified
koan06classesUnderstandCanUnderstandSuccess

^ 'Success! Remember to only use meta programming if absolutely required for the situation.'
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
tests
test02instanceVariablesAreEncapsulated
"First take a look at the KoanLotus class using the Browse Project button.
"First take a look at the KoanLotus class using the 'browse' button.
(You may also select 'KoanLotus' and click browse it)
It has two instance variables: privateInstanceVariable and publicInstanceVariable.
Also look at the methods of the Lotus. Now what will happen down below?"
Also look at the methods of the Lotus. Now what will happen down below?
Hint:
should:raise: executes the code in braces and looks for an exception specified after raise:.
You can find the name of the exception class in the title of the debugger window above."

| aLotus |
aLotus := KoanLotus new.
self should: [aLotus privateInstanceVariable] raise: xx

"should:raise: executes the code in braces and looks for an exception specified after raise:.
You can find the name of the exception class in the title of the debugger window."
self should: [aLotus privateInstanceVariable] raise: xx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
tests
test06classesUnderstandCanUnderstand
"Always reflecting on yourself isn't good. Use it wisely!
Otherwise, you spill implementation details over your nice model."

"In most cases, just sending the message instead of checking for it is enough."

self assert: xx equals: (KoanLotus canUnderstand: #publicInstanceVariable).
self assert: xx equals: (KoanLotus canUnderstand: #walk).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"class" : {
"koan05whoIAmTellsYouClassSuccess" : "ek 6/14/2023 11:14",
"koan06classesUnderstandCanUnderstandSuccess" : "ek 6/14/2023 11:14",
"priority" : "rhi 10/12/2017 11:44",
"requiredClasses" : "rhi 10/12/2017 11:44",
"requirements" : "JE 6/8/2017 15:19" },
"instance" : {
"test01createAnInstanceWithNew" : "rhi 10/12/2017 09:11",
"test02instanceVariablesAreEncapsulated" : "rhi 10/12/2017 09:25",
"test02instanceVariablesAreEncapsulated" : "ek 6/14/2023 11:00",
"test03theTaleOfNewAndBasicNew" : "rhi 10/12/2017 09:14",
"test04useGettersAndSetters" : "rhi 10/12/2017 09:15",
"test05whoIAmTellsYouClass" : "rhi 10/12/2017 09:25",
"test06classesUnderstandCanUnderstand" : "rhi 10/12/2017 09:24" } }
"test06classesUnderstandCanUnderstand" : "ek 6/14/2023 11:11" } }
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tests
test01thereIsOnlyOneNil
"The concept of nil represents nothingness. How many nil objects are there?"

self assert: xx equals: self class countAllInstancesOfNil
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
tests
test02variablesAreInitializedToNil
"What value does a variable have before one is assigned?"

| aVariable |
self assert: xx equals: aVariable
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
tests
test03nilIsJustAnotherObject
"What is the class of the nil object?"

self assert: xx equals: nil class

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"priority" : "rhi 10/12/2017 11:48",
"requirements" : "rhi 10/12/2017 11:49" },
"instance" : {
"test01thereIsOnlyOneNil" : "rhi 10/12/2017 11:48",
"test02variablesAreInitializedToNil" : "JLO 8/4/2017 14:37",
"test03nilIsJustAnotherObject" : "rhi 10/12/2017 11:15" } }
"test01thereIsOnlyOneNil" : "ek 6/14/2023 11:18",
"test02variablesAreInitializedToNil" : "ek 6/14/2023 11:17",
"test03nilIsJustAnotherObject" : "ek 6/14/2023 11:18" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hints-explanations
koan07useCascadesToNotRepeatSuccess

^ 'Success! Cascades should be used whenever you send multiple messages to the same receiver.'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hints-explanations
koan08useCascadesToNotRepeatButBeCareful1Success

^ 'Success! The return value of #add: is the newly added value, not the collection it was added to.'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hints-explanations
koan09useCascadesToNotRepeatButBeCareful2Success

^ 'Success! Methods such as #reversed and #asUppercase do not change the original String but instead return a copy.'
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tests
test07useCascadesToNotRepeat

"You can use cascades to send multiple Messages to one object"
"Use cascades to send multiple messages to one object"
| result |
result := Morph new
extent: 20@20;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
tests
test10yourselfIsTheObjectItself

"The method #yourself always returns the object itself. This can be used in cascades such that the last method returns for sure what you expect."
"The method #yourself always returns the object itself. This can be used in cascades such that the last method returns for sure what you expect.
Keep in mind what you previously learned about the used messages."

| result |
result := Set new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"class" : {
"koan07useCascadesToNotRepeatSuccess" : "ek 6/14/2023 11:04",
"koan08useCascadesToNotRepeatButBeCareful1Success" : "ek 6/14/2023 11:06",
"koan09useCascadesToNotRepeatButBeCareful2Success" : "ek 6/14/2023 11:08",
"priority" : "rhi 10/12/2017 11:49",
"requirements" : "JE 6/8/2017 15:22" },
"instance" : {
Expand All @@ -9,7 +12,7 @@
"test04everyObjectHasADifferentId" : "rhi 10/12/2017 11:16",
"test05butNotSmallIntegers" : "rhi 10/12/2017 08:50",
"test06copyObjectsWithNewFrom" : "rhi 10/12/2017 08:50",
"test07useCascadesToNotRepeat" : "ek 6/14/2023 10:52",
"test07useCascadesToNotRepeat" : "ek 6/14/2023 11:02",
"test08useCascadesToNotRepeatButBeCareful1" : "ek 6/14/2023 10:52",
"test09useCascadesToNotRepeatButBeCareful2" : "ek 6/14/2023 10:54",
"test10yourselfIsTheObjectItself" : "ek 6/14/2023 10:52" } }
"test10yourselfIsTheObjectItself" : "ek 6/14/2023 11:06" } }

0 comments on commit f031d1f

Please sign in to comment.