wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
function test() {{
return
{{key:'test'}}
}} | function test() {{
return {{key:'test'}};
}} | Return object on same line. | JavaScript |
if (bar = 85) | if (bar == 85) | Use ==. | Scala |
<entry><age>world</age><name>7</name></entry | <entry><age>world</age><name>7</name></entry> | Add closing >. | XML |
var item int = 'message' | var item string = 'message' | Type mismatch. | Go |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
int* p = nullptr; *p=5; | int* p = new int; *p=5; | Allocate memory. | C++ |
void main() {{ print('message') }} | void main() {{ print('message'); }} | Add semicolon. | Dart |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
val foo: Int = 'message' | val foo: String = 'message' | Fix type. | Kotlin |
{{"name":"world",}} | {{"name":"world"}} | Remove trailing comma. | JSON |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
val a = 'data' | val a = "data" | Double quotes. | Kotlin |
if y = 2 | if y == 2 | Use ==. | Ruby |
[45, 29, 63 | [45, 29, 63] | Close bracket. | Python |
values[83] | if (length(values) >= 83) values[83] | Check length. | R |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
console.log('data' | console.log('data') | Close parenthesis. | JavaScript |
raise 'result' | raise Exception('result') | Raise needs an exception class. | Python |
if ($item = 86) | if ($item == 86) | Use ==. | Perl |
list.forEach(function(z) {{ console.log(z); }}) | list.forEach((z) => {{ console.log(z); }}) | Arrow functions are cleaner. | JavaScript |
if temp = 58: | if temp == 58: | Use == for comparison. | Python |
String index = 'world'; | String index = "world"; | Double quotes. | Java |
disp('hello') | disp('hello') | Correct. | MATLAB |
try {{ throw 'output'; }} catch(e) {{}} | try {{ throw new Error('output'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
<p>info <b>test</p></b> | <p>info <b>test</b></p> | Nest properly. | HTML |
#header {{ color: green; }} | #header {{ color: green; }} | Correct. | CSS |
'98' + 92 | 98 + 92 | Avoid string coercion. | JavaScript |
$list[42] | if ($list.Count -gt 42) {{ $list[42] }} | Check bounds. | PowerShell |
println('value') | println("value") | Double quotes. | Scala |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
<center>hello</center> | <div style='text-align:center;'>hello</div> | Use CSS. | HTML |
DELETE FROM orders WHERE age=43 | DELETE FROM orders WHERE age=43; | Add semicolon. | SQL |
SELECT COUNT(*) FROM items | SELECT COUNT(*) FROM items; | Missing semicolon. | SQL |
'world' + 75 | 'world' + 75.to_s | Convert int. | Ruby |
jwt.sign({{id:57}}, 'key'); | jwt.sign({{id:57}}, 'key', {{expiresIn:'1h'}}); | Add expiration. | Node.js |
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 |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
for (int i=0; i<72; i++) {{}} | for (int i=0; i<72; i++) {{}} | Correct. | Java |
.Order {{ color: #fff; }} | .Order {{ color: #fff; }} | Correct. | CSS |
list[37] | if (list.indices.contains(37)) list[37] | Check index. | Kotlin |
while read line; do echo $line; done < log.txt | while read line; do echo $line; done < log.txt | Correct. | Shell |
if (foo = 51) | if (foo == 51) | Use ==. | C++ |
if (index = 9) {{}} | if (index === 9) {{}} | Use === for equality. | JavaScript |
if (num = 81) {{}} | if (num == 81) {{}} | Use ==. | Kotlin |
my @arr = (83,74,94); | my @arr = (83,74,94); | Correct. | Perl |
int c = 'world'; | String c = 'world'; | Type mismatch. | Dart |
def foo():
print('result') | def foo():
print('result') | Indent function body. | Python |
for (int i=0; i<74; i++) {{}} | for (int i=0; i<74; i++) {{}} | Correct. | Java |
class User {{ int val; }}
obj.val=5; | class User {{ public int val; }}
obj.val=5; | Make field public. | Java |
if (data) console.log('yes') else console.log('no') | if (data) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
Order.save(); | Order.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
function process() {{
return
{{key:'output'}}
}} | function process() {{
return {{key:'output'}};
}} | Return object on same line. | JavaScript |
'output' + 57 | 'output' + 57.to_s | Convert int. | Ruby |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
if (index = 6) | if (index == 6) | Use ==. | R |
var z int = 'test' | var z string = 'test' | Type mismatch. | Go |
{{'title':'output'}} | {{"title":"output"}} | Use double quotes. | JSON |
println('test') | println("test") | Double quotes. | Scala |
baz | baz() | Add parentheses. | Kotlin |
div {{ color=blue; }} | div {{ color: blue; }} | Use colon. | CSS |
if (index = 41) {{}} | if (index == 41) {{}} | Use ==. | Java |
[14, 60, 3 | [14, 60, 3] | Close bracket. | Python |
cin >> a; | int a;
cin >> a; | Declare variable. | C++ |
x := 90 | x := 90 | Correct. | Go |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
fmt.Println 'message' | fmt.Println('message') | Missing parentheses. | Go |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
<div color=green> | <div style='color:green;'> | Use style attribute. | CSS |
let temp = 60; let temp = 8; | let temp = 60; temp = 8; | Duplicate declaration. | JavaScript |
int* p = nullptr; *p=5; | int* p = new int; *p=5; | Allocate memory. | C++ |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
$list[35] | if ($list.Count -gt 35) {{ $list[35] }} | Check bounds. | PowerShell |
{{'name':24, 'status' 42}} | {{'name':24, 'status':42}} | Colon missing. | Python |
[21, 24, 61 | [21, 24, 61] | Close bracket. | Ruby |
'world' + 1 | 'world' + str(1) | Can't add int to string. | Python |
if data = 54 | if data == 54 | Use ==. | MATLAB |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }}); | fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
echo output data | echo 'output data' | Quote to prevent splitting. | Shell |
h1 {{ font-size:46px color:green; }} | h1 {{ font-size:46px; color:green; }} | Add semicolon. | CSS |
arr[9] | if arr.indices.contains(9) {{ arr[9] }} | Check index. | Swift |
<img src='hello.jpg'> | <img src='hello.jpg' alt='desc'> | Add alt text. | HTML |
<person age=22> | <person age="22"> | Quote attribute. | XML |
list[27] | if (length(list) >= 27) list[27] | Check length. | R |
function compute() {{ echo 'output'; }} | function compute() {{ echo 'output'; }} | Correct. | PHP |
else
print('value') | else:
print('value') | Colon after else. | Python |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
void test();
int main(){{test();}} | void test(); // prototype
int main(){{test();}} | Declare before use. | C++ |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
{{"value":"hello" "name":7}} | {{"value":"hello", "name":7}} | Add comma. | JSON |
if temp > 26
puts 'test' | if temp > 26
puts 'test'
end | Add 'end'. | Ruby |
cin >> val
cout << val; | cin >> val;
cout << val; | Add semicolon. | C++ |
object User {{ def main(args: Array[String]) = println("result") }} | object User {{ def main(args: Array[String]): Unit = println("result") }} | Add return type Unit. | Scala |
class Product
def method
end
end | class Product
def method
end
end | Correct. | Ruby |
class User {{ int index; }}; | class User {{ public: int index; }}; | Make public. | C++ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.