[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

TAs: Post your students' hilariously shitty code

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 63
Thread images: 5

File: graduate.png (82KB, 694x801px) Image search: [Google]
graduate.png
82KB, 694x801px
Former and current programming teachers and TAs, I know you saved that shit, so post it.

My contribution:

>Assignment: given a social security number of format "123-45-6789", output the two middle digits.

Student submission:
String[] securityDigits = securityNumber.split("-");
for(int index = 0; index < securityDigits.length; index++)
{
if(index == 2)
{
System.out.println(securityDigits[index]);
}
}
>>
4chan is full of NEETs, there are no TAs here
>>
File: 9f9.jpg (28KB, 613x533px) Image search: [Google]
9f9.jpg
28KB, 613x533px
>>57965749
Not a TA, but your example reminds me of a programming assignment where we had to take two strings of the format "HH:MM:SS" and add them together using clock rules. Most students had maybe 20 to 30 lines of code. One guy had over 500 lines of code. mfw I glanced at it.
>>
>>57965749
holy shit what a retard
>>
>>57965749
Reeks like someone who only ever learned to use arrays by iterating through them.
The hell were your courses teaching anyway?
>>
>>57966408
There were good students who got it right.

But every semester we had a few of these people. When a homework assignment was coming up, they just looked through the previous week's powerpoints and slapped together seemingly random combinations of the the ideas we introduced them to.

>surely i will need an if statement for this assignment because we just talked about conditionals in class

>i will add a loop here, i don't know why, but the teacher was talking about them

To be fair the professor was pretty bad. She was teaching Java but could hardly operate Windows 7; it could take her 20 minutes to find the powerpoint she wanted for a lecture. I had to pick up a lot of the slack as TA.
>>
>>57966649
>inept professor breeding inept programmers
God i fucking love college
>>
>>57965749
>>Assignment: given a social security number of format "123-45-6789", output the two middle digits.
kek hahahaha, sounds like an easy assignment.

also god bless you TA, all the TA's I've had are a godsend, great friendly people who know everything <3 xoxox
>>
>>57966030
>One guy had over 500 lines of code.
what the fuck

did you save it
>>
>>57966649

Kinda makes sense to try implementing all the new stuff learned in class. Hell it's just an introductory programming course, if you can't experiment there, where can you?
>>
>>57966649
What country?
>>
>>57966649
a well-designed course WOULD build on itself like that
>>
>>57966030
shiit hahah cool stuff
I woulda use a date parser thjig, convert to unix timestamp, sum and then date format to the specified format. would that work?
>>
>>57968447
using standard libraries is usually cheating on assignments that small
>>
>>57966649
>To be fair the professor was pretty bad. She was teaching Java but could hardly operate Windows 7

oh boy
when we did java our TA basically said he wouldnt help anyone who didn't use OSX or Linux because Windows is a fuckfest for using cli (which is what we were doing, no Eclipse only text editor)
I'm pretty sure Windows and Java play alright tho -- but I remember a student quitting because they were ""bullied"" by the TA, who was the best TA we ever had.
>>
>>57965749
>>57966100
This really isn't that bad if submitted by a beginner, I've seen way worse. I remember sometimes over thinking/complicating solutions when I first got started.
>>
>>57968480
>TA basically said he wouldnt help anyone who didn't use OSX or Linux because Windows is a fuckfest

I can't take a person like that seriously.
>>
>>57968460
yea, or at least missing the point, I remember in week 1 we had a task to reverse a string in java, and some people ended up googling and using a StringBuilder and .reverse() on it or a similar method, which is good practise to learn what a stringbuilder is and what it does, but most people didn't. & they missed out on practising a for-loop
>>
>>57968561
when things break on windows you never know how to fix them
when they break on uni you know how to fix it, always.
he wouldn't help anyone because fixing shit on windows is a waste of time
>>
>>57968306
And this is why algorithm challenges in interviews are a thing.
>>
>>57968580
It's just fucking Java and a text-editor.
He doesn't have to fix their windows but if he refuses to help them with the java-related issues because of their choice of OS he's not fit for his position.
>>
(define (index-of c s i)
(cond
[(= 0 (string-length s)) -1]
[(string=? (substring s 0 1) c) i]
[else (index-of c (substring s 1) (+ 1 i))]))
>>
Production code. I need to use one of my co-worker's extraction methods to pull email, name, and phone number from a body of text.

Except it's not a method or function. It's code that you include in your code. You set a variable "body" to the text you want to extract from, then you include the code. The code will evaluate and initialize the variables "firstname", "lastname", "email", and "phone number" for you. Yes, if you're using any of those variables before, well fuck you--it's replaced by these new values.
>>
>>57968564
Or, you could come up with a task where a loop actually is a good idea to use.
>>
>>57968634
lol he'll help with java shit and unix shit but not windows shit
>>
>>57968661
Then
>TA basically said he wouldnt help anyone who didn't use OSX or Linux

was a lie?
>>
>>57968580
You have to know how to fix things when using linux, because shit is always breaking and if you didn't know how to fix anything you would actually have to spend money on a professional-grade OS that does work, instead of using your free hobby OS which you pay for with time and effort fixing stupid bullshit.
>>
>>57968639
You just copy-paste the code in there?
>>
>>57966030

If you didn't save that shit to pastebin, you're dead to me
>>
>>57968703
No, it's a file that you import.

It's shitty ColdFusion, so you can include code from anywhere and it will take on its environment; but even CF can define functions. So I don't know what the fuck he's smoking when he wrote it, but it works so I gotta use it.
>>
File: 1362540725023.jpg (21KB, 251x205px) Image search: [Google]
1362540725023.jpg
21KB, 251x205px
>>57968729
>ColdFusion
When you leave this job... are you actually going to put this on your resume? I'd make something up. Say you had cancer.
>>
>>57965749
Not a TA, but in one of my courses that had a group project last year, we had a guy writing useless functions to make it seem like he was contributing.

It was shit like taking taking the input given to his function, checking if it was equal to itself and then returning true if it was.
>>
>>57968792
They use other shit like nodejs and C#. This is just a legacy piece that somehow didn't get rewritten.
>>
>>57968639
Put some special chars around the text. Like %%THIS%%
>>
>>57968416
>>57968721

Sadly, I didn't have a chance to save it.

It looked like he didn't get the concept of "mod 60", nor did he get the concept of "if the sum is greater than 60 then subtract 60", so he used quite a bit of code to implement a -- let's call it "innovative" -- alternative approach that involved very extensive use of "if" statements. I think your imagination can fill in the rest.

>>57968447

Well sure, but it turns out we were given a list of approved functions we could call, and there was nothing more powerful than simple character I/O on the list.
>>
>>57968447
public static void ayy(String s1, String s2) {
String[] sArgs = new String[]{s1, s2};
int hours = 0;
int minutes = 0;
int seconds = 0;
for (String sArg : sArgs) {
String[] split = sArg.split(":");
int tempSec = 0;
for (int j = 0; j <= 2; j++) {
int sec = Integer.parseInt(split[j]);
for (int k = j; k < 2; k++) {
sec = sec * 60;
}

tempSec = tempSec + sec;
}
seconds = seconds + tempSec;
}

int hrs = 60 * 60;
while (seconds >= hrs) {
seconds = seconds - hrs;
hours++;
}

hours = hours % 24;
int mins = 60;
while (seconds >= mins) {
seconds = seconds - mins;
minutes++;
}

System.out.printf("%1$02d:%2$02d:%3$02d", hours, minutes, seconds);
}
>>
>>57965749
as a 'beginner' this looks like something i could write, how would you write it better?

genuinely interested in writing better code
>>
>>57966649
>When a homework assignment was coming up, they just looked through the previous week's powerpoints and slapped together seemingly random combinations of the the ideas we introduced them to.
I did that for my VB class and it worked just fine. Got the top score in the class despite not programming at all in my free time.
>>
>>57969713
I would just print the characters 4 and 5 of the string
>>
>>57969805
Slapping together the different programming ideas you've been introduced to throughout your study sounds like programming to me m80.
>>
>>57965749
I'm very confused but I know a bit about arrays. Couldn't he have just done System.out.println(securityDigits[1]) ?
>>
>>57970083
I missed the keyword, "randomly."

Still, the slides are a major hint to what you need to do. Like if you haven't been introduced to loops yet you don't use a loop. Takes a monkey to not figure it out.
>>
File: 1473645092023.jpg (49KB, 500x718px) Image search: [Google]
1473645092023.jpg
49KB, 500x718px
>>57969713
Observe
String[] securityDigits = securityNumber.split("-");
System.out.println(securityDigits[1]);
>>
>>57968635
What hellspawn of a syntax is this? It clearly isn't lisp. What the fuck are square brackets doing there? Why is there a ? at the end of string=?
>>
File: 1475046122201.jpg (69KB, 1000x667px) Image search: [Google]
1475046122201.jpg
69KB, 1000x667px
>>57970133
"randomly" changes nothing broski.

You would be not be programming any less by rolling a dice to decide which approach to go with for every little task.
>>
>>57970245
That's very zen dude. Too bad my professor would not have any of that.
>>
>>57970194
I didn't post it but I know the language. It is scheme. the brackets are cases for the switch statement its in. (cond starts a switch. each bracket opens a case. the ? indicates it returns a boolean which part of schemes naming conventions for functions.
>>
>>57970194
Also the brackets are completely optional. Makes no difference to the compilers. Personal taste/syntax
>>
>>57965749
>>57969713
>>57970142
public static void youAreLikeALittleBabyWatchThis(String s) {
System.out.println(s.split("-")[1]);
}
>>
>>57965749
I am pretty sure I have written code that I regret in my younger days.
>>
>>57969713
use regex
\b\d{3}\-(\d{2})\-\d{4}\b
the capturing group contains the two middle digits
>>
bool x = true;
if (*(int *)x == 1) {
return true
} else {
return false
}
>>
import Data.List.Split

f ssn = splitOn "-" ssn !! 1
>>
>>57970646
The student knows pointer type-casting at least. Useful for some problems in the past.

float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;

x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed

return y;
}
>>
>>57970693
>useful for some problems in the past.
C qsort literally expects you to typecast if you want to sort things.
>>
>>57970693
thanks, id software
>>
>>57965749
Whats wrong with this solution other than him picking the wrong index? If he put index == 1 it would work perfectly.
>>
>>57970767
The loop wasn't even needed.
>>
>>57970711
Void pointer casts are different.
>>
>>57970809
no, they're literally typecasting

Q_rsqrt() is typepunning, purposefully casting to an integer pointer so you can fuck with the floating point mantissa and exponent manually.
>>
>>57970841
>they're literally typecasting
Right. I thought you were comparing void pointer casts to type punning.
They're two different things, and just casting and using a pointer like that is undefined behaviour.
>>
>>57970521
did no one teach you good coding practices?
>>
>>57968806
Toppest of keks
At least he did something desu.
Thread posts: 63
Thread images: 5


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.