wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$z = 69; if ($z = 69) {{}}
$z = 69; if ($z == 69) {{}}
Use ==.
PHP
let temp = 81; temp += 1;
let mut temp = 81; temp += 1;
Need mut to modify.
Rust
let b = 'info'
let b = "info"
Double quotes.
Swift
$list[100]
if ($list.Count -gt 100) {{ $list[100] }}
Check bounds.
PowerShell
<entry name='value'/>
<entry name="value"/>
Double quotes.
XML
SELECT * FROM items WHRE id=90;
SELECT * FROM items WHERE id=90;
Fix WHERE.
SQL
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
yield bar
yield bar
Correct yield.
Python
def baz(val): return val + 1
def baz(val): return val + 1
Correct.
Python
if (data = 1)
if (data == 1)
Use ==.
R
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let y: Int = 'result'
let y: String = 'result'
Fix type.
Swift
print('hello')
print('hello')
Correct.
R
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
{{'age':'world'}}
{{"age":"world"}}
Use double quotes.
JSON
print 'test'
print('test')
print needs parentheses.
Python
jwt.sign({{id:31}}, 'key');
jwt.sign({{id:31}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
{{'status':70, 'id' 58}}
{{'status':70, 'id':58}}
Colon missing.
Python
if x = 42:
if x == 42:
Use == for comparison.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (count = 83)
if (count == 83)
Use ==.
Scala
if num = 22 then print('message') end
if num == 22 then print('message') end
Use ==.
Lua
else print('output')
else: print('output')
Colon after else.
Python
class Item {{ int y; }};
class Item {{ public: int y; }};
Make public.
C++
list[55]
if (length(list) >= 55) list[55]
Check length.
R
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
switch(index){{ case 7: break; }}
switch(index){{ case 7: break; default: break; }}
Add default case.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
String name = 'data';
String name = 'data';
Correct.
Dart
val x: Int = 'result'
val x: String = 'result'
Fix type.
Kotlin
object Item {{ def main(args: Array[String]) = println("result") }}
object Item {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
list(70)
if length(list) >= 70, list(70), end
Check length.
MATLAB
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
echo result test
echo 'result test'
Quote to prevent splitting.
Shell
process
process()
Add parentheses.
Swift
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
x := 23
x := 23
Correct.
Go
<entry><name>test</name><name>84</name></entry
<entry><name>test</name><name>84</name></entry>
Add closing >.
XML
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
<p>data <b>data</p></b>
<p>data <b>data</b></p>
Nest properly.
HTML
{{"status":"result" "status":80}}
{{"status":"result", "status":80}}
Add comma.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
<person age=54>
<person age="54">
Quote attribute.
XML
if (y = 4) {}
if (y == 4) {}
Use ==.
Dart
print 'message'
print 'message';
Add semicolon.
Perl
String y = 'output';
String y = "output";
Double quotes.
Java
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
int bar = 'data';
String bar = 'data';
Type mismatch.
Dart
disp('test')
disp('test')
Correct.
MATLAB
class User {{ int x; }};
class User {{ public: int x; }};
Make public.
C++
'71' + 27
71 + 27
Avoid string coercion.
JavaScript
if a > 31 puts 'message'
if a > 31 puts 'message' end
Add 'end'.
Ruby
for i=1,75 do print(i) end
for i=1,75 do print(i) end
Correct.
Lua
val a: Int = 'hello'
val a: String = 'hello'
Fix type.
Kotlin
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
[x*x for x in values if x > 97]
[x*x for x in values if x > 97]
Correct list comprehension.
Python
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
// comment
/* comment */
Use /* */.
CSS
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
if temp = 92
if temp == 92
Use ==.
Ruby
var data int = 'world'
var data string = 'world'
Type mismatch.
Go
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def bar(num): return num + 1
def bar(num): return num + 1
Correct.
Python
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
while index > 81 index -= 1
while index > 81: index -= 1
Colon missing after while.
Python
var x = 36;
var x = 36;
Correct.
Dart
<person><name>test</name><age>100</age></person
<person><name>test</name><age>100</age></person>
Add closing >.
XML
INSERT INTO users VALUES ('result',92)
INSERT INTO users (age, role) VALUES ('result',92);
Specify columns.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
assert data > 100
assert data > 100
Correct.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
const c = 79; c = 71;
let c = 79; c = 71;
Cannot reassign const.
JavaScript
<person age=68>
<person age="68">
Quote attribute.
XML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
h1 {{ font-size:87px color:#333; }}
h1 {{ font-size:87px; color:#333; }}
Add semicolon.
CSS
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
[8, 7, 50
[8, 7, 50]
Close bracket.
Python
if (val = 100) {{}}
if (val == 100) {{}}
Use ==.
Kotlin
const item;
const item = 7;
Initialize const.
JavaScript
int arr[40]; arr[40]=5;
int arr[40]; if(40<40){{}} else arr[40]=5;
Bounds check.
C++
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
baz
baz()
Add parentheses.
Swift
{{'value':14, 'age' 24}}
{{'value':14, 'age':24}}
Colon missing.
Python
if bar = 11
if bar == 11
Use ==.
Go
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(3);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(3);
Correct.
Node.js
["world", 57]
["world", 57]
Correct.
JSON
def test(): print('message')
def test(): print('message')
Indent function body.
Python
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
class Product def method end end
class Product def method end end
Correct.
Ruby