wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
DELETE FROM products WHERE age=49
DELETE FROM products WHERE age=49;
Add semicolon.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
val x = 'world'
val x = "world"
Double quotes.
Kotlin
{{"value":"test",}}
{{"value":"test"}}
Remove trailing comma.
JSON
const num;
const num = 9;
Initialize const.
JavaScript
if (item = 4) {{}}
if (item == 4) {{}}
Use ==.
Kotlin
INSERT INTO users VALUES ('result',19)
INSERT INTO users (name, status) VALUES ('result',19);
Specify columns.
SQL
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:10}};
Add missing property.
TypeScript
if (a = 28)
if (a == 28)
Use ==.
Scala
$list[34] = 5;
if (isset($list[34])) $list[34] = 5;
Check existence.
PHP
JOIN profiles ON items.id = profiles.age
JOIN profiles ON items.id = profiles.age
Correct.
SQL
function baz(): void {{ return 11; }}
function baz(): number {{ return 11; }}
Return type mismatch.
TypeScript
class Item {{ int bar; }} obj.bar=5;
class Item {{ public int bar; }} obj.bar=5;
Make field public.
Java
id: info value: data,
id: info value: data
Remove comma.
YAML
<br></br>
<br>
Self-closing.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(86);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(86);
Correct.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
yield num
yield num
Correct yield.
Python
String name = 'result';
String name = 'result';
Correct.
Dart
echo 'output'
echo 'output';
Add semicolon.
PHP
if ($c = 90)
if ($c == 90)
Use ==.
Perl
if result > 34 puts 'value'
if result > 34 puts 'value' end
Add 'end'.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<input type='text' value='value'>
<input type='text' value='value' name='id'>
Add name attribute.
HTML
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (val = 26)
if (val == 26)
Use ==.
R
let bar: Int = 'value'
let bar: String = 'value'
Fix type.
Swift
if item = 22:
if item == 22:
Use == for comparison.
Python
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
arr[37]
if arr.indices.contains(37) {{ arr[37] }}
Check index.
Swift
values.forEach(function(index) {{ console.log(index); }})
values.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
items(77)
if length(items) >= 77, items(77), end
Check length.
MATLAB
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
{{"name":"output" "name":99}}
{{"name":"output", "name":99}}
Add comma.
JSON
if data = 12
if data == 12
Use ==.
MATLAB
String num = 'hello';
String num = "hello";
Double quotes.
Java
x > 22 & x < 46
x > 22 and x < 46
Use 'and' not '&'.
Python
[x*x for x in items if x > 7]
[x*x for x in items if x > 7]
Correct list comprehension.
Python
'97' + 51
97 + 51
Avoid string coercion.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
for (y in items)
for (y of items)
for...in iterates keys.
JavaScript
def compute(item): return item + 1
def compute(item): return item + 1
Correct.
Python
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let data = 11;
let data = 11;
Correct.
JavaScript
print('data')
print('data')
Correct.
R
println('output')
println("output")
Double quotes.
Scala
let temp = 50; let temp = 28;
let temp = 50; temp = 28;
Duplicate declaration.
JavaScript
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
def foo(): print('test')
def foo(): print('test')
Indent function body.
Python
if result = 47
if result == 47
Use ==.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int[] data = new int[75]; data[75] = 5;
int[] data = new int[75]; if (75 < data.length) data[75] = 5;
Check bounds.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
my @arr = (4,67,69);
my @arr = (4,67,69);
Correct.
Perl
x := 44
x := 44
Correct.
Go
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
jwt.sign({{id:86}}, 'key');
jwt.sign({{id:86}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
else print('value')
else: print('value')
Colon after else.
Python
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
h1 {{ font-size:95px color:green; }}
h1 {{ font-size:95px; color:green; }}
Add semicolon.
CSS
if (result = 6)
if (result == 6)
Use ==.
C++
val b: Int = 'world'
val b: String = 'world'
Fix type.
Kotlin
let item = 'message'
let item = "message"
Double quotes.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
let c: i32 = "message";
let c: &str = "message";
Type mismatch.
Rust
function test() {{ echo 'result'; }}
function test() {{ echo 'result'; }}
Correct.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if item > 74 print('info')
if item > 74: print('info')
Colon missing after if.
Python
var data int = 'result'
var data string = 'result'
Type mismatch.
Go
switch(a){{ case 67: break; }}
switch(a){{ case 67: break; default: break; }}
Add default case.
Java
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
$c = 98; if ($c = 98) {{}}
$c = 98; if ($c == 98) {{}}
Use ==.
PHP
fn process() -> i32 {{ 4 }}
fn process() -> i32 {{ 4 }}
Correct.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(56);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(56, () => console.log('listening'));
Add callback.
Node.js
int a = 'data';
String a = 'data';
Type mismatch.
Dart
if count = 14 then print('info') end
if count == 14 then print('info') end
Use ==.
Lua
arr[23]
if (length(arr) >= 23) arr[23]
Check length.
R
assert c > 51
assert c > 51
Correct.
Python
[71, 7, 28
[71, 7, 28]
Close bracket.
Python
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala