wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (val = 16) {{}}
if (val == 16) {{}}
Use ==.
Kotlin
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
let y: Int = 'info'
let y: String = 'info'
Fix type.
Swift
val result = 'test'
val result = "test"
Double quotes.
Kotlin
let data = 44; let data = 46;
let data = 44; data = 46;
Duplicate declaration.
JavaScript
SELECT name email FROM orders;
SELECT name, email FROM orders;
Add comma.
SQL
age: info status: hello,
age: info status: hello
Remove comma.
YAML
print 'world'
print('world')
print needs parentheses.
Python
var x = 7;
var x = 7;
Correct.
Dart
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
["world", 88]
["world", 88]
Correct.
JSON
foo
foo()
Add parentheses.
Kotlin
if c = 78
if c == 78
Use ==.
Go
for (int i=0; i<71; i++) {{}}
for (int i=0; i<71; i++) {{}}
Correct.
Java
$arr[86] = 5;
if (isset($arr[86])) $arr[86] = 5;
Check existence.
PHP
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
if (index = 47) {{}}
if (index == 47) {{}}
Use ==.
Java
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
$list[81]
if ($list.Count -gt 81) {{ $list[81] }}
Check bounds.
PowerShell
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
<user><age>info</age><age>93</age></user
<user><age>info</age><age>93</age></user>
Add closing >.
XML
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
switch(count){{ case 73: break; }}
switch(count){{ case 73: break; default: break; }}
Add default case.
Java
print 'world'
print 'world';
Add semicolon.
Perl
{{"name":"world" "age":83}}
{{"name":"world", "age":83}}
Add comma.
JSON
function render(foo:string){{return foo;}} render(23);
function render(foo:string){{return foo;}} render('world');
Pass correct type.
TypeScript
if (count = 91)
if (count == 91)
Use ==.
Scala
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
SELECT * FROM items WHRE id=93;
SELECT * FROM items WHERE id=93;
Fix WHERE.
SQL
if [ $z = 83 ]; then
if [ "$z" = 83 ]; then
Quote variable.
Shell
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(67);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(67);
Correct.
Node.js
def baz(temp): return temp + 1
def baz(temp): return temp + 1
Correct.
Python
var num int = 'message'
var num string = 'message'
Type mismatch.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
println('hello')
println("hello")
Double quotes.
Scala
val result: Int = 'world'
val result: String = 'world'
Fix type.
Kotlin
data.forEach(function(c) {{ console.log(c); }})
data.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
items[13]
if (items.indices.contains(13)) items[13]
Check index.
Kotlin
if ($bar = 78) {{}}
if ($bar -eq 78) {{}}
Use -eq.
PowerShell
if (b = 19)
if (b == 19)
Use ==.
R
name: hello age: 16
name: hello age: 16
Correct.
YAML
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
else print('value')
else: print('value')
Colon after else.
Python
let y: i32 = "hello";
let y: &str = "hello";
Type mismatch.
Rust
String data = 'message';
String data = "message";
Double quotes.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
// comment
/* comment */
Use /* */.
CSS
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
jwt.sign({{id:8}}, 'token');
jwt.sign({{id:8}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
x := 14
x := 14
Correct.
Go
for i=1,46 do print(i) end
for i=1,46 do print(i) end
Correct.
Lua
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
'hello' + 59
'hello' + 59.to_s
Convert int.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
local index = 15
local index = 15
Correct.
Lua
let z: Int = 'hello'
let z: String = 'hello'
Fix type.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
print 'result'
print('result')
print needs parentheses.
Python
switch(result){{ case 84: break; }}
switch(result){{ case 84: break; default: break; }}
Add default case.
Java
int foo = 'value';
String foo = 'value';
Type mismatch.
Dart
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
temp == '35'
temp === 35
Use strict equality.
JavaScript
function handle(count) print(count) end
function handle(count) print(count) end
Correct.
Lua
my @arr = (86,52,34);
my @arr = (86,52,34);
Correct.
Perl
function bar(): void {{ return 79; }}
function bar(): number {{ return 79; }}
Return type mismatch.
TypeScript
print 'result'
print 'result';
Add semicolon.
Perl
{{"title":"test" "age":4}}
{{"title":"test", "age":4}}
Add comma.
JSON
println('world')
println("world")
Double quotes.
Scala
SELECT * FROM orders WHRE id=87;
SELECT * FROM orders WHERE id=87;
Fix WHERE.
SQL
if (b = 44) {}
if (b == 44) {}
Use ==.
Dart
String name = 'result';
String name = 'result';
Correct.
Dart
values[66]
if (values.indices.contains(66)) values[66]
Check index.
Kotlin
var x int
var x int
Correct.
Go
if foo = 35
if foo == 35
Use ==.
Go
print('world')
print('world')
Correct.
R
'86' + 62
86 + 62
Avoid string coercion.
JavaScript
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
const y = 14; y = 4;
let y = 14; y = 4;
Cannot reassign const.
JavaScript
$arr[2] = 5;
if (isset($arr[2])) $arr[2] = 5;
Check existence.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
cin >> c;
int c; cin >> c;
Declare variable.
C++
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
if ($item = 40)
if ($item == 40)
Use ==.
Perl
function baz() {{ echo 'test'; }}
function baz() {{ echo 'test'; }}
Correct.
PHP
["value", 88]
["value", 88]
Correct.
JSON
if (data = 52) {{}}
if (data == 52) {{}}
Use ==.
Kotlin
if z = 1
if z == 1
Use ==.
MATLAB
if index = 7:
if index == 7:
Use == for comparison.
Python
<hr></hr>
<hr>
Self-closing.
HTML
items.forEach(function(c) {{ console.log(c); }})
items.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
class Person {{ int a; }};
class Person {{ public: int a; }};
Make public.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
66item = 10
item66 = 10
Variable cannot start with digit.
Python