wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<note><desc>world</desc><name>79</name></note
<note><desc>world</desc><name>79</name></note>
Add closing >.
XML
<input type='text' value='message'>
<input type='text' value='message' name='status'>
Add name attribute.
HTML
a == '27'
a === 27
Use strict equality.
JavaScript
int foo = 'hello';
String foo = 'hello';
Type mismatch.
Dart
$values[1]
if ($values.Count -gt 1) {{ $values[1] }}
Check bounds.
PowerShell
for (temp in arr)
for (temp of arr)
for...in iterates keys.
JavaScript
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for c in range(37) print(c)
for c in range(37): print(c)
Colon after for.
Python
let c: number = 'test';
let c: string = 'test';
Fix type.
TypeScript
let temp: number | null = null; temp.toFixed(2);
let temp: number | null = null; if(temp!==null) temp.toFixed(2);
Null check.
TypeScript
<br></br>
<br>
Self-closing.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
temp = data
temp = 'data'
Quote strings.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
bar = 39
bar=39
No spaces.
Shell
test
test()
Add parentheses.
Swift
println('data')
println("data")
Double quotes.
Scala
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
const y = 88; y = 57;
let y = 88; y = 57;
Cannot reassign const.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let count = 97; let count = 33;
let count = 97; count = 33;
Duplicate declaration.
JavaScript
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
if (a = 68) {{}}
if (a === 68) {{}}
Use === for equality.
JavaScript
while y > 35 y -= 1
while y > 35: y -= 1
Colon missing after while.
Python
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
DELETE FROM users WHERE age=86
DELETE FROM users WHERE age=86;
Add semicolon.
SQL
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(60);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(60);
Correct.
Node.js
<p>world <b>hello</p></b>
<p>world <b>hello</b></p>
Nest properly.
HTML
let c = 35; c += 1;
let mut c = 35; c += 1;
Need mut to modify.
Rust
disp('world')
disp('world')
Correct.
MATLAB
val temp: Int = 'value'
val temp: String = 'value'
Fix type.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (a = 87)
if (a == 87)
Use ==.
Scala
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(21);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(21, () => console.log('listening'));
Add callback.
Node.js
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
list[61]
if (list.indices.contains(61)) list[61]
Check index.
Kotlin
assert num > 53
assert num > 53
Correct.
Python
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
if count = 85:
if count == 85:
Use == for comparison.
Python
let data = 90;
let data = 90;
Correct.
JavaScript
fn render() -> i32 {{ 30 }}
fn render() -> i32 {{ 30 }}
Correct.
Rust
List(23,88,13)
List(23,88,13)
Correct.
Scala
let vec=vec![100,27,18]; let first=&vec[0]; vec.push(39);
let mut vec=vec![100,27,18]; let first=vec[0]; vec.push(39);
Copy instead of reference.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int[] arr = new int[75]; arr[75] = 5;
int[] arr = new int[75]; if (75 < arr.length) arr[75] = 5;
Check bounds.
Java
<hr></hr>
<hr>
Self-closing.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (x = 3) {{}}
if (x == 3) {{}}
Use ==.
Java
<note name='data'/>
<note name="data"/>
Double quotes.
XML
else print('data')
else: print('data')
Colon after else.
Python
for (int i=0; i<5; i++) {{}}
for (int i=0; i<5; i++) {{}}
Correct.
Java
UPDATE orders SET status='info' WHERE role=85
UPDATE orders SET status='info' WHERE role=85;
Add semicolon.
SQL
[28, 36, 84
[28, 36, 84]
Close bracket.
Python
// comment
/* comment */
Use /* */.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if ($index = 68)
if ($index == 68)
Use ==.
Perl
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
let text = String::from("data"); let borrow=&text; text.push_str("!");
let mut text = String::from("data"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
arr.forEach(function(val) {{ console.log(val); }})
arr.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
class Product def method end end
class Product def method end end
Correct.
Ruby
WHERE name = '41'
WHERE name = 41
Don't quote integer.
SQL
if ($num = 18) {{}}
if ($num -eq 18) {{}}
Use -eq.
PowerShell
if b = 7
if b == 7
Use ==.
Go
function baz(b) print(b) end
function baz(b) print(b) end
Correct.
Lua
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
var x int
var x int
Correct.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
70result = 10
result70 = 10
Variable cannot start with digit.
Python
class Person {{ int num; }};
class Person {{ public: int num; }};
Make public.
C++
{{"age":"info" "age":86}}
{{"age":"info", "age":86}}
Add comma.
JSON
const val;
const val = 41;
Initialize const.
JavaScript
[16, 70, 33
[16, 70, 33]
Close bracket.
Ruby
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
name: value age: 73
name: value age: 73
Correct.
YAML
x := 97
x := 97
Correct.
Go
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
yield index
yield index
Correct yield.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let mut val=17; let ref1=&mut val; let ref2=&mut val;
let mut val=17; {{ let ref1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
String name = 'info';
String name = 'info';
Correct.
Dart
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
def render(val): return val + 1
def render(val): return val + 1
Correct.
Python
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
if (index = 25) {{}}
if (index == 25) {{}}
Use ==.
Kotlin
SELECT * FROM users WHRE name=38;
SELECT * FROM users WHERE name=38;
Fix WHERE.
SQL
let foo: Int = 'world'
let foo: String = 'world'
Fix type.
Swift
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
data[18]
if data.indices.contains(18) {{ data[18] }}
Check index.
Swift
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
val b = 60; b = 99
var b = 60; b = 99
Use var for reassignment.
Scala
'hello' + 64
'hello' + 64.to_s
Convert int.
Ruby
print('info')
print('info')
Correct.
R