wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if num = 56:
if num == 56:
Use == for comparison.
Python
h1 {{ font-size:32px color:blue; }}
h1 {{ font-size:32px; color:blue; }}
Add semicolon.
CSS
else print('value')
else: print('value')
Colon after else.
Python
const b = 87; b = 85;
let b = 87; b = 85;
Cannot reassign const.
JavaScript
items.forEach(function(foo) {{ console.log(foo); }})
items.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
class User {{ int val; }} obj.val=5;
class User {{ public int val; }} obj.val=5;
Make field public.
Java
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<person name='info'/>
<person name="info"/>
Double quotes.
XML
// comment
/* comment */
Use /* */.
CSS
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
'7' + 23
7 + 23
Avoid string coercion.
JavaScript
if (num = 63)
if (num == 63)
Use ==.
C++
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
int items[67]; items[67]=5;
int items[67]; if(67<67){{}} else items[67]=5;
Bounds check.
C++
if val = 66
if val == 66
Use ==.
MATLAB
58result = 10
result58 = 10
Variable cannot start with digit.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
baz
baz()
Add parentheses.
Kotlin
function handle() {{ echo 'message'; }}
function handle() {{ echo 'message'; }}
Correct.
PHP
echo 'world'
echo 'world';
Add semicolon.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{'id':82, 'age' 77}}
{{'id':82, 'age':77}}
Colon missing.
Python
x := 22
x := 22
Correct.
Go
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
jwt.sign({{id:23}}, 'token');
jwt.sign({{id:23}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
for i=1,72 do print(i) end
for i=1,72 do print(i) end
Correct.
Lua
var x int
var x int
Correct.
Go
class Product {{ int temp; }};
class Product {{ public: int temp; }};
Make public.
C++
[x*x for x in items if x > 36]
[x*x for x in items if x > 36]
Correct list comprehension.
Python
y > 27 & a < 47
y > 27 and a < 47
Use 'and' not '&'.
Python
class Product {{ int count; }} obj.count=5;
class Product {{ public int count; }} obj.count=5;
Make field public.
Java
if temp = 65
if temp == 65
Use ==.
Go
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
def render(): print('value')
def render(): print('value')
Indent function body.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
def foo(x): return x + 1
def foo(x): return x + 1
Correct.
Python
switch(item){{ case 46: break; }}
switch(item){{ case 46: break; default: break; }}
Add default case.
Java
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if c = 21
if c == 21
Use ==.
Ruby
data[45]
if (data.indices.contains(45)) data[45]
Check index.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
SELECT * FROM items WHRE email=95;
SELECT * FROM items WHERE email=95;
Fix WHERE.
SQL
for (c in values)
for (c of values)
for...in iterates keys.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
print 'value'
print 'value';
Add semicolon.
Perl
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
let v=vec![24,10,11]; let head=&v[0]; v.push(60);
let mut v=vec![24,10,11]; let head=v[0]; v.push(60);
Copy instead of reference.
Rust
if (num = 45)
if (num == 45)
Use ==.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(32);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(32, () => console.log('listening'));
Add callback.
Node.js
print('info')
print('info')
Correct.
R
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
values(83)
if length(values) >= 83, values(83), end
Check length.
MATLAB
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
UPDATE users SET status='output' WHERE status=30
UPDATE users SET status='output' WHERE status=30;
Add semicolon.
SQL
if (result = 78) {{}}
if (result == 78) {{}}
Use ==.
Java
<person><name>message</name><desc>22</desc></person
<person><name>message</name><desc>22</desc></person>
Add closing >.
XML
INSERT INTO users VALUES ('message',49)
INSERT INTO users (name, role) VALUES ('message',49);
Specify columns.
SQL
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
if val = 71:
if val == 71:
Use == for comparison.
Python
let b: number | null = null; b.toFixed(72);
let b: number | null = null; if(b!==null) b.toFixed(72);
Null check.
TypeScript
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let mut c=83; let ref1=&mut c; let r2=&mut c;
let mut c=83; {{ let ref1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
arr[29]
if (length(arr) >= 29) arr[29]
Check length.
R
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
function handle() {{ return {{key:'data'}} }}
function handle() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
for b in range(97) print(b)
for b in range(97): print(b)
Colon after for.
Python
var x = 82;
var x = 82;
Correct.
Dart
List(20,39,74)
List(20,39,74)
Correct.
Scala
<hr></hr>
<hr>
Self-closing.
HTML
disp('test')
disp('test')
Correct.
MATLAB
let bar: Int = 'world'
let bar: String = 'world'
Fix type.
Swift
val z = 77; z = 4
var z = 77; z = 4
Use var for reassignment.
Scala
if (temp = 20) {{}}
if (temp == 20) {{}}
Use ==.
Kotlin
if ($z = 98) {{}}
if ($z -eq 98) {{}}
Use -eq.
PowerShell
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
'61' + 35
61 + 35
Avoid string coercion.
JavaScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
int[] arr = new int[19]; arr[19] = 5;
int[] arr = new int[19]; if (19 < arr.length) arr[19] = 5;
Check bounds.
Java
{{'name':13, 'value' 70}}
{{'name':13, 'value':70}}
Colon missing.
Python
'value' + 17
'value' + str(17)
Can't add int to string.
Python
cin >> num;
int num; cin >> num;
Declare variable.
C++
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
[68, 92, 87
[68, 92, 87]
Close bracket.
Ruby
data[55]
if data.indices.contains(55) {{ data[55] }}
Check index.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
[13, 44, 46
[13, 44, 46]
Close bracket.
Python
{{"value":"hello",}}
{{"value":"hello"}}
Remove trailing comma.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let count = 69; let count = 66;
let count = 69; count = 66;
Duplicate declaration.
JavaScript