This summer I was working on translating a project with a dozen Python classes into Javascript ES6 classes. The following are “notes to myself” about the substitutions that can be made automatically in order to speed up the translation process.
replace all (this –> with that) |
---|
def __init__ --> constructor |
def --> |
(self): --> (){ |
(self, --> ( |
): --> ){ |
self. --> this. |
# --> //# |
else: --> }else{ |
print( --> console.log( |
int( --> Math.floor( |
str( --> (""+ |
True --> true |
False --> false |
None --> null |
and not --> && ! |
if not --> if (! |
while true: --> while (true){ |
The following substitutions need to be made manually (one at a time).
find and replace manually |
---|
and --> && |
result = --> let result = |
temp = --> let temp = |
.append --> .push |
len(foo) |
for i in range( |
for each in --> for (let each of |
while |
.insert(0,"foo") --> .splice(0,0,"foo") |
a in b --> b.includes(a) |
@staticmethod \n def --> static |
@classmethod \n def --> static |
.sort(key=lambda x: x.getGrade(), reverse=False) --> .sort(function(a, b){return a.getGrade() - b.getGrade()}) |
.sort(key=lambda x: x.getGrade(), reverse=True) --> .sort(function(a, b){return b.getGrade() - a.getGrade()}) |
Notes to myself about how to setup a Java repl to work with automatic JUnit tests.
First, add junit:junit from Packages
Next, redirect the “Run” button:
Create a new .replit file and add run = "bash run.sh"
Create a new shell script run.sh and add the following lines…
javac -classpath .:/run_dir/junit-4.12.jar:/run_dir/hamcrest-core-1.3.jar:/run_dir/json-simple-1.1.1.jar -d . *.java
java -classpath .:/run_dir/junit-4.12.jar:/run_dir/hamcrest-core-1.3.jar:/run_dir/json-simple-1.1.1.jar ShoesTester
# javac *.java
# java ShoesTester
Here is a sample ShoesTester file:
import org.junit.*;
import org.junit.runner.*;
import static org.junit.Assert.*;
public class ShoesTester {
public int add3(int n) {
return n+3;
}
@Test
public void test_add3() {
assertEquals(8,add3(5));
}
@Test
public void trivial_test(){
assertTrue(5 == 2+3);
assertFalse(7 != 14/2);
}
public static void main(String[] args) {
System.out.println("Hello tests!");
org.junit.runner.JUnitCore.main("ShoesTester");
}
}
Here is the TEDIOUS process to follow to convert an old Quiz Question Bank to a new Quiz Item Bank in Canvas:
RECENT POSTS