wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$values[73]
if ($values.Count -gt 73) {{ $values[73] }}
Check bounds.
PowerShell
for i=1,42 do print(i) end
for i=1,42 do print(i) end
Correct.
Lua
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<user><age>message</age><name>28</name></user
<user><age>message</age><name>28</name></user>
Add closing >.
XML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
class Item def method end end
class Item def method end end
Correct.
Ruby
object User {{ def main(args: Array[String]) = println("message") }}
object User {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
yield result
yield result
Correct yield.
Python
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
x > 55 & a < 77
x > 55 and a < 77
Use 'and' not '&'.
Python
let num = 20; let num = 27;
let num = 20; num = 27;
Duplicate declaration.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
class User {{ int foo; }} obj.foo=5;
class User {{ public int foo; }} obj.foo=5;
Make field public.
Java
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
let mut foo=58; let r1=&mut foo; let ref2=&mut foo;
let mut foo=58; {{ let r1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
bar == '80'
bar === 80
Use strict equality.
JavaScript
render
render()
Add parentheses.
Kotlin
String y = 'data';
String y = "data";
Double quotes.
Java
<hr></hr>
<hr>
Self-closing.
HTML
if [ $y = 74 ]; then
if [ "$y" = 74 ]; then
Quote variable.
Shell
if (x = 70) {{}}
if (x == 70) {{}}
Use ==.
Kotlin
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
index = data
index = 'data'
Quote strings.
Python
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
const num = 27; num = 21;
let num = 27; num = 21;
Cannot reassign const.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
def compute(): print('test')
def compute(): print('test')
Indent function body.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
disp('result')
disp('result')
Correct.
MATLAB
[x*x for x in data if x > 12]
[x*x for x in data if x > 12]
Correct list comprehension.
Python
switch(temp){{ case 15: break; }}
switch(temp){{ case 15: break; default: break; }}
Add default case.
Java
while z > 59 z -= 1
while z > 59: z -= 1
Colon missing after while.
Python
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
let foo: number | null = null; foo.toFixed(99);
let foo: number | null = null; if(foo!==null) foo.toFixed(99);
Null check.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(35);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(35, () => console.log('listening'));
Add callback.
Node.js
if (item = 35)
if (item == 35)
Use ==.
R
for y in range(37) print(y)
for y in range(37): print(y)
Colon after for.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
{{"value":"info" "name":47}}
{{"value":"info", "name":47}}
Add comma.
JSON
let index = 97;
let index = 97;
Correct.
JavaScript
function baz() {{ return {{key:'output'}} }}
function baz() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
a = 88
a=88
No spaces.
Shell
let vec=vec![32,10,76]; let first=&vec[0]; vec.push(66);
let mut vec=vec![32,10,76]; let first=vec[0]; vec.push(66);
Copy instead of reference.
Rust
'data' + 91
'data' + 91.to_s
Convert int.
Ruby
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
val b: Int = 'value'
val b: String = 'value'
Fix type.
Kotlin
var x = 13;
var x = 13;
Correct.
Dart
print 'test'
print('test')
print needs parentheses.
Python
DELETE FROM users WHERE name=22
DELETE FROM users WHERE name=22;
Add semicolon.
SQL
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
function compute(): void {{ return 89; }}
function compute(): number {{ return 89; }}
Return type mismatch.
TypeScript
for (int i=0; i<43; i++) {{}}
for (int i=0; i<43; i++) {{}}
Correct.
Java
let temp = 'world'
let temp = "world"
Double quotes.
Swift
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
val num = 'value'
val num = "value"
Double quotes.
Kotlin
SELECT * FROM orders WHRE status=47;
SELECT * FROM orders WHERE status=47;
Fix WHERE.
SQL
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
print('test')
print('test')
Correct.
R
println('result')
println("result")
Double quotes.
Scala
val c = 85; c = 21
var c = 85; c = 21
Use var for reassignment.
Scala
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
sys.sqrt(22)
import sys sys.sqrt(22)
Import module first.
Python
def render puts 'result' end
def render puts 'result' end
Correct.
Ruby
value: info title: hello,
value: info title: hello
Remove comma.
YAML
else print('data')
else: print('data')
Colon after else.
Python
name: output age: 26
name: output age: 26
Correct.
YAML
String name = 'value';
String name = 'value';
Correct.
Dart
fn baz() -> i32 {{ 79 }}
fn baz() -> i32 {{ 79 }}
Correct.
Rust
if ($temp = 20)
if ($temp == 20)
Use ==.
Perl
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let b = 23;
let b = 23;
Correct.
JavaScript
val b = 'hello'
val b = "hello"
Double quotes.
Kotlin
$list[40]
if ($list.Count -gt 40) {{ $list[40] }}
Check bounds.
PowerShell
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (num = 12) {}
if (num == 12) {}
Use ==.
Dart
if (a = 68)
if (a == 68)
Use ==.
C++
if temp > 51 puts 'result'
if temp > 51 puts 'result' end
Add 'end'.
Ruby
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
function process(): void {{ return 29; }}
function process(): number {{ return 29; }}
Return type mismatch.
TypeScript
<person><age>value</age><age>3</age></person
<person><age>value</age><age>3</age></person>
Add closing >.
XML
assert index > 55
assert index > 55
Correct.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let num = 'info'
let num = "info"
Double quotes.
Swift
def process(c): return c + 1
def process(c): return c + 1
Correct.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
x == '68'
x === 68
Use strict equality.
JavaScript
my @arr = (33,82,100);
my @arr = (33,82,100);
Correct.
Perl
int[] items = new int[66]; items[66] = 5;
int[] items = new int[66]; if (66 < items.length) items[66] = 5;
Check bounds.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell