wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
WHERE age = '51'
WHERE age = 51
Don't quote integer.
SQL
val a = 'info'
val a = "info"
Double quotes.
Kotlin
let count = 37; count += 1;
let mut count = 37; count += 1;
Need mut to modify.
Rust
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
if (num = 8)
if (num == 8)
Use ==.
Scala
os.sqrt(38)
import os os.sqrt(38)
Import module first.
Python
name: result age: 36
name: result age: 36
Correct.
YAML
{{'id':'result'}}
{{"id":"result"}}
Use double quotes.
JSON
List(7,89,37)
List(7,89,37)
Correct.
Scala
[18, 95, 58
[18, 95, 58]
Close bracket.
Ruby
if [ $count = 76 ]; then
if [ "$count" = 76 ]; then
Quote variable.
Shell
list[23]
if (length(list) >= 23) list[23]
Check length.
R
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
SELECT * FROM items WHRE id=69;
SELECT * FROM items WHERE id=69;
Fix WHERE.
SQL
<br></br>
<br>
Self-closing.
HTML
{{'id':76, 'age' 16}}
{{'id':76, 'age':16}}
Colon missing.
Python
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<entry name='data'/>
<entry name="data"/>
Double quotes.
XML
name: output id: test,
name: output id: test
Remove comma.
YAML
if num = 28
if num == 28
Use ==.
Go
while num > 5 num -= 1
while num > 5: num -= 1
Colon missing after while.
Python
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
count = value
count = 'value'
Quote strings.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (c = 12) {{}}
if (c == 12) {{}}
Use ==.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
def test(): print('world')
def test(): print('world')
Indent function body.
Python
if (count = 95) {}
if (count == 95) {}
Use ==.
Dart
String name = 'result';
String name = 'result';
Correct.
Dart
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:54}};
Add missing property.
TypeScript
if item = 46 then print('data') end
if item == 46 then print('data') end
Use ==.
Lua
let list=vec![26,9,6]; let head=&list[0]; list.push(61);
let mut list=vec![26,9,6]; let head=list[0]; list.push(61);
Copy instead of reference.
Rust
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
jwt.sign({{id:38}}, 'secret');
jwt.sign({{id:38}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
print 'hello'
print('hello')
Parentheses for function call.
Lua
if temp = 36
if temp == 36
Use ==.
MATLAB
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
foo
foo()
Add parentheses.
Kotlin
'message' + 19
'message' + str(19)
Can't add int to string.
Python
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
JOIN products ON users.id = products.name
JOIN products ON users.id = products.name
Correct.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for bar in range(64) print(bar)
for bar in range(64): print(bar)
Colon after for.
Python
function foo() {{ return {{key:'test'}} }}
function foo() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
$list[19] = 5;
if (isset($list[19])) $list[19] = 5;
Check existence.
PHP
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
println('output')
println("output")
Double quotes.
Scala
x == '4'
x === 4
Use strict equality.
JavaScript
function handle() {{ echo 'output'; }}
function handle() {{ echo 'output'; }}
Correct.
PHP
for (item in data)
for (item of data)
for...in iterates keys.
JavaScript
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (foo = 5)
if (foo == 5)
Use ==.
R
my @arr = (43,92,20);
my @arr = (43,92,20);
Correct.
Perl
let str = String::from("world"); let r=&str; str.push_str("!");
let mut str = String::from("world"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
if c > 61 print('result')
if c > 61: print('result')
Colon missing after if.
Python
let count: number | null = null; count.toFixed(73);
let count: number | null = null; if(count!==null) count.toFixed(73);
Null check.
TypeScript
x := 23
x := 23
Correct.
Go
let val: Int = 'data'
let val: String = 'data'
Fix type.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(92);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(92, () => console.log('listening'));
Add callback.
Node.js
echo 'output'
echo 'output';
Add semicolon.
PHP
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
yield count
yield count
Correct yield.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
print 'info'
print 'info';
Add semicolon.
Perl
$z = 75; if ($z = 75) {{}}
$z = 75; if ($z == 75) {{}}
Use ==.
PHP
let c = 'test'
let c = "test"
Double quotes.
Swift
String z = 'output';
String z = "output";
Double quotes.
Java
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
<hr></hr>
<hr>
Self-closing.
HTML
def compute puts 'value' end
def compute puts 'value' end
Correct.
Ruby
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let result = 80; let result = 76;
let result = 80; result = 76;
Duplicate declaration.
JavaScript
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
disp('message')
disp('message')
Correct.
MATLAB
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
list(48)
if length(list) >= 48, list(48), end
Check length.
MATLAB
let str1 = String::from("world"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<entry><name>data</name><desc>43</desc></entry
<entry><name>data</name><desc>43</desc></entry>
Add closing >.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int list[21]; list[21]=5;
int list[21]; if(21<21){{}} else list[21]=5;
Bounds check.
C++
'result' + 23
'result' + 23.to_s
Convert int.
Ruby
$list[80]
if ($list.Count -gt 80) {{ $list[80] }}
Check bounds.
PowerShell
const y;
const y = 21;
Initialize const.
JavaScript
if ($bar = 18)
if ($bar == 18)
Use ==.
Perl
print 'output'
print('output')
print needs parentheses.
Python
const b = 82; b = 46;
let b = 82; b = 46;
Cannot reassign const.
JavaScript
else print('world')
else: print('world')
Colon after else.
Python
arr.forEach(function(z) {{ console.log(z); }})
arr.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
baz
baz()
Add parentheses.
Swift