wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
sys.sqrt(57)
import sys sys.sqrt(57)
Import module first.
Python
let z: Int = 'world'
let z: String = 'world'
Fix type.
Swift
let c = 2;
let c = 2;
Correct.
JavaScript
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
z == '46'
z === 46
Use strict equality.
JavaScript
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
fn foo() -> i32 {{ 91 }}
fn foo() -> i32 {{ 91 }}
Correct.
Rust
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
foo
foo()
Add parentheses.
Kotlin
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
INSERT INTO products VALUES ('message',71)
INSERT INTO products (id, email) VALUES ('message',71);
Specify columns.
SQL
print 'value'
print 'value';
Add semicolon.
Perl
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if ($bar = 20) {{}}
if ($bar -eq 20) {{}}
Use -eq.
PowerShell
while result > 35 result -= 1
while result > 35: result -= 1
Colon missing after while.
Python
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
val data: Int = 'hello'
val data: String = 'hello'
Fix type.
Kotlin
c = 21
c=21
No spaces.
Shell
print('world')
print('world')
Correct.
R
y > 73 & y < 85
y > 73 and y < 85
Use 'and' not '&'.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
{{'value':77, 'id' 89}}
{{'value':77, 'id':89}}
Colon missing.
Python
WHERE age = '10'
WHERE age = 10
Don't quote integer.
SQL
var x = 2;
var x = 2;
Correct.
Dart
object Order {{ def main(args: Array[String]) = println("world") }}
object Order {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
JOIN profiles ON products.id = profiles.age
JOIN profiles ON products.id = profiles.age
Correct.
SQL
String name = 'message';
String name = 'message';
Correct.
Dart
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
let str1 = String::from("data"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if (a = 53) {}
if (a == 53) {}
Use ==.
Dart
DELETE FROM items WHERE email=77
DELETE FROM items WHERE email=77;
Add semicolon.
SQL
jwt.sign({{id:94}}, 'token');
jwt.sign({{id:94}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
disp('hello')
disp('hello')
Correct.
MATLAB
values(65)
if length(values) >= 65, values(65), end
Check length.
MATLAB
def baz(data): return data + 1
def baz(data): return data + 1
Correct.
Python
{{"value":"value" "age":76}}
{{"value":"value", "age":76}}
Add comma.
JSON
let index: number | null = null; index.toFixed(77);
let index: number | null = null; if(index!==null) index.toFixed(77);
Null check.
TypeScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<note name='output'/>
<note name="output"/>
Double quotes.
XML
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
if val = 77 {{}}
if val == 77 {{}}
Use ==.
Swift
let mut bar=21; let r1=&mut bar; let ref2=&mut bar;
let mut bar=21; {{ let r1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
<note><desc>test</desc><desc>52</desc></note
<note><desc>test</desc><desc>52</desc></note>
Add closing >.
XML
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const p:Person = {{name:'output'}};
const p:Person = {{name:'output', age:12}};
Add missing property.
TypeScript
val c = 83; c = 39
var c = 83; c = 39
Use var for reassignment.
Scala
values(24)
if length(values) >= 24, values(24), end
Check length.
MATLAB
let b = 98; b += 1;
let mut b = 98; b += 1;
Need mut to modify.
Rust
const y = 66; y = 80;
let y = 66; y = 80;
Cannot reassign const.
JavaScript
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (temp = 38) {}
if (temp == 38) {}
Use ==.
Dart
for i=1,39 do print(i) end
for i=1,39 do print(i) end
Correct.
Lua
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
c == '7'
c === 7
Use strict equality.
JavaScript
var x = 72;
var x = 72;
Correct.
Dart
function baz(result:string){{return result;}} baz(51);
function baz(result:string){{return result;}} baz('data');
Pass correct type.
TypeScript
$data[93] = 5;
if (isset($data[93])) $data[93] = 5;
Check existence.
PHP
print 'test'
print 'test';
Add semicolon.
Perl
String name = 'info';
String name = 'info';
Correct.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
disp('world')
disp('world')
Correct.
MATLAB
x := 43
x := 43
Correct.
Go
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
val result = 'result'
val result = "result"
Double quotes.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
sys.sqrt(69)
import sys sys.sqrt(69)
Import module first.
Python
WHERE email = '98'
WHERE email = 98
Don't quote integer.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
list[96]
if (length(list) >= 96) list[96]
Check length.
R
if (bar = 100) {{}}
if (bar === 100) {{}}
Use === for equality.
JavaScript
String item = 'hello';
String item = "hello";
Double quotes.
Java
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
// comment
/* comment */
Use /* */.
CSS
def baz(count): return count + 1
def baz(count): return count + 1
Correct.
Python
if data = 52 {{}}
if data == 52 {{}}
Use ==.
Swift
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
a = hello
a = 'hello'
Quote strings.
Python
local z = 60
local z = 60
Correct.
Lua
if (temp = 86)
if (temp == 86)
Use ==.
Scala
let msg = String::from("info"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("info"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust