Skip to content

Commit

Permalink
Merge pull request #102 from WildMeOrg/table-and-code-styles
Browse files Browse the repository at this point in the history
set table and code types
  • Loading branch information
goddesswarship authored Dec 12, 2024
2 parents 8cbdf54 + e3d0b0b commit 6e4f3c9
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 67 deletions.
54 changes: 31 additions & 23 deletions docs/contribute/code-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ If you are updating a translation for general use, do your PR against the `main`

Instead of:

```
```{code-block} java
ArrayList encounters = new ArrayList<Encounter>();
...
public int getMax(ArrayList<int> numbers) {
```

Try:

```
```{code-block} java
List encounters = new ArrayList<Encounter>();
...
public int getMax(Collection<int> numbers) {
Expand All @@ -97,24 +97,28 @@ Related: when writing utility methods, making the input type as abstract as poss

Instead of:

```
List<MarkedIndividual> uniqueIndividuals = new ArrayList<MarkedIndividual>();
for(Encounter currentEncounter: encounters){
MarkedIndividual currentInd = enc.getIndividual();
if !(uniqueIndividuals.contains(currentInd) {
uniqueIndividuals.add(currentInd);
doStuff();
```{code-block} java
List<MarkedIndividual> uniqueIndividuals = new ArrayList<MarkedIndividual>();
for(Encounter currentEncounter: encounters){
MarkedIndividual currentInd = enc.getIndividual();
if !(uniqueIndividuals.contains(currentInd)) {
uniqueIndividuals.add(currentInd);
doStuff();
}
}
```
Try:

```
```{code-block} java
Set<MarkedIndividual> uniqueIndividuals = new HashSet<MarkedIndividual>();
for(Encounter currentEncounter: encounters){
MarkedIndividual currentInd = enc.getIndividual();
if !(uniqueIndividuals.contains(currentInd) {
uniqueIndividuals.add(currentInd);
doStuff();
for(Encounter currentEncounter: encounters){
MarkedIndividual currentInd = enc.getIndividual();
if !(uniqueIndividuals.contains(currentInd)) {
uniqueIndividuals.add(currentInd);
doStuff();
}
}
```

The reason is a little deep in the data types. Sets are defined as unordered collections of unique elements; and Lists/arrays are ordered collections with no bearing on element-uniqueness. If the order of a collection doesn’t matter and you’re just checking membership, you’ll have faster runtime using a Set.
Expand All @@ -125,17 +129,19 @@ Sets implement contains, add, and remove methods much faster than lists [contain

Instead of:

```
```{code-block} java
for (int i=0; i<encounters.length(); i++) {
Encounter enc = encounters.get(i)
doStuff();
}
```

try:

```
```{code-block} java
for (Encounter enc: encounters) {
doStuff();
}
```

Note that in both cases you might want to check if `encounters == null` if relevant, but you rarely need to check if `encounters.length()>0` because the for-loops take care of that.
Expand All @@ -147,16 +153,18 @@ Conversely, if you want access to the `i` variable for logging or otherwise, the

Instead of:

```
if (str!=Null && !str.equals("")) {
doStuff();
```{code-block} java
if (str!=Null && !str.equals("")) {
doStuff();
}
```

Try:

```
if (Util.stringExists(str)) {
doStuff();
```{code-block} java
if (Util.stringExists(str)) {
doStuff();
}
```

This method also checks for the strings “none” and “unknown” which have given us trouble in displays in the past.
Expand Down
2 changes: 1 addition & 1 deletion docs/contribute/dev-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ You need the following installed on your system:
### Deploy directory setup
1. Create your **deploy directory**, matching the value of `WILDBOOK_BASE_DIR` in the .env file. The default is `~/wildbook-dev/`)
1. Create the necessary subdirectories
```
```{code-block}
wildbook-dev
|--logs
|--webapps
Expand Down
2 changes: 1 addition & 1 deletion docs/contribute/pr-workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To start, you will need to be signed in to your GitHub account, have admin acces
1. In your terminal, enter the command `git clone https://github.com/USERNAME/Wildbook.git`
1. Once the Wildbook directory becomes available in your working directory, move to it with the command `cd Wildbook`
1. Add a reference to the original repo, denoting it as the upstream repo.
```
```{code-block}
git remote add upstream https://github.com/WildMeOrg/Wildbook
git fetch upstream
```
Expand Down
Loading

0 comments on commit 6e4f3c9

Please sign in to comment.