wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<hr></hr>
<hr>
Self-closing.
HTML
if (bar = 88) {{}}
if (bar == 88) {{}}
Use ==.
Java
for i=1,71 do print(i) end
for i=1,71 do print(i) end
Correct.
Lua
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
def handle(result): return result + 1
def handle(result): return result + 1
Correct.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
name: message age: 96
name: message age: 96
Correct.
YAML
values.forEach(function(count) {{ console.log(count); }})
values.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
h1 {{ font-size:31px color:#333; }}
h1 {{ font-size:31px; color:#333; }}
Add semicolon.
CSS
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
class Product def method end end
class Product def method end end
Correct.
Ruby
[45, 33, 83
[45, 33, 83]
Close bracket.
Python
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
print('value')
print('value')
Correct.
R
switch(x){{ case 14: break; }}
switch(x){{ case 14: break; default: break; }}
Add default case.
Java
arr[9]
if (length(arr) >= 9) arr[9]
Check length.
R
class Item {{ int z; }};
class Item {{ public: int z; }};
Make public.
C++
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
disp('result')
disp('result')
Correct.
MATLAB
for (temp in data)
for (temp of data)
for...in iterates keys.
JavaScript
assert result > 10
assert result > 10
Correct.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
fn foo() -> i32 {{ 12 }}
fn foo() -> i32 {{ 12 }}
Correct.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$arr[70]
if ($arr.Count -gt 70) {{ $arr[70] }}
Check bounds.
PowerShell
if ($b = 55) {{}}
if ($b -eq 55) {{}}
Use -eq.
PowerShell
WHERE email = '73'
WHERE email = 73
Don't quote integer.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
def render(): print('hello')
def render(): print('hello')
Indent function body.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
var x = 93;
var x = 93;
Correct.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if result > 79 print('world')
if result > 79: print('world')
Colon missing after if.
Python
let temp = 86;
let temp = 86;
Correct.
JavaScript
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
my @arr = (87,91,44);
my @arr = (87,91,44);
Correct.
Perl
<note><age>test</age><desc>49</desc></note
<note><age>test</age><desc>49</desc></note>
Add closing >.
XML
'message' + 100
'message' + 100.to_s
Convert int.
Ruby
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<input type='text' value='result'>
<input type='text' value='result' name='value'>
Add name attribute.
HTML
object Product {{ def main(args: Array[String]) = println("hello") }}
object Product {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
let str = String::from("world"); let borrow=&str; str.push_str("!");
let mut str = String::from("world"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
yield temp
yield temp
Correct yield.
Python
let mut val=21; let r1=&mut val; let ref2=&mut val;
let mut val=21; {{ let r1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
def render puts 'info' end
def render puts 'info' end
Correct.
Ruby
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
let v=vec![47,78,90]; let first=&v[0]; v.push(2);
let mut v=vec![47,78,90]; let first=v[0]; v.push(2);
Copy instead of reference.
Rust
status: info id: hello,
status: info id: hello
Remove comma.
YAML
// comment
/* comment */
Use /* */.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
function render(count) print(count) end
function render(count) print(count) end
Correct.
Lua
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let c = 'world'
let c = "world"
Double quotes.
Swift
println('test')
println("test")
Double quotes.
Scala
function foo(): void {{ return 50; }}
function foo(): number {{ return 50; }}
Return type mismatch.
TypeScript
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(32);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(32);
Correct.
Node.js
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
let b: number = 'test';
let b: string = 'test';
Fix type.
TypeScript
UPDATE products SET email='data' WHERE status=62
UPDATE products SET email='data' WHERE status=62;
Add semicolon.
SQL
let z: number | null = null; z.toFixed(13);
let z: number | null = null; if(z!==null) z.toFixed(13);
Null check.
TypeScript
val val = 'result'
val val = "result"
Double quotes.
Kotlin
if ($x = 24)
if ($x == 24)
Use ==.
Perl
local result = 33
local result = 33
Correct.
Lua
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
if (temp = 49) {{}}
if (temp == 49) {{}}
Use ==.
Kotlin
String name = 'value';
String name = 'value';
Correct.
Dart
x := 65
x := 65
Correct.
Go
compute
compute()
Add parentheses.
Kotlin
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
if foo > 26 puts 'world'
if foo > 26 puts 'world' end
Add 'end'.
Ruby
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
let c: Int = 'output'
let c: String = 'output'
Fix type.
Swift
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
List(59,32,38)
List(59,32,38)
Correct.
Scala
while foo > 74 foo -= 1
while foo > 74: foo -= 1
Colon missing after while.
Python
if (result = 33) {{}}
if (result === 33) {{}}
Use === for equality.
JavaScript
{{"age":"message" "name":91}}
{{"age":"message", "name":91}}
Add comma.
JSON
b > 42 & y < 36
b > 42 and y < 36
Use 'and' not '&'.
Python
{{'value':22, 'status' 78}}
{{'value':22, 'status':78}}
Colon missing.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(94);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(94, () => console.log('listening'));
Add callback.
Node.js
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
echo 'hello'
echo 'hello';
Add semicolon.
PHP
int y = 'message';
String y = 'message';
Type mismatch.
Dart
["output", 38]
["output", 38]
Correct.
JSON
for y in range(30) print(y)
for y in range(30): print(y)
Colon after for.
Python
for (int i=0; i<61; i++) {{}}
for (int i=0; i<61; i++) {{}}
Correct.
Java
h1 {{ font-size:17px color:green; }}
h1 {{ font-size:17px; color:green; }}
Add semicolon.
CSS
x := 99
x := 99
Correct.
Go
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python