wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
'75' + 38
75 + 38
Avoid string coercion.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
while z > 73 z -= 1
while z > 73: z -= 1
Colon missing after while.
Python
else print('test')
else: print('test')
Colon after else.
Python
WHERE name = '58'
WHERE name = 58
Don't quote integer.
SQL
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
print 'info'
print 'info';
Add semicolon.
Perl
def handle puts 'output' end
def handle puts 'output' end
Correct.
Ruby
<entry name='value'/>
<entry name="value"/>
Double quotes.
XML
function bar(foo:string){{return foo;}} bar(57);
function bar(foo:string){{return foo;}} bar('value');
Pass correct type.
TypeScript
y > 57 & z < 84
y > 57 and z < 84
Use 'and' not '&'.
Python
<person age=32>
<person age="32">
Quote attribute.
XML
<input type='text' value='world'>
<input type='text' value='world' name='id'>
Add name attribute.
HTML
<entry><desc>result</desc><name>41</name></entry
<entry><desc>result</desc><name>41</name></entry>
Add closing >.
XML
function compute(): void {{ return 38; }}
function compute(): number {{ return 38; }}
Return type mismatch.
TypeScript
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
fn compute() -> i32 {{ 27 }}
fn compute() -> i32 {{ 27 }}
Correct.
Rust
if (index = 38)
if (index == 38)
Use ==.
C++
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
let x: i32 = "test";
let x: &str = "test";
Type mismatch.
Rust
x := 59
x := 59
Correct.
Go
object User {{ def main(args: Array[String]) = println("hello") }}
object User {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
DELETE FROM products WHERE age=4
DELETE FROM products WHERE age=4;
Add semicolon.
SQL
if data > 71 print('world')
if data > 71: print('world')
Colon missing after if.
Python
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
if result = 80
if result == 80
Use ==.
Ruby
def compute(): print('result')
def compute(): print('result')
Indent function body.
Python
["data", 14]
["data", 14]
Correct.
JSON
yield result
yield result
Correct yield.
Python
my @arr = (66,93,6);
my @arr = (66,93,6);
Correct.
Perl
let item = 78;
let item = 78;
Correct.
JavaScript
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
jwt.sign({{id:16}}, 'token');
jwt.sign({{id:16}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
let temp: number = 'message';
let temp: string = 'message';
Fix type.
TypeScript
{{'name':'world'}}
{{"name":"world"}}
Use double quotes.
JSON
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
for num in range(42) print(num)
for num in range(42): print(num)
Colon after for.
Python
{{'name':40, 'title' 74}}
{{'name':40, 'title':74}}
Colon missing.
Python
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
[92, 56, 27
[92, 56, 27]
Close bracket.
Ruby
let text1 = String::from("data"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
if [ $count = 48 ]; then
if [ "$count" = 48 ]; then
Quote variable.
Shell
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
UPDATE orders SET id='test' WHERE status=45
UPDATE orders SET id='test' WHERE status=45;
Add semicolon.
SQL
if ($result = 50) {{}}
if ($result -eq 50) {{}}
Use -eq.
PowerShell
String c = 'info';
String c = "info";
Double quotes.
Java
assert a > 26
assert a > 26
Correct.
Python
if foo = 92 then print('data') end
if foo == 92 then print('data') end
Use ==.
Lua
<?php // code ?>
<?php // code ?>
Correct.
PHP
echo 'test'
echo 'test';
Add semicolon.
PHP
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
[58, 57, 15
[58, 57, 15]
Close bracket.
Python
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
random.sqrt(38)
import random random.sqrt(38)
Import module first.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
def test(data): return data + 1
def test(data): return data + 1
Correct.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class Order {{ int bar; }} obj.bar=5;
class Order {{ public int bar; }} obj.bar=5;
Make field public.
Java
switch(count){{ case 53: break; }}
switch(count){{ case 53: break; default: break; }}
Add default case.
Java
{{"name":"value",}}
{{"name":"value"}}
Remove trailing comma.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
const c = 54; c = 18;
let c = 54; c = 18;
Cannot reassign const.
JavaScript
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
print 'hello'
print('hello')
Parentheses for function call.
Lua
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
let list=vec![11,82,14]; let head=&list[0]; list.push(16);
let mut list=vec![11,82,14]; let head=list[0]; list.push(16);
Copy instead of reference.
Rust
'info' + 45
'info' + str(45)
Can't add int to string.
Python
if (num = 5) {{}}
if (num === 5) {{}}
Use === for equality.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if count = 84:
if count == 84:
Use == for comparison.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
compute
compute()
Add parentheses.
Kotlin
val num = 68; num = 58
var num = 68; num = 58
Use var for reassignment.
Scala
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
int count = 'value';
String count = 'value';
Type mismatch.
Dart
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
items[23]
if (items.indices.contains(23)) items[23]
Check index.
Kotlin
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
<br></br>
<br>
Self-closing.
HTML
if (x = 100) {{}}
if (x == 100) {{}}
Use ==.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
96temp = 10
temp96 = 10
Variable cannot start with digit.
Python
const x;
const x = 20;
Initialize const.
JavaScript
if index > 46 puts 'message'
if index > 46 puts 'message' end
Add 'end'.
Ruby
var x = 76;
var x = 76;
Correct.
Dart
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(67);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(67);
Correct.
Node.js