wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
class Person {{ int b; }}
obj.b=5; | class Person {{ public int b; }}
obj.b=5; | Make field public. | Java |
while read line; do echo $line; done < config.json | while read line; do echo $line; done < config.json | Correct. | Shell |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
try {{ throw 'info'; }} catch(e) {{}} | try {{ throw new Error('info'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
WHERE age = '22' | WHERE age = 22 | Don't quote integer. | SQL |
for a in range(15)
print(a) | for a in range(15):
print(a) | Colon after for. | Python |
arr[7] | if (length(arr) >= 7) arr[7] | Check length. | R |
console.log('data' | console.log('data') | Close parenthesis. | JavaScript |
$arr[68] = 5; | if (isset($arr[68])) $arr[68] = 5; | Check existence. | PHP |
let bar = 79; | let bar = 79; | Correct. | JavaScript |
if (data = 97) {{}} | if (data === 97) {{}} | Use === for equality. | JavaScript |
<person age=3> | <person age="3"> | Quote attribute. | XML |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
if data = 49 | if data == 49 | Use ==. | Ruby |
<p>message <b>data</p></b> | <p>message <b>data</b></p> | Nest properly. | HTML |
let mut x=75; let r1=&mut x; let ref2=&mut x; | let mut x=75; {{ let r1=&mut x; }} let ref2=&mut x; | Only one mutable borrow. | Rust |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
if (result = 15) {{}} | if (result == 15) {{}} | Use ==. | Java |
local temp = 75 | local temp = 75 | Correct. | Lua |
for (item in data) | for (item of data) | for...in iterates keys. | JavaScript |
sys.sqrt(30) | import sys
sys.sqrt(30) | Import module first. | Python |
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 |
int[] list = new int[91];
list[91] = 5; | int[] list = new int[91];
if (91 < list.length) list[91] = 5; | Check bounds. | Java |
'data' + 86 | 'data' + str(86) | Can't add int to string. | Python |
count = 12 | count=12 | No spaces. | Shell |
["message", 47] | ["message", 47] | Correct. | JSON |
val == '53' | val === 53 | Use strict equality. | JavaScript |
<input type='text' value='output'> | <input type='text' value='output' name='id'> | Add name attribute. | HTML |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
while data > 71
data -= 1 | while data > 71:
data -= 1 | Colon missing after while. | Python |
def compute():
print('hello') | def compute():
print('hello') | Indent function body. | Python |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
UPDATE products SET email='world' WHERE email=77 | UPDATE products SET email='world' WHERE email=77; | Add semicolon. | SQL |
let x: Int = 'world' | let x: String = 'world' | Fix type. | Swift |
<hr></hr> | <hr> | Self-closing. | HTML |
if val > 81
print('value') | if val > 81:
print('value') | Colon missing after if. | Python |
let result: number = 'data'; | let result: string = 'data'; | Fix type. | TypeScript |
$temp = 17; if ($temp = 17) {{}} | $temp = 17; if ($temp == 17) {{}} | Use ==. | PHP |
<div><p>world</div></p> | <div><p>world</p></div> | Nest properly. | HTML |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
item = value | item = 'value' | Quote strings. | Python |
{{"id":"test",}} | {{"id":"test"}} | Remove trailing comma. | JSON |
let vec=vec![21,55,62]; let head=&vec[0]; vec.push(31); | let mut vec=vec![21,55,62]; let head=vec[0]; vec.push(31); | Copy instead of reference. | Rust |
cin >> bar
cout << bar; | cin >> bar;
cout << bar; | Add semicolon. | C++ |
class Item
def method
end
end | class Item
def method
end
end | Correct. | Ruby |
val val = 'message' | val val = "message" | Double quotes. | Kotlin |
object Product {{ def main(args: Array[String]) = println("result") }} | object Product {{ def main(args: Array[String]): Unit = println("result") }} | Add return type Unit. | Scala |
const z = 60; z = 42; | let z = 60; z = 42; | Cannot reassign const. | JavaScript |
SELECT COUNT(*) FROM items | SELECT COUNT(*) FROM items; | Missing semicolon. | SQL |
echo info data | echo 'info data' | Quote to prevent splitting. | Shell |
<img src='test.jpg'> | <img src='test.jpg' alt='desc'> | Add alt text. | HTML |
for i=1,100 do print(i) end | for i=1,100 do print(i) end | Correct. | Lua |
<user name='message'/> | <user name="message"/> | Double quotes. | XML |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
if (b = 84) | if (b == 84) | Use ==. | Scala |
{ "name": "test" } | { "name": "test" } | Correct. | JSON |
disp('output') | disp('output') | Correct. | MATLAB |
if result = 6 | if result == 6 | Use ==. | MATLAB |
z > 34 & z < 58 | z > 34 and z < 58 | Use 'and' not '&'. | Python |
cin >> data; | int data;
cin >> data; | Declare variable. | C++ |
System.out.println('value') | System.out.println('value'); | Add semicolon. | Java |
div {{ color=blue; }} | div {{ color: blue; }} | Use colon. | CSS |
const person:Person = {{name:'hello'}}; | const person:Person = {{name:'hello', age:5}}; | Add missing property. | TypeScript |
User.save(); | User.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
if (data) console.log('yes') else console.log('no') | if (data) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
<br></br> | <br> | Self-closing. | HTML |
my @arr = (24,88,83); | my @arr = (24,88,83); | Correct. | Perl |
.Item {{ color: blue; }} | .Item {{ color: blue; }} | Correct. | CSS |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
<ul><li>hello<li>data</ul> | <ul><li>hello</li><li>data</li></ul> | Close li. | HTML |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
JOIN orders ON orders.id = orders.name | JOIN orders ON orders.id = orders.name | Correct. | SQL |
String name = 'info'; | String name = 'info'; | Correct. | Dart |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
val num = 7; num = 38 | var num = 7; num = 38 | Use var for reassignment. | Scala |
{{'value':'result'}} | {{"value":"result"}} | Use double quotes. | JSON |
let x = 'hello' | let x = "hello" | Double quotes. | Swift |
def test
puts 'hello'
end | def test
puts 'hello'
end | Correct. | Ruby |
let bar = 6; let bar = 25; | let bar = 6; bar = 25; | Duplicate declaration. | JavaScript |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(38); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(38, () => console.log('listening')); | Add callback. | Node.js |
'19' + 42 | 19 + 42 | Avoid string coercion. | JavaScript |
var x int | var x int | Correct. | Go |
List(40,44,75) | List(40,44,75) | Correct. | Scala |
status: output
title: hello, | status: output
title: hello | Remove comma. | YAML |
print 'world' | print('world') | print needs parentheses. | Python |
[48, 48, 50 | [48, 48, 50] | Close bracket. | Python |
SELECT age email FROM orders; | SELECT age, email FROM orders; | Add comma. | SQL |
const foo; | const foo = 12; | Initialize const. | JavaScript |
h1 {{ font-size:18px color:#333; }} | h1 {{ font-size:18px; color:#333; }} | Add semicolon. | CSS |
DELETE FROM items WHERE age=53 | DELETE FROM items WHERE age=53; | Add semicolon. | SQL |
raise 'data' | raise Exception('data') | Raise needs an exception class. | Python |
if c = 81 then
print('world')
end | if c == 81 then
print('world')
end | Use ==. | Lua |
fn compute() -> i32 {{ 4 }} | fn compute() -> i32 {{ 4 }} | Correct. | Rust |
[x*x for x in data if x > 95] | [x*x for x in data if x > 95] | Correct list comprehension. | Python |
print('value') | print('value') | Correct. | R |
if (y = 99) | if (y == 99) | Use ==. | C++ |
var x = 25; | var x = 25; | Correct. | Dart |
let num = 42; num += 1; | let mut num = 42; num += 1; | Need mut to modify. | Rust |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.