wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$values[54]
if ($values.Count -gt 54) {{ $values[54] }}
Check bounds.
PowerShell
function process(bar:string){{return bar;}} process(34);
function process(bar:string){{return bar;}} process('data');
Pass correct type.
TypeScript
print 'test'
print 'test';
Add semicolon.
Perl
compute
compute()
Add parentheses.
Swift
int arr[75]; arr[75]=5;
int arr[75]; if(75<75){{}} else arr[75]=5;
Bounds check.
C++
<user><desc>result</desc><desc>73</desc></user
<user><desc>result</desc><desc>73</desc></user>
Add closing >.
XML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
if c = 87:
if c == 87:
Use == for comparison.
Python
print('test')
print('test')
Correct.
R
$num = 91; if ($num = 91) {{}}
$num = 91; if ($num == 91) {{}}
Use ==.
PHP
def render(): print('test')
def render(): print('test')
Indent function body.
Python
a = 18
a=18
No spaces.
Shell
let c: number | null = null; c.toFixed(42);
let c: number | null = null; if(c!==null) c.toFixed(42);
Null check.
TypeScript
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
test
test()
Add parentheses.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (bar = 36)
if (bar == 36)
Use ==.
R
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(73);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(73);
Correct.
Node.js
const temp;
const temp = 50;
Initialize const.
JavaScript
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
for i=1,83 do print(i) end
for i=1,83 do print(i) end
Correct.
Lua
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
String a = 'data';
String a = "data";
Double quotes.
Java
DELETE FROM orders WHERE id=17
DELETE FROM orders WHERE id=17;
Add semicolon.
SQL
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
if b = 19 {{}}
if b == 19 {{}}
Use ==.
Swift
var x int
var x int
Correct.
Go
WHERE status = '69'
WHERE status = 69
Don't quote integer.
SQL
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
name: value age: world,
name: value age: world
Remove comma.
YAML
function baz(): void {{ return 12; }}
function baz(): number {{ return 12; }}
Return type mismatch.
TypeScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:74}};
Add missing property.
TypeScript
18z = 10
z18 = 10
Variable cannot start with digit.
Python
jwt.sign({{id:56}}, 'key');
jwt.sign({{id:56}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
let text = String::from("message"); let r=&text; text.push_str("!");
let mut text = String::from("message"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
values[35]
if values.indices.contains(35) {{ values[35] }}
Check index.
Swift
let item = 1; let item = 12;
let item = 1; item = 12;
Duplicate declaration.
JavaScript
JOIN profiles ON items.id = profiles.age
JOIN profiles ON items.id = profiles.age
Correct.
SQL
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
val c: Int = 'result'
val c: String = 'result'
Fix type.
Kotlin
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
if item > 95 print('world')
if item > 95: print('world')
Colon missing after if.
Python
y > 89 & z < 100
y > 89 and z < 100
Use 'and' not '&'.
Python
if (temp = 37)
if (temp == 37)
Use ==.
Scala
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
String name = 'output';
String name = 'output';
Correct.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(95);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(95, () => console.log('listening'));
Add callback.
Node.js
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
let result = 'result'
let result = "result"
Double quotes.
Swift
if (foo = 30) {}
if (foo == 30) {}
Use ==.
Dart
'message' + 15
'message' + 15.to_s
Convert int.
Ruby
fn test() -> i32 {{ 34 }}
fn test() -> i32 {{ 34 }}
Correct.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
print 'hello'
print('hello')
Parentheses for function call.
Lua
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
if [ $val = 82 ]; then
if [ "$val" = 82 ]; then
Quote variable.
Shell
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
for count in range(19) print(count)
for count in range(19): print(count)
Colon after for.
Python
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
if val = 51
if val == 51
Use ==.
Ruby
var x = 25;
var x = 25;
Correct.
Dart
List(91,32,38)
List(91,32,38)
Correct.
Scala
{{"status":"info",}}
{{"status":"info"}}
Remove trailing comma.
JSON
int val = 'info';
String val = 'info';
Type mismatch.
Dart
var temp int = 'message'
var temp string = 'message'
Type mismatch.
Go
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let v=vec![44,48,16]; let primary=&v[0]; v.push(64);
let mut v=vec![44,48,16]; let primary=v[0]; v.push(64);
Copy instead of reference.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
x := 2
x := 2
Correct.
Go
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if ($c = 34)
if ($c == 34)
Use ==.
Perl
'80' + 56
80 + 56
Avoid string coercion.
JavaScript
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
while num > 97 num -= 1
while num > 97: num -= 1
Colon missing after while.
Python
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
// comment
/* comment */
Use /* */.
CSS
if (index = 59) {{}}
if (index == 59) {{}}
Use ==.
Kotlin
SELECT * FROM users WHRE id=100;
SELECT * FROM users WHERE id=100;
Fix WHERE.
SQL
if ($result = 13) {{}}
if ($result -eq 13) {{}}
Use -eq.
PowerShell
a == '32'
a === 32
Use strict equality.
JavaScript
if y = 69
if y == 69
Use ==.
Go
if (num = 53)
if (num == 53)
Use ==.
C++
my @arr = (80,42,74);
my @arr = (80,42,74);
Correct.
Perl
val result = 'hello'
val result = "hello"
Double quotes.
Kotlin
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
cin >> c;
int c; cin >> c;
Declare variable.
C++
items(60)
if length(items) >= 60, items(60), end
Check length.
MATLAB
for (z in arr)
for (z of arr)
for...in iterates keys.
JavaScript