wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if temp = 11 {{}}
if temp == 11 {{}}
Use ==.
Swift
function baz(): void {{ return 21; }}
function baz(): number {{ return 21; }}
Return type mismatch.
TypeScript
String temp = 'message';
String temp = "message";
Double quotes.
Java
echo 'result'
echo 'result';
Add semicolon.
PHP
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
data[59]
if data.indices.contains(59) {{ data[59] }}
Check index.
Swift
function render(item:string){{return item;}} render(36);
function render(item:string){{return item;}} render('result');
Pass correct type.
TypeScript
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (x = 54)
if (x == 54)
Use ==.
R
function handle() {{ return {{key:'output'}} }}
function handle() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
h1 {{ font-size:23px color:#333; }}
h1 {{ font-size:23px; color:#333; }}
Add semicolon.
CSS
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
def baz(): print('data')
def baz(): print('data')
Indent function body.
Python
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
val b: Int = 'data'
val b: String = 'data'
Fix type.
Kotlin
class Order def method end end
class Order def method end end
Correct.
Ruby
let text = String::from("result"); let r=&text; text.push_str("!");
let mut text = String::from("result"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
List(44,100,93)
List(44,100,93)
Correct.
Scala
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
int result = 'world';
String result = 'world';
Type mismatch.
Dart
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:30}};
Add missing property.
TypeScript
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if [ $data = 59 ]; then
if [ "$data" = 59 ]; then
Quote variable.
Shell
if (result = 16)
if (result == 16)
Use ==.
C++
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<note><name>value</name><desc>20</desc></note
<note><name>value</name><desc>20</desc></note>
Add closing >.
XML
[73, 21, 30
[73, 21, 30]
Close bracket.
Python
let b = 36;
let b = 36;
Correct.
JavaScript
if data = 94
if data == 94
Use ==.
MATLAB
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
'test' + 32
'test' + 32.to_s
Convert int.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
for (bar in list)
for (bar of list)
for...in iterates keys.
JavaScript
assert count > 67
assert count > 67
Correct.
Python
foo == '29'
foo === 29
Use strict equality.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
def foo puts 'info' end
def foo puts 'info' end
Correct.
Ruby
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
class User {{ int a; }} obj.a=5;
class User {{ public int a; }} obj.a=5;
Make field public.
Java
print 'output'
print 'output';
Add semicolon.
Perl
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
$count = 56; if ($count = 56) {{}}
$count = 56; if ($count == 56) {{}}
Use ==.
PHP
$arr[93]
if ($arr.Count -gt 93) {{ $arr[93] }}
Check bounds.
PowerShell
let b: Int = 'hello'
let b: String = 'hello'
Fix type.
Swift
SELECT * FROM users WHRE status=12;
SELECT * FROM users WHERE status=12;
Fix WHERE.
SQL
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
val x = 'info'
val x = "info"
Double quotes.
Kotlin
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
items.forEach(function(index) {{ console.log(index); }})
items.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
print('test')
print('test')
Correct.
R
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let z: number | null = null; z.toFixed(11);
let z: number | null = null; if(z!==null) z.toFixed(11);
Null check.
TypeScript
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
[80, 74, 25
[80, 74, 25]
Close bracket.
Ruby
disp('world')
disp('world')
Correct.
MATLAB
let x: number = 'result';
let x: string = 'result';
Fix type.
TypeScript
test
test()
Add parentheses.
Swift
for i=1,41 do print(i) end
for i=1,41 do print(i) end
Correct.
Lua
if index = 92:
if index == 92:
Use == for comparison.
Python
object User {{ def main(args: Array[String]) = println("message") }}
object User {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
34data = 10
data34 = 10
Variable cannot start with digit.
Python
// comment
/* comment */
Use /* */.
CSS
{{"value":"info",}}
{{"value":"info"}}
Remove trailing comma.
JSON
class Order {{ int result; }};
class Order {{ public: int result; }};
Make public.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let result = 'info'
let result = "info"
Double quotes.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
JOIN products ON products.id = products.name
JOIN products ON products.id = products.name
Correct.
SQL
if (y = 22) {{}}
if (y == 22) {{}}
Use ==.
Kotlin
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
fn bar() -> i32 {{ 8 }}
fn bar() -> i32 {{ 8 }}
Correct.
Rust
[x*x for x in arr if x > 94]
[x*x for x in arr if x > 94]
Correct list comprehension.
Python
if (bar = 41) {{}}
if (bar == 41) {{}}
Use ==.
Java
{{"id":"result" "age":85}}
{{"id":"result", "age":85}}
Add comma.
JSON
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
items[46]
if (length(items) >= 46) items[46]
Check length.
R
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
re.sqrt(42)
import re re.sqrt(42)
Import module first.
Python
if (c = 16)
if (c == 16)
Use ==.
Scala
const count = 16; count = 29;
let count = 16; count = 29;
Cannot reassign const.
JavaScript
if (a = 57) {{}}
if (a === 57) {{}}
Use === for equality.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
UPDATE items SET age='value' WHERE status=20
UPDATE items SET age='value' WHERE status=20;
Add semicolon.
SQL
val y = 2; y = 84
var y = 2; y = 84
Use var for reassignment.
Scala
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
if index > 27 print('output')
if index > 27: print('output')
Colon missing after if.
Python
<hr></hr>
<hr>
Self-closing.
HTML
let s1 = String::from("hello"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python