Skip to content

Commit 426d6ec

Browse files
committedJul 15, 2021
Initial port
0 parents  commit 426d6ec

File tree

12 files changed

+1051
-0
lines changed

12 files changed

+1051
-0
lines changed
 

‎.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text eol=lf

‎.github/workflows/RunTests.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Runtests
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
repository_dispatch:
9+
10+
jobs:
11+
build:
12+
runs-on: ${{ matrix.os }}-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
java: ['8', '11', '16', '17-ea']
17+
os: [ ubuntu, windows ]
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
- uses: actions/cache@v2
22+
with:
23+
path: ~/.m2/repository
24+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
25+
restore-keys: |
26+
${{ runner.os }}-maven-
27+
- name: Set up JDK
28+
uses: actions/setup-java@v1
29+
with:
30+
java-version: ${{ matrix.java }}
31+
- name: Build with Maven
32+
run: mvn -B verify --file pom.xml

‎.gitignore

+354
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
*.received.*
2+
3+
4+
## Ignore Visual Studio temporary files, build results, and
5+
## files generated by popular Visual Studio add-ons.
6+
##
7+
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
8+
9+
# User-specific files
10+
*.rsuser
11+
*.suo
12+
*.user
13+
*.userosscache
14+
*.sln.docstates
15+
16+
# User-specific files (MonoDevelop/Xamarin Studio)
17+
*.userprefs
18+
19+
# Mono auto generated files
20+
mono_crash.*
21+
22+
# Build results
23+
[Dd]ebug/
24+
[Dd]ebugPublic/
25+
[Rr]elease/
26+
[Rr]eleases/
27+
x64/
28+
x86/
29+
[Aa][Rr][Mm]/
30+
[Aa][Rr][Mm]64/
31+
bld/
32+
[Bb]in/
33+
[Oo]bj/
34+
[Ll]og/
35+
[Ll]ogs/
36+
37+
# Visual Studio 2015/2017 cache/options directory
38+
.vs/
39+
# Uncomment if you have tasks that create the project's static files in wwwroot
40+
#wwwroot/
41+
42+
# Visual Studio 2017 auto generated files
43+
Generated\ Files/
44+
45+
# MSTest test Results
46+
[Tt]est[Rr]esult*/
47+
[Bb]uild[Ll]og.*
48+
49+
# NUnit
50+
*.VisualState.xml
51+
TestResult.xml
52+
nunit-*.xml
53+
54+
# Build Results of an ATL Project
55+
[Dd]ebugPS/
56+
[Rr]eleasePS/
57+
dlldata.c
58+
59+
# Benchmark Results
60+
BenchmarkDotNet.Artifacts/
61+
62+
# .NET Core
63+
project.lock.json
64+
project.fragment.lock.json
65+
artifacts/
66+
67+
# StyleCop
68+
StyleCopReport.xml
69+
70+
# Files built by Visual Studio
71+
*_i.c
72+
*_p.c
73+
*_h.h
74+
*.ilk
75+
*.meta
76+
*.obj
77+
*.iobj
78+
*.pch
79+
*.pdb
80+
*.ipdb
81+
*.pgc
82+
*.pgd
83+
*.rsp
84+
*.sbr
85+
*.tlb
86+
*.tli
87+
*.tlh
88+
*.tmp
89+
*.tmp_proj
90+
*_wpftmp.csproj
91+
*.log
92+
*.vspscc
93+
*.vssscc
94+
.builds
95+
*.pidb
96+
*.svclog
97+
*.scc
98+
99+
# Chutzpah Test files
100+
_Chutzpah*
101+
102+
# Visual C++ cache files
103+
ipch/
104+
*.aps
105+
*.ncb
106+
*.opendb
107+
*.opensdf
108+
*.sdf
109+
*.cachefile
110+
*.VC.db
111+
*.VC.VC.opendb
112+
113+
# Visual Studio profiler
114+
*.psess
115+
*.vsp
116+
*.vspx
117+
*.sap
118+
119+
# Visual Studio Trace Files
120+
*.e2e
121+
122+
# TFS 2012 Local Workspace
123+
$tf/
124+
125+
# Guidance Automation Toolkit
126+
*.gpState
127+
128+
# ReSharper is a .NET coding add-in
129+
_ReSharper*/
130+
*.[Rr]e[Ss]harper
131+
*.DotSettings.user
132+
133+
# TeamCity is a build add-in
134+
_TeamCity*
135+
136+
# DotCover is a Code Coverage Tool
137+
*.dotCover
138+
139+
# AxoCover is a Code Coverage Tool
140+
.axoCover/*
141+
!.axoCover/settings.json
142+
143+
# Visual Studio code coverage results
144+
*.coverage
145+
*.coveragexml
146+
147+
# NCrunch
148+
_NCrunch_*
149+
.*crunch*.local.xml
150+
nCrunchTemp_*
151+
152+
# MightyMoose
153+
*.mm.*
154+
AutoTest.Net/
155+
156+
# Web workbench (sass)
157+
.sass-cache/
158+
159+
# Installshield output folder
160+
[Ee]xpress/
161+
162+
# DocProject is a documentation generator add-in
163+
DocProject/buildhelp/
164+
DocProject/Help/*.HxT
165+
DocProject/Help/*.HxC
166+
DocProject/Help/*.hhc
167+
DocProject/Help/*.hhk
168+
DocProject/Help/*.hhp
169+
DocProject/Help/Html2
170+
DocProject/Help/html
171+
172+
# Click-Once directory
173+
publish/
174+
175+
# Publish Web Output
176+
*.[Pp]ublish.xml
177+
*.azurePubxml
178+
# Note: Comment the next line if you want to checkin your web deploy settings,
179+
# but database connection strings (with potential passwords) will be unencrypted
180+
*.pubxml
181+
*.publishproj
182+
183+
# Microsoft Azure Web App publish settings. Comment the next line if you want to
184+
# checkin your Azure Web App publish settings, but sensitive information contained
185+
# in these scripts will be unencrypted
186+
PublishScripts/
187+
188+
# NuGet Packages
189+
*.nupkg
190+
# NuGet Symbol Packages
191+
*.snupkg
192+
# The packages folder can be ignored because of Package Restore
193+
**/[Pp]ackages/*
194+
# except build/, which is used as an MSBuild target.
195+
!**/[Pp]ackages/build/
196+
# Uncomment if necessary however generally it will be regenerated when needed
197+
#!**/[Pp]ackages/repositories.config
198+
# NuGet v3's project.json files produces more ignorable files
199+
*.nuget.props
200+
*.nuget.targets
201+
202+
# Microsoft Azure Build Output
203+
csx/
204+
*.build.csdef
205+
206+
# Microsoft Azure Emulator
207+
ecf/
208+
rcf/
209+
210+
# Windows Store app package directories and files
211+
AppPackages/
212+
BundleArtifacts/
213+
Package.StoreAssociation.xml
214+
_pkginfo.txt
215+
*.appx
216+
*.appxbundle
217+
*.appxupload
218+
219+
# Visual Studio cache files
220+
# files ending in .cache can be ignored
221+
*.[Cc]ache
222+
# but keep track of directories ending in .cache
223+
!?*.[Cc]ache/
224+
225+
# Others
226+
ClientBin/
227+
~$*
228+
*~
229+
*.dbmdl
230+
*.dbproj.schemaview
231+
*.jfm
232+
*.pfx
233+
*.publishsettings
234+
orleans.codegen.cs
235+
236+
# Including strong name files can present a security risk
237+
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
238+
#*.snk
239+
240+
# Since there are multiple workflows, uncomment next line to ignore bower_components
241+
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
242+
#bower_components/
243+
244+
# RIA/Silverlight projects
245+
Generated_Code/
246+
247+
# Backup & report files from converting an old project file
248+
# to a newer Visual Studio version. Backup files are not needed,
249+
# because we have git ;-)
250+
_UpgradeReport_Files/
251+
Backup*/
252+
UpgradeLog*.XML
253+
UpgradeLog*.htm
254+
ServiceFabricBackup/
255+
*.rptproj.bak
256+
257+
# SQL Server files
258+
*.mdf
259+
*.ldf
260+
*.ndf
261+
262+
# Business Intelligence projects
263+
*.rdl.data
264+
*.bim.layout
265+
*.bim_*.settings
266+
*.rptproj.rsuser
267+
*- [Bb]ackup.rdl
268+
*- [Bb]ackup ([0-9]).rdl
269+
*- [Bb]ackup ([0-9][0-9]).rdl
270+
271+
# Microsoft Fakes
272+
FakesAssemblies/
273+
274+
# GhostDoc plugin setting file
275+
*.GhostDoc.xml
276+
277+
# Node.js Tools for Visual Studio
278+
.ntvs_analysis.dat
279+
node_modules/
280+
281+
# Visual Studio 6 build log
282+
*.plg
283+
284+
# Visual Studio 6 workspace options file
285+
*.opt
286+
287+
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
288+
*.vbw
289+
290+
# Visual Studio LightSwitch build output
291+
**/*.HTMLClient/GeneratedArtifacts
292+
**/*.DesktopClient/GeneratedArtifacts
293+
**/*.DesktopClient/ModelManifest.xml
294+
**/*.Server/GeneratedArtifacts
295+
**/*.Server/ModelManifest.xml
296+
_Pvt_Extensions
297+
298+
# Paket dependency manager
299+
.paket/paket.exe
300+
paket-files/
301+
302+
# FAKE - F# Make
303+
.fake/
304+
305+
# CodeRush personal settings
306+
.cr/personal
307+
308+
# Python Tools for Visual Studio (PTVS)
309+
__pycache__/
310+
*.pyc
311+
312+
# Cake - Uncomment if you are using it
313+
# tools/**
314+
# !tools/packages.config
315+
316+
# Tabs Studio
317+
*.tss
318+
319+
# Telerik's JustMock configuration file
320+
*.jmconfig
321+
322+
# BizTalk build output
323+
*.btp.cs
324+
*.btm.cs
325+
*.odx.cs
326+
*.xsd.cs
327+
328+
# OpenCover UI analysis results
329+
OpenCover/
330+
331+
# Azure Stream Analytics local run output
332+
ASALocalRun/
333+
334+
# MSBuild Binary and Structured Log
335+
*.binlog
336+
337+
# NVidia Nsight GPU debugger configuration file
338+
*.nvuser
339+
340+
# MFractors (Xamarin productivity tool) working folder
341+
.mfractor/
342+
343+
# Local History for Visual Studio
344+
.localhistory/
345+
346+
# BeatPulse healthcheck temp database
347+
healthchecksdb
348+
349+
# Backup folder for Package Reference Convert tool in Visual Studio 2017
350+
MigrationBackup/
351+
352+
# Ionide (cross platform F# VS Code tools) working folder
353+
.ionide/
354+
.DS_Store

‎Course.md

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Run tests manually
2+
3+
* Validate the environment
4+
* [ ] Run all tests (`Ctrl-U, L`)
5+
6+
# Run tests automatically
7+
8+
* Open InfiniTest menu (`Alt-U`)
9+
* [ ] Enable InfiniTest
10+
* [ ] Ensure **Risk/Progress** window is open and visible and out of the way.
11+
12+
# Read this:
13+
14+
## Scenario
15+
16+
We are looking at a large method that we don't understand, and we want to clean up. We are going to "follow our nose", leaning into the places we don't like and pulling out chunks and improving them.
17+
18+
## Starting Rules for today's refactorings
19+
20+
- Automated refactorings "only"
21+
- Commit after each refactoring
22+
- Every refactoring commit prefixed with `r - `
23+
- Rotate typist on commit
24+
25+
## Improvement Loop
26+
27+
1. Identify a smell
28+
2. Improve it
29+
3. Evaluate
30+
4. Commit (or revert)
31+
32+
# Do this
33+
34+
- [ ] ## Activity 1: Extract Paragraphs to methods
35+
36+
1. Identify a paragraph (a `case`)
37+
2. Extract a method to an Obvious Nonsense name
38+
3. Evaluate it at the caller (ignore the body)
39+
4. Fix or revert and try again
40+
5. Commit
41+
42+
- [ ] ## Activity 2: Move methods onto new classes
43+
44+
1. Pick a method
45+
2. Move into a better class
46+
3. Evaluate at caller
47+
4. Commit (or revert)
48+
49+
- [ ] ## Activity 3: Clean up the main method
50+
51+
1. Convert `switch` to `if`/`else`, commit
52+
2. Remove redundant `else` in method, commit
53+
3. Extract condition to a method with a Nonsense name, commit
54+
4. Move the method to the corresponding class, commit
55+
56+
- [ ] ## Activity 4: Remove duplication
57+
58+
1. Make similar things identical
59+
2. Surround each `if` with a block
60+
3. Apply Refactoring Combo: Provable Undo to make non-static
61+
4. Make each class non-static
62+
5. Extract local variables
63+
6. Extract interface x 1
64+
7. Apply interface x 3
65+
8. Use base type x 4
66+
9. Apply Refactoring Combo: Many-of-one (two, three, four)
67+
11. Extract list of scorers
68+
12. Extract apply scorers
69+
70+
# Resources
71+
72+
## Smell: bad names
73+
74+
1. Missing/Misleading -> (Obvious) Nonsense
75+
76+
2. Nonsense -> Honest (but incomplete)
77+
78+
3. Honest -> Honest-and-complete
79+
80+
4. Honest-and-Complete -> Does the right thing
81+
82+
5. Does the right thing -> Intent
83+
84+
6. Intent -> Domain Abstraction
85+
86+
## Refactoring Combo: Provable Undo
87+
88+
**Insight:** A proven-correct refactoring means that the resulting code is the same as the beginning code. Therefore undoing a proven-correct refactoring is also a proven-correct refactoring.
89+
90+
1. Verify that Git shows no changes
91+
2. Execute manual, unproven refactoring
92+
3. Execute automated refactoring to undo #1
93+
4. Save All
94+
5. Verify that Git shows no changes
95+
6. Undo (CTRL-Z) once
96+
7. Commit
97+
98+
## Refactoring Recipe: many-of-one
99+
100+
> This is not a proven-correct refactoring.
101+
102+
Given:
103+
104+
```c#
105+
SOMETYPE somevar = ...;
106+
// do something with somevar
107+
```
108+
109+
Becomes:
110+
111+
```c#
112+
foreach (SOMETYPE somevar in new SOMETYPE[]{ ... })
113+
{
114+
// do something with somevar
115+
}
116+
```
117+
118+
1. Add curly braces (`{}`) around the body
119+
2. Prefix with `foreach (`
120+
3. Replace `=` with `in new SOMETYPE[]{`
121+
4. Replace `;` with `})`
122+
123+
124+
## Homework
125+
126+
* Redo today’s coding exercises on your own computer
127+
128+
* Start from the code on the [`main` branch](https://github.com/LearnWithLlew/RefactoringToCleanerCode.net)
129+
* If you want to see the code we wrote together, check the [other branches](https://github.com/LearnWithLlew/RefactoringToCleanerCode.net/branches)
130+
* Pay attention to:
131+
* how often you're able to execute a single refactoring - more is better
132+
* how many times you are able to pull out a paragraph into a new method
133+
* Print out this sheet and keep it on your desk. Over the next week as you're doing your normal work:
134+
* note when you were able to improve the code with a single, committed refactoring
135+
* note when you extract a paragraph
136+
* Make a TODO list of code you wish was better but couldn't improve at this time
137+

‎Instructor checklist.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# 1 week before
2+
3+
- [ ] Set up machine
4+
- [ ] Customize toolbar with Refactor This button
5+
```
6+
Tools->Customize
7+
On toolbars tab:
8+
New
9+
Name = Refactoring to Cleanr Code
10+
On commands tab
11+
Toolbar = Refactoring to Cleaner Code
12+
Add Command
13+
Categories = Extensions
14+
Select Resharper_RefactorThis
15+
Drag new toolbar to the right
16+
```
17+
- [ ] Schedule Zoom meeting
18+
- [ ] Send email to attendees
19+
- [ ] With Zoom
20+
- [ ] With AnyDesk
21+
22+
# 1 day before
23+
24+
- [ ] Open Solution, build, run tests, turn off NCrunch
25+
- May need to add real NuGet feed (https://api.nuget.org/v3/index.json) and remove offline packages feed
26+
- [ ] Check keyboard shortcuts in Visual Studio
27+
- [ ] Ctrl-Shift-R
28+
- [ ] Ctrl-U, Ctrl-L
29+
- [ ] Get slides onto machine via Office 365
30+
- [ ] Make a branch
31+
- [ ] Enable `Show procedure line separators`
32+
- [ ] Ensure Typora installed
33+
34+
# 20 minutes before
35+
36+
- [ ] Launch Zoom
37+
- [ ] Make Jay a co-host
38+
- [ ] Launch AnyDesk
39+
- [ ] Sync slides with OneDrive
40+
- [ ] Open `Course.md` in Typora
41+
- [ ] Open Solution
42+
- [ ] Place MobTime in the corner
43+
- [ ] Arrange Visual Studio, Typora course.md, MobTime
44+
45+
# During
46+
47+
- [ ] Introduce ourselves and the course
48+
- [ ] Show slides
49+
- [ ] Get everyone on Anydesk
50+
- [ ] Set up mob rotation
51+
- [ ] Refactor
52+
- [ ] Homework
53+
- [ ] Guided reflections
54+
- [ ] Code Cleaners for Hire
55+
56+
# 1 hour after
57+
58+
- [ ] Send slides and repo and survey and Code Cleaners doc
59+
60+
# 1 week after
61+
62+
- [ ] Followup email
63+
64+
65+

‎LICENSE

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
Apache License
2+
Version 2.0, January 2004
3+
http://www.apache.org/licenses/
4+
5+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6+
7+
1. Definitions.
8+
9+
"License" shall mean the terms and conditions for use, reproduction,
10+
and distribution as defined by Sections 1 through 9 of this document.
11+
12+
"Licensor" shall mean the copyright owner or entity authorized by
13+
the copyright owner that is granting the License.
14+
15+
"Legal Entity" shall mean the union of the acting entity and all
16+
other entities that control, are controlled by, or are under common
17+
control with that entity. For the purposes of this definition,
18+
"control" means (i) the power, direct or indirect, to cause the
19+
direction or management of such entity, whether by contract or
20+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
21+
outstanding shares, or (iii) beneficial ownership of such entity.
22+
23+
"You" (or "Your") shall mean an individual or Legal Entity
24+
exercising permissions granted by this License.
25+
26+
"Source" form shall mean the preferred form for making modifications,
27+
including but not limited to software source code, documentation
28+
source, and configuration files.
29+
30+
"Object" form shall mean any form resulting from mechanical
31+
transformation or translation of a Source form, including but
32+
not limited to compiled object code, generated documentation,
33+
and conversions to other media types.
34+
35+
"Work" shall mean the work of authorship, whether in Source or
36+
Object form, made available under the License, as indicated by a
37+
copyright notice that is included in or attached to the work
38+
(an example is provided in the Appendix below).
39+
40+
"Derivative Works" shall mean any work, whether in Source or Object
41+
form, that is based on (or derived from) the Work and for which the
42+
editorial revisions, annotations, elaborations, or other modifications
43+
represent, as a whole, an original work of authorship. For the purposes
44+
of this License, Derivative Works shall not include works that remain
45+
separable from, or merely link (or bind by name) to the interfaces of,
46+
the Work and Derivative Works thereof.
47+
48+
"Contribution" shall mean any work of authorship, including
49+
the original version of the Work and any modifications or additions
50+
to that Work or Derivative Works thereof, that is intentionally
51+
submitted to Licensor for inclusion in the Work by the copyright owner
52+
or by an individual or Legal Entity authorized to submit on behalf of
53+
the copyright owner. For the purposes of this definition, "submitted"
54+
means any form of electronic, verbal, or written communication sent
55+
to the Licensor or its representatives, including but not limited to
56+
communication on electronic mailing lists, source code control systems,
57+
and issue tracking systems that are managed by, or on behalf of, the
58+
Licensor for the purpose of discussing and improving the Work, but
59+
excluding communication that is conspicuously marked or otherwise
60+
designated in writing by the copyright owner as "Not a Contribution."
61+
62+
"Contributor" shall mean Licensor and any individual or Legal Entity
63+
on behalf of whom a Contribution has been received by Licensor and
64+
subsequently incorporated within the Work.
65+
66+
2. Grant of Copyright License. Subject to the terms and conditions of
67+
this License, each Contributor hereby grants to You a perpetual,
68+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69+
copyright license to reproduce, prepare Derivative Works of,
70+
publicly display, publicly perform, sublicense, and distribute the
71+
Work and such Derivative Works in Source or Object form.
72+
73+
3. Grant of Patent License. Subject to the terms and conditions of
74+
this License, each Contributor hereby grants to You a perpetual,
75+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76+
(except as stated in this section) patent license to make, have made,
77+
use, offer to sell, sell, import, and otherwise transfer the Work,
78+
where such license applies only to those patent claims licensable
79+
by such Contributor that are necessarily infringed by their
80+
Contribution(s) alone or by combination of their Contribution(s)
81+
with the Work to which such Contribution(s) was submitted. If You
82+
institute patent litigation against any entity (including a
83+
cross-claim or counterclaim in a lawsuit) alleging that the Work
84+
or a Contribution incorporated within the Work constitutes direct
85+
or contributory patent infringement, then any patent licenses
86+
granted to You under this License for that Work shall terminate
87+
as of the date such litigation is filed.
88+
89+
4. Redistribution. You may reproduce and distribute copies of the
90+
Work or Derivative Works thereof in any medium, with or without
91+
modifications, and in Source or Object form, provided that You
92+
meet the following conditions:
93+
94+
(a) You must give any other recipients of the Work or
95+
Derivative Works a copy of this License; and
96+
97+
(b) You must cause any modified files to carry prominent notices
98+
stating that You changed the files; and
99+
100+
(c) You must retain, in the Source form of any Derivative Works
101+
that You distribute, all copyright, patent, trademark, and
102+
attribution notices from the Source form of the Work,
103+
excluding those notices that do not pertain to any part of
104+
the Derivative Works; and
105+
106+
(d) If the Work includes a "NOTICE" text file as part of its
107+
distribution, then any Derivative Works that You distribute must
108+
include a readable copy of the attribution notices contained
109+
within such NOTICE file, excluding those notices that do not
110+
pertain to any part of the Derivative Works, in at least one
111+
of the following places: within a NOTICE text file distributed
112+
as part of the Derivative Works; within the Source form or
113+
documentation, if provided along with the Derivative Works; or,
114+
within a display generated by the Derivative Works, if and
115+
wherever such third-party notices normally appear. The contents
116+
of the NOTICE file are for informational purposes only and
117+
do not modify the License. You may add Your own attribution
118+
notices within Derivative Works that You distribute, alongside
119+
or as an addendum to the NOTICE text from the Work, provided
120+
that such additional attribution notices cannot be construed
121+
as modifying the License.
122+
123+
You may add Your own copyright statement to Your modifications and
124+
may provide additional or different license terms and conditions
125+
for use, reproduction, or distribution of Your modifications, or
126+
for any such Derivative Works as a whole, provided Your use,
127+
reproduction, and distribution of the Work otherwise complies with
128+
the conditions stated in this License.
129+
130+
5. Submission of Contributions. Unless You explicitly state otherwise,
131+
any Contribution intentionally submitted for inclusion in the Work
132+
by You to the Licensor shall be under the terms and conditions of
133+
this License, without any additional terms or conditions.
134+
Notwithstanding the above, nothing herein shall supersede or modify
135+
the terms of any separate license agreement you may have executed
136+
with Licensor regarding such Contributions.
137+
138+
6. Trademarks. This License does not grant permission to use the trade
139+
names, trademarks, service marks, or product names of the Licensor,
140+
except as required for reasonable and customary use in describing the
141+
origin of the Work and reproducing the content of the NOTICE file.
142+
143+
7. Disclaimer of Warranty. Unless required by applicable law or
144+
agreed to in writing, Licensor provides the Work (and each
145+
Contributor provides its Contributions) on an "AS IS" BASIS,
146+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147+
implied, including, without limitation, any warranties or conditions
148+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149+
PARTICULAR PURPOSE. You are solely responsible for determining the
150+
appropriateness of using or redistributing the Work and assume any
151+
risks associated with Your exercise of permissions under this License.
152+
153+
8. Limitation of Liability. In no event and under no legal theory,
154+
whether in tort (including negligence), contract, or otherwise,
155+
unless required by applicable law (such as deliberate and grossly
156+
negligent acts) or agreed to in writing, shall any Contributor be
157+
liable to You for damages, including any direct, indirect, special,
158+
incidental, or consequential damages of any character arising as a
159+
result of this License or out of the use or inability to use the
160+
Work (including but not limited to damages for loss of goodwill,
161+
work stoppage, computer failure or malfunction, or any and all
162+
other commercial damages or losses), even if such Contributor
163+
has been advised of the possibility of such damages.
164+
165+
9. Accepting Warranty or Additional Liability. While redistributing
166+
the Work or Derivative Works thereof, You may choose to offer,
167+
and charge a fee for, acceptance of support, warranty, indemnity,
168+
or other liability obligations and/or rights consistent with this
169+
License. However, in accepting such obligations, You may act only
170+
on Your own behalf and on Your sole responsibility, not on behalf
171+
of any other Contributor, and only if You agree to indemnify,
172+
defend, and hold each Contributor harmless for any liability
173+
incurred by, or claims asserted against, such Contributor by reason
174+
of your accepting any such warranty or additional liability.
175+
176+
END OF TERMS AND CONDITIONS
177+
178+
APPENDIX: How to apply the Apache License to your work.
179+
180+
To apply the Apache License to your work, attach the following
181+
boilerplate notice, with the fields enclosed by brackets "[]"
182+
replaced with your own identifying information. (Don't include
183+
the brackets!) The text should be enclosed in the appropriate
184+
comment syntax for the file format. We also recommend that a
185+
file or class name and description of purpose be included on the
186+
same "printed page" as the copyright notice for easier
187+
identification within third-party archives.
188+
189+
Copyright [yyyy] [name of copyright owner]
190+
191+
Licensed under the Apache License, Version 2.0 (the "License");
192+
you may not use this file except in compliance with the License.
193+
You may obtain a copy of the License at
194+
195+
http://www.apache.org/licenses/LICENSE-2.0
196+
197+
Unless required by applicable law or agreed to in writing, software
198+
distributed under the License is distributed on an "AS IS" BASIS,
199+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200+
See the License for the specific language governing permissions and
201+
limitations under the License.

‎README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
![Java](https://github.com/LearnWithLlew/RefactoringToCleanerCode.java/workflows/Runtests/badge.svg)
2+
3+
# Refactoring to Cleaner Code by Jay Bazuzi and Llewellyn Falco
4+
5+
You can grab the slides here: https://github.com/LearnWithLlew/RefactoringToCleanerCode.Slides
6+
7+
Remember to print out the [homework](https://github.com/LearnWithLlew/RefactoringToCleanerCode.Slides/raw/main/Homework%20Printouts.pdf).
8+
9+
# Setting up a machine
10+
11+
If you have a machine for Java, you can simply clone, open the solution, and run the tests.
12+
13+
If you don't, you can see exactly how we set up a machine from scratch by opening the PowerShell script [machine-setup.ps1](machine-setup.ps1). Please note that this script calls other scripts via the `iwr` (`Invoke-WebRequest`) PowerShell command. You can run this and it will install everything you need on a completely clean machine, or you can pick and choose the pieces you want to install.
14+
15+
# About the Course
16+
17+
If you want to sign up for one of our weekend courses, see our [EventBrite page](https://www.eventbrite.com/e/workshop-refactoring-to-cleaner-code-tickets-131743126237).
18+
19+
You can follow us on Twitter at [@JayBazuzi](https://twitter.com/JayBazuzi) and [@LlewellynFalco](https://twitter.com/LlewellynFalco).
20+
21+
Or you can [hire us to clean your code](https://github.com/LearnWithLlew/RefactoringToCleanerCode.Slides/raw/main/marketing/CodeCleanerForHire.pdf).
22+
23+
# F.A.Q
24+
25+
**Q:**
26+
**A:**

‎machine-setup.ps1

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# To run this script directly, open PowerShell and run this command:
2+
# PS> Invoke-WebRequest -UseBasicParsing https://raw.githubusercontent.com/LearnWithLlew/RefactoringToCleanerCode.net/master/machine-setup.ps1 | Invoke-Expression
3+
4+
#Requires -RunAsAdministrator
5+
6+
iwr -useb https://raw.githubusercontent.com/JayBazuzi/machine-setup/main/windows.ps1 | iex
7+
iwr -useb https://raw.githubusercontent.com/JayBazuzi/machine-setup/main/java-intellij.ps1 | iex
8+
9+
cinst typora
10+
11+
12+
mkdir C:\Source\
13+
pushd C:\Source\
14+
15+
Set-Alias github $env:LOCALAPPDATA\GitHubDesktop\bin\github.bat
16+
& "C:\Program Files\Git\cmd\git.exe" clone https://github.com/LearnWithLlew/RefactoringToCleanerCode.slides.git
17+
pushd RefactoringToCleanerCode.Slides\
18+
github .
19+
Expand-Archive fonts\playfair-display.zip fonts\install-me
20+
Expand-Archive fonts\pt-serif.zip fonts\install-me
21+
Invoke-Item fonts\install-me
22+
popd
23+
24+
25+
& "C:\Program Files\Git\cmd\git.exe" clone https://github.com/LearnWithLlew/RefactoringToCleanerCode.java.git
26+
pushd RefactoringToCleanerCode.java
27+
github .
28+
29+
# force prompt for credentials
30+
& 'C:\Program Files\Git\cmd\git.exe' push
31+
popd
32+
33+
popd

‎pom.xml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
4+
<groupId>org.learnwithllew</groupId>
5+
<artifactId>BetterGames</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
8+
<properties>
9+
<maven.compiler.source>13</maven.compiler.source>
10+
<maven.compiler.target>13</maven.compiler.target>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
</properties>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.junit.jupiter</groupId>
17+
<artifactId>junit-jupiter</artifactId>
18+
<version>5.6.2</version>
19+
<scope>test</scope>
20+
</dependency>
21+
<dependency>
22+
<groupId>com.approvaltests</groupId>
23+
<artifactId>approvaltests</artifactId>
24+
<version>11.6.0</version>
25+
</dependency>
26+
</dependencies>
27+
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-compiler-plugin</artifactId>
33+
<version>3.8.1</version>
34+
</plugin>
35+
<plugin>
36+
<artifactId>maven-surefire-plugin</artifactId>
37+
<version>2.22.2</version>
38+
</plugin>
39+
<plugin>
40+
<groupId>org.apache.maven.plugins</groupId>
41+
<artifactId>maven-jar-plugin</artifactId>
42+
<version>3.2.0</version>
43+
<configuration>
44+
<archive>
45+
<manifest>
46+
<mainClass>com.first.pkg.Application</mainClass>
47+
</manifest>
48+
</archive>
49+
</configuration>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
</project>
+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package bettergames;
2+
3+
public class BigDiceGame
4+
{
5+
public static int calculateScore(ScoringType st, int die1, int die2, int d3, int dieFour, int fifthDie)
6+
{
7+
final int bigScore = 50;
8+
switch (st)
9+
{
10+
case Pair:
11+
{
12+
final int value = 2;
13+
int[] tallies1;
14+
tallies1 = new int[6];
15+
tallies1[die1 - 1]++;
16+
tallies1[die2 - 1]++;
17+
tallies1[d3 - 1]++;
18+
tallies1[dieFour - 1]++;
19+
tallies1[fifthDie - 1]++;
20+
for (var i = 6 - 1; i >= 0; i--)
21+
{
22+
if (tallies1[i] >= value)
23+
{
24+
return (i + 1) * value;
25+
}
26+
}
27+
28+
return 0;
29+
}
30+
31+
case TwoPair:
32+
{
33+
var counts1 = new int[6];
34+
counts1[die1 - 1]++;
35+
counts1[die2 - 1]++;
36+
counts1[d3 - 1]++;
37+
counts1[dieFour - 1]++;
38+
counts1[fifthDie - 1]++;
39+
var n = 0;
40+
var score = 0;
41+
for (var i = 0; i < 6; i += 1)
42+
{
43+
if (counts1[6 - i - 1] >= 2)
44+
{
45+
n++;
46+
score += 6 - i;
47+
}
48+
}
49+
50+
if (n == 2)
51+
{
52+
return score * 2;
53+
}
54+
55+
return 0;
56+
}
57+
58+
case FullHouse:
59+
{
60+
int[] tallies;
61+
var _2 = false;
62+
int i;
63+
var _2_at = 0;
64+
var _3 = false;
65+
var _3_at = 0;
66+
67+
tallies = new int[6];
68+
tallies[die1 - 1] += 1;
69+
tallies[die2 - 1] += 1;
70+
tallies[d3 - 1] += 1;
71+
tallies[dieFour - 1] += 1;
72+
tallies[fifthDie - 1] += 1;
73+
74+
for (i = 0; i != 6; i += 1)
75+
{
76+
if (tallies[i] == 2)
77+
{
78+
_2 = true;
79+
_2_at = i + 1;
80+
}
81+
}
82+
83+
for (i = 0; i != 6; i += 1)
84+
{
85+
if (tallies[i] == 3)
86+
{
87+
_3 = true;
88+
_3_at = i + 1;
89+
}
90+
}
91+
92+
if (_2 && _3)
93+
{
94+
return _2_at * 2 + _3_at * 3;
95+
}
96+
97+
return 0;
98+
}
99+
100+
case FiveOfAKind:
101+
{
102+
int[] dice1 = {die1, die2, d3, dieFour, fifthDie};
103+
var counts2 = new int[6];
104+
for (var die : dice1)
105+
{
106+
counts2[die - 1]++;
107+
}
108+
109+
for (var i1 = 0; i1 != 6; i1++)
110+
{
111+
if (counts2[i1] == 5)
112+
{
113+
return bigScore;
114+
}
115+
}
116+
117+
return 0;
118+
}
119+
}
120+
121+
return 0;
122+
}
123+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package bettergames;
2+
3+
public enum ScoringType {
4+
Pair,
5+
TwoPair,
6+
FullHouse,
7+
FiveOfAKind
8+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package bettergames;
2+
3+
import org.approvaltests.combinations.CombinationApprovals;
4+
import org.junit.jupiter.api.Test;
5+
6+
public class GameTest {
7+
8+
@Test
9+
public void pinEverything() {
10+
var dice = new Integer[]{1, 2, 3, 4, 5, 6};
11+
var scoringTypes = ScoringType.values();
12+
13+
CombinationApprovals.verifyAllCombinations(
14+
BigDiceGame::calculateScore,
15+
scoringTypes, dice, dice, dice, dice, dice
16+
);
17+
}
18+
}

0 commit comments

Comments
 (0)
Please sign in to comment.