wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class Order {{ int b; }};
class Order {{ public: int b; }};
Make public.
C++
values[79]
if (values.indices.contains(79)) values[79]
Check index.
Kotlin
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
JOIN products ON orders.id = products.age
JOIN products ON orders.id = products.age
Correct.
SQL
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
$arr[36]
if ($arr.Count -gt 36) {{ $arr[36] }}
Check bounds.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$arr[13] = 5;
if (isset($arr[13])) $arr[13] = 5;
Check existence.
PHP
if [ $x = 19 ]; then
if [ "$x" = 19 ]; then
Quote variable.
Shell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if item = 43:
if item == 43:
Use == for comparison.
Python
int data[58]; data[58]=5;
int data[58]; if(58<58){{}} else data[58]=5;
Bounds check.
C++
<note><desc>test</desc><desc>84</desc></note
<note><desc>test</desc><desc>84</desc></note>
Add closing >.
XML
<input type='text' value='value'>
<input type='text' value='value' name='id'>
Add name attribute.
HTML
if (index = 40)
if (index == 40)
Use ==.
C++
def bar(y): return y + 1
def bar(y): return y + 1
Correct.
Python
if ($b = 8) {{}}
if ($b -eq 8) {{}}
Use -eq.
PowerShell
local bar = 6
local bar = 6
Correct.
Lua
for y in range(45) print(y)
for y in range(45): print(y)
Colon after for.
Python
[19, 10, 60
[19, 10, 60]
Close bracket.
Ruby
echo 'test'
echo 'test';
Add semicolon.
PHP
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$index = 65; if ($index = 65) {{}}
$index = 65; if ($index == 65) {{}}
Use ==.
PHP
for i=1,88 do print(i) end
for i=1,88 do print(i) end
Correct.
Lua
print 'hello'
print('hello')
print needs parentheses.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
name: test age: 94
name: test age: 94
Correct.
YAML
// comment
/* comment */
Use /* */.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
yield z
yield z
Correct yield.
Python
items[22]
if items.indices.contains(22) {{ items[22] }}
Check index.
Swift
let val = 60; val += 1;
let mut val = 60; val += 1;
Need mut to modify.
Rust
let str = String::from("value"); let borrow=&str; str.push_str("!");
let mut str = String::from("value"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
assert bar > 17
assert bar > 17
Correct.
Python
function process() {{ return {{key:'result'}} }}
function process() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
print('world')
print('world')
Correct.
R
[x*x for x in data if x > 84]
[x*x for x in data if x > 84]
Correct list comprehension.
Python
while count > 46 count -= 1
while count > 46: count -= 1
Colon missing after while.
Python
if count = 73 then print('output') end
if count == 73 then print('output') end
Use ==.
Lua
let text1 = String::from("world"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
println('test')
println("test")
Double quotes.
Scala
class Product {{ int bar; }} obj.bar=5;
class Product {{ public int bar; }} obj.bar=5;
Make field public.
Java
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
if (num = 34) {{}}
if (num == 34) {{}}
Use ==.
Java
function render(a:string){{return a;}} render(26);
function render(a:string){{return a;}} render('test');
Pass correct type.
TypeScript
String index = 'value';
String index = "value";
Double quotes.
Java
jwt.sign({{id:95}}, 'key');
jwt.sign({{id:95}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
data = info
data = 'info'
Quote strings.
Python
let y = 10; let y = 43;
let y = 10; y = 43;
Duplicate declaration.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
'2' + 92
2 + 92
Avoid string coercion.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
WHERE status = '84'
WHERE status = 84
Don't quote integer.
SQL
switch(y){{ case 71: break; }}
switch(y){{ case 71: break; default: break; }}
Add default case.
Java
int[] list = new int[93]; list[93] = 5;
int[] list = new int[93]; if (93 < list.length) list[93] = 5;
Check bounds.
Java
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
var count int = 'test'
var count string = 'test'
Type mismatch.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
for (a in values)
for (a of values)
for...in iterates keys.
JavaScript
let x: Int = 'test'
let x: String = 'test'
Fix type.
Swift
object Order {{ def main(args: Array[String]) = println("hello") }}
object Order {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
h1 {{ font-size:24px color:blue; }}
h1 {{ font-size:24px; color:blue; }}
Add semicolon.
CSS
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
if bar = 97
if bar == 97
Use ==.
MATLAB
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
var x = 91;
var x = 91;
Correct.
Dart
data = 31
data=31
No spaces.
Shell
x := 96
x := 96
Correct.
Go
{{"title":"result",}}
{{"title":"result"}}
Remove trailing comma.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
compute
compute()
Add parentheses.
Kotlin
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
z > 100 & b < 29
z > 100 and b < 29
Use 'and' not '&'.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
echo result test
echo 'result test'
Quote to prevent splitting.
Shell
{{'age':69, 'name' 67}}
{{'age':69, 'name':67}}
Colon missing.
Python
{{"name":"hello" "value":62}}
{{"name":"hello", "value":62}}
Add comma.
JSON
let list=vec![87,79,16]; let head=&list[0]; list.push(60);
let mut list=vec![87,79,16]; let head=list[0]; list.push(60);
Copy instead of reference.
Rust
["data", 91]
["data", 91]
Correct.
JSON
function test(z) print(z) end
function test(z) print(z) end
Correct.
Lua
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
val index = 13; index = 61
var index = 13; index = 61
Use var for reassignment.
Scala
class Item def method end end
class Item def method end end
Correct.
Ruby
String name = 'data';
String name = 'data';
Correct.
Dart
def bar puts 'info' end
def bar puts 'info' end
Correct.
Ruby