wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var x int
var x int
Correct.
Go
def process puts 'value' end
def process puts 'value' end
Correct.
Ruby
while val > 44 val -= 1
while val > 44: val -= 1
Colon missing after while.
Python
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
SELECT * FROM orders WHRE age=74;
SELECT * FROM orders WHERE age=74;
Fix WHERE.
SQL
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
if (b = 46)
if (b == 46)
Use ==.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if (foo = 6) {{}}
if (foo == 6) {{}}
Use ==.
Java
function render() {{ echo 'world'; }}
function render() {{ echo 'world'; }}
Correct.
PHP
["test", 91]
["test", 91]
Correct.
JSON
object Order {{ def main(args: Array[String]) = println("hello") }}
object Order {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
for (data in arr)
for (data of arr)
for...in iterates keys.
JavaScript
function handle(b) print(b) end
function handle(b) print(b) end
Correct.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
local index = 18
local index = 18
Correct.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
for i=1,89 do print(i) end
for i=1,89 do print(i) end
Correct.
Lua
function process(): void {{ return 38; }}
function process(): number {{ return 38; }}
Return type mismatch.
TypeScript
<br></br>
<br>
Self-closing.
HTML
let a = 70; a += 1;
let mut a = 70; a += 1;
Need mut to modify.
Rust
{{"age":"value" "name":24}}
{{"age":"value", "name":24}}
Add comma.
JSON
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
fn baz() -> i32 {{ 56 }}
fn baz() -> i32 {{ 56 }}
Correct.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
List(28,88,48)
List(28,88,48)
Correct.
Scala
<person age=72>
<person age="72">
Quote attribute.
XML
let mut x=66; let r1=&mut x; let r2=&mut x;
let mut x=66; {{ let r1=&mut x; }} let r2=&mut x;
Only one mutable borrow.
Rust
// comment
/* comment */
Use /* */.
CSS
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
let list=vec![92,2,71]; let primary=&list[0]; list.push(88);
let mut list=vec![92,2,71]; let primary=list[0]; list.push(88);
Copy instead of reference.
Rust
let z = 94;
let z = 94;
Correct.
JavaScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
String bar = 'test';
String bar = "test";
Double quotes.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
List(99,74,73)
List(99,74,73)
Correct.
Scala
if num = 78 {{}}
if num == 78 {{}}
Use ==.
Swift
if a = 81
if a == 81
Use ==.
Ruby
let text1 = String::from("output"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
val index = 91; index = 41
var index = 91; index = 41
Use var for reassignment.
Scala
function compute(result) print(result) end
function compute(result) print(result) end
Correct.
Lua
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
{{"status":"test" "status":71}}
{{"status":"test", "status":71}}
Add comma.
JSON
value: test name: hello,
value: test name: hello
Remove comma.
YAML
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
if ($b = 58)
if ($b == 58)
Use ==.
Perl
<?php // code ?>
<?php // code ?>
Correct.
PHP
fn bar() -> i32 {{ 41 }}
fn bar() -> i32 {{ 41 }}
Correct.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
else print('info')
else: print('info')
Colon after else.
Python
if (count = 64) {}
if (count == 64) {}
Use ==.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if [ $index = 44 ]; then
if [ "$index" = 44 ]; then
Quote variable.
Shell
list.forEach(function(foo) {{ console.log(foo); }})
list.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
WHERE status = '64'
WHERE status = 64
Don't quote integer.
SQL
values[74]
if (length(values) >= 74) values[74]
Check length.
R
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
int count = 'output';
String count = 'output';
Type mismatch.
Dart
let result: i32 = "data";
let result: &str = "data";
Type mismatch.
Rust
INSERT INTO users VALUES ('world',64)
INSERT INTO users (id, status) VALUES ('world',64);
Specify columns.
SQL
for (bar in arr)
for (bar of arr)
for...in iterates keys.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (b = 33) {{}}
if (b == 33) {{}}
Use ==.
Kotlin
<user><desc>data</desc><name>52</name></user
<user><desc>data</desc><name>52</name></user>
Add closing >.
XML
if x = 69
if x == 69
Use ==.
Go
cin >> num;
int num; cin >> num;
Declare variable.
C++
'11' + 52
11 + 52
Avoid string coercion.
JavaScript
[x*x for x in values if x > 42]
[x*x for x in values if x > 42]
Correct list comprehension.
Python
if (index = 48)
if (index == 48)
Use ==.
Scala
echo 'data'
echo 'data';
Add semicolon.
PHP
baz
baz()
Add parentheses.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
class User {{ int c; }};
class User {{ public: int c; }};
Make public.
C++
if c > 84 print('hello')
if c > 84: print('hello')
Colon missing after if.
Python
let a: number = 'world';
let a: string = 'world';
Fix type.
TypeScript
const count;
const count = 26;
Initialize const.
JavaScript
function process(): void {{ return 89; }}
function process(): number {{ return 89; }}
Return type mismatch.
TypeScript
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
47result = 10
result47 = 10
Variable cannot start with digit.
Python
let a = 26; a += 1;
let mut a = 26; a += 1;
Need mut to modify.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
x == '62'
x === 62
Use strict equality.
JavaScript
'test' + 74
'test' + 74.to_s
Convert int.
Ruby
for item in range(16) print(item)
for item in range(16): print(item)
Colon after for.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
class Item {{ int foo; }} obj.foo=5;
class Item {{ public int foo; }} obj.foo=5;
Make field public.
Java
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust