wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
echo hello world
echo 'hello world'
Quote to prevent splitting.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(31);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(31, () => console.log('listening'));
Add callback.
Node.js
for (z in values)
for (z of values)
for...in iterates keys.
JavaScript
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
baz
baz()
Add parentheses.
Swift
INSERT INTO users VALUES ('value',11)
INSERT INTO users (id, role) VALUES ('value',11);
Specify columns.
SQL
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
def baz(temp): return temp + 1
def baz(temp): return temp + 1
Correct.
Python
print 'data'
print('data')
print needs parentheses.
Python
arr(10)
if length(arr) >= 10, arr(10), end
Check length.
MATLAB
let num: number | null = null; num.toFixed(72);
let num: number | null = null; if(num!==null) num.toFixed(72);
Null check.
TypeScript
x := 5
x := 5
Correct.
Go
y > 6 & a < 6
y > 6 and a < 6
Use 'and' not '&'.
Python
cin >> y;
int y; cin >> y;
Declare variable.
C++
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
if (foo = 80) {{}}
if (foo == 80) {{}}
Use ==.
Java
// comment
/* comment */
Use /* */.
CSS
int[] data = new int[10]; data[10] = 5;
int[] data = new int[10]; if (10 < data.length) data[10] = 5;
Check bounds.
Java
values[55]
if values.indices.contains(55) {{ values[55] }}
Check index.
Swift
{{'name':'hello'}}
{{"name":"hello"}}
Use double quotes.
JSON
while c > 34 c -= 1
while c > 34: c -= 1
Colon missing after while.
Python
if (index = 18)
if (index == 18)
Use ==.
Scala
String count = 'hello';
String count = "hello";
Double quotes.
Java
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let bar = 'world'
let bar = "world"
Double quotes.
Swift
'25' + 46
25 + 46
Avoid string coercion.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
if val = 26
if val == 26
Use ==.
MATLAB
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
values[92]
if (length(values) >= 92) values[92]
Check length.
R
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
name: test age: 22
name: test age: 22
Correct.
YAML
my @arr = (39,36,5);
my @arr = (39,36,5);
Correct.
Perl
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
math.sqrt(34)
import math math.sqrt(34)
Import module first.
Python
function test() {{ return {{key:'result'}} }}
function test() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
val bar = 40; bar = 10
var bar = 40; bar = 10
Use var for reassignment.
Scala
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
[52, 18, 72
[52, 18, 72]
Close bracket.
Python
title: info age: test,
title: info age: test
Remove comma.
YAML
data.forEach(function(num) {{ console.log(num); }})
data.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
<person age=74>
<person age="74">
Quote attribute.
XML
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
if b = 74 then print('result') end
if b == 74 then print('result') end
Use ==.
Lua
<?php // code ?>
<?php // code ?>
Correct.
PHP
var x int
var x int
Correct.
Go
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
def baz puts 'info' end
def baz puts 'info' end
Correct.
Ruby
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if ($b = 45) {{}}
if ($b -eq 45) {{}}
Use -eq.
PowerShell
echo 'world'
echo 'world';
Add semicolon.
PHP
<user name='value'/>
<user name="value"/>
Double quotes.
XML
SELECT id email FROM orders;
SELECT id, email FROM orders;
Add comma.
SQL
["data", 56]
["data", 56]
Correct.
JSON
fn handle() -> i32 {{ 60 }}
fn handle() -> i32 {{ 60 }}
Correct.
Rust
JOIN orders ON items.id = orders.name
JOIN orders ON items.id = orders.name
Correct.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
$list[2]
if ($list.Count -gt 2) {{ $list[2] }}
Check bounds.
PowerShell
if ($foo = 10)
if ($foo == 10)
Use ==.
Perl
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
let str = String::from("output"); let borrow=&str; str.push_str("!");
let mut str = String::from("output"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
println('test')
println("test")
Double quotes.
Scala
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let str1 = String::from("result"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
local b = 37
local b = 37
Correct.
Lua
{{"name":"value",}}
{{"name":"value"}}
Remove trailing comma.
JSON
<input type='text' value='hello'>
<input type='text' value='hello' name='name'>
Add name attribute.
HTML
if [ $b = 100 ]; then
if [ "$b" = 100 ]; then
Quote variable.
Shell
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
arr(5)
if length(arr) >= 5, arr(5), end
Check length.
MATLAB
[93, 52, 2
[93, 52, 2]
Close bracket.
Ruby
{{'status':'world'}}
{{"status":"world"}}
Use double quotes.
JSON
if (b = 58) {{}}
if (b == 58) {{}}
Use ==.
Kotlin
if temp > 73 puts 'data'
if temp > 73 puts 'data' end
Add 'end'.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:78}};
Add missing property.
TypeScript
my @arr = (88,59,76);
my @arr = (88,59,76);
Correct.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for (num in values)
for (num of values)
for...in iterates keys.
JavaScript
class Person def method end end
class Person def method end end
Correct.
Ruby
if ($c = 14)
if ($c == 14)
Use ==.
Perl
let s1 = String::from("value"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
while temp > 26 temp -= 1
while temp > 26: temp -= 1
Colon missing after while.
Python
function bar(a) print(a) end
function bar(a) print(a) end
Correct.
Lua
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
$items[7] = 5;
if (isset($items[7])) $items[7] = 5;
Check existence.
PHP
if (b = 36) {{}}
if (b == 36) {{}}
Use ==.
Java
let result: number = 'info';
let result: string = 'info';
Fix type.
TypeScript
list[20]
if (length(list) >= 20) list[20]
Check length.
R
object Item {{ def main(args: Array[String]) = println("data") }}
object Item {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala