[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]

/tech/ - Technology

Catalog

Name
Email
Subject
Comment *
File
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Flag
Oekaki
Show oekaki applet
(replaces files and can be used instead)
Options
Password (For file and post deletion.)

Allowed file types:jpg, jpeg, gif, png, webm, mp4, pdf
Max filesize is 8 MB.
Max image dimensions are 10000 x 10000.
You may upload 3 per post.


File: 1455537830386.png (10.56 KB, 647x88, 647:88, Screenshot from 2016-02-15….png)

 No.522593

what happened to cs grad thread

bring back cs grad thread

here is some graduate level computer science I did this afternoon

 No.522694

File: 1455551722786.png (17.56 KB, 533x357, 533:357, Capture.PNG)


 No.522737

File: 1455556509797.png (136.38 KB, 828x801, 92:89, yandere.png)


 No.522749

>>522737

You should put a knife in her hand, instead of a degree.

Please tell me that this code is old and yandev fixed it


 No.522753

>>522737

>Everything about this

>Allman style

>CamelCase

>String comparison

>Unnecessary hardcoded if clauses

>(float) 6

>Dubious UpdateLabel parameters

Is this yandere simulator code? He wasn't wrong when he said he didn't want to get another programmer because of the code.


 No.522765

File: 1455560310884-0.png (Spoiler Image, 125.17 KB, 828x801, 92:89, we_wuz_programmerz_n_shiet.png)

File: 1455560310885-1.png (Spoiler Image, 96.16 KB, 828x801, 92:89, registry.png)

>>522753

Yes.

>>522749

I thought of that too, but I already posted it by then.

It's from the January 15th build. You could open up any script, stop at random and be able to put what you see into a CS meme. I doubt it's changed by then. Storing game state in playerPrefs, having 300 lines of nothing but public fields in every class, mazes of if if-else-s everywhere you look and coupling tighter than Yandere-chan's crusty vagina is not something you can fix in a week. It's like he read Code Complete and then decided to do the exact opposite of everything it said.


 No.522782

File: 1455561447846.jpeg (349.97 KB, 2024x1019, 2024:1019, 1455461080755.jpeg)

>>522765

I feel fucking insulted

how did he even manage to run the game at all


 No.522793

>>522753

>Allman style

>bad

Fucking javamonkeys.


 No.522800

>>522793

>Anything that isn't 1TBS/K&R in a C style language

>Not completely retarded


 No.522817

File: 1455563829128.jpg (5.53 KB, 230x220, 23:22, index.jpg)

>>522765

>It's like he read Code Complete and then decided to do the exact opposite of everything it said.

nailed it


 No.522821

>>522782

>>522749

>>522753

Actually I just saw his update where he said he optimized the code. I'm gonna take a look at it.


 No.523230

>>522765

>using the registry like that

what is this windows 95 era again?


 No.523287

>>522694

What's wrong with that?


 No.523393

>>523287

You serious m8?


 No.523423

From some collision code in a top-down shooter. It took me like an hour to pinpoint this shit.

return (-b - sqrt(b*b - 4*a*c))/2*a;


 No.523424

>>523287

The use of MIME types


 No.523427

>>522753

>>allman style

Undergrads pls.


 No.523442

>>522694

Should you use magic numbers to identify filetype instead? Maybe with an external library?


 No.523446

>>523423

Is it the brackets being wrong, should it be

return (-b - (sqrt((b * b) - (4 * a * c))/(2  *a))


 No.523459

>>523446

Yeah. I looked at it like half a dozen times while trying to find the error and missed it every time. It looked so simple I never wrote a test for it, and the code kinda worked at low velocities, when a was close to 1 so I thought it was something else entirely.


 No.523462

>>523287

>>523393

Nothing wrong with it.


 No.523520

>>523287

>>523393

>>523462

Not >>522694 guy, but number of checks seem to be large enough to use a map container instead of a bunch of else-ifs


 No.523549

>>523520

Map would fuck it up. Why the fuck would you mess with this function. It's simple, easy to understand, O(1).

With maps you'd have to have a separate data structure to store the keys and values. Why waste the space?

The number of checks is not large enough to justify using a map container. You'd have to be talking about hundreds of checks. This is 7.


 No.523550

>>523520

>>523549

Are we all just ignoring that the proper solution would be calling out to an external library for MIME type detection?


 No.523558

>>523550

Yes, there's a function that already does that, but I'm just saying there's an intrinsic merit to simple ifelse chains. Just cuz /tech/ has a hardon for bashing 'em doesn't mean they aren't the right choice sometimes.


 No.523560

>>523558

Here's how I would write that code anyway

string ext = extension(filename);

switch (ext) {
case "html":
case "htm":
return "text/html";
case "jpg"
return "image/jpeg";
default:
return "text/plain";
}


 No.523580

>>523560

If you've never ready cracking the coding interview, you should. It's a good book that explains there's no technical computational difference between what you wrote and what's in the pic.

BUT

I like the way you wrote that code snippet better. It's easier to read. Better style.


 No.523584

>>523580

>If you've never ready cracking the coding interview, you should. It's a good book that explains there's no technical computational difference between what you wrote and what's in the pic.

I'm not sure why you're thinking about the computational difference to begin with. I care far more about how readable and maintainable something is than how it's mapped onto the hardware.

It could be implemented with jump tables or hash maps for all I care, I don't give a single shit. This code is not going to be a performance bottleneck.

Anything else is premature optimization.


 No.523598

File: 1455648350822.jpg (43.75 KB, 718x402, 359:201, untitled.jpg)

>>523549

Hashmaps are close to O(1). If this check is not in a performance critical code, that's neglible. And this amount of space is practically free. Difference between a set of elseifs and a map is that with map you have code that does the check and the actual mapping separated, which makes it more readable/extendable/easier to maintain. It's probably an overkill if you know that you'll always have only 7 checks but eh.

Or maybe you can write it like this >>523560 if your language allows strings in switch statements. Damn java or c# or whatever it is.


 No.523602

>>523549

>why people make fun of webdevs


 No.523603

>>523598

>Hashmaps are close to O(1).

This triggers me

1. With <10 values, the constant factor matters more than the asymptotic behavior ever will. O(n) code might easily be faster than O(1) code by a few orders of magnitude on such small scales.

Asymptotic behavior is a lying sack of shit even on large scales, because usually the code with better cache locality and lower constant factors will beat the code that has better theoretical asymptotics but shit real-world properties.

>Damn java or c# or whatever it is.

C# and Java both allow this


 No.523604

>>523560

A single return statement at the end, and breaks in the switch is preferable to that.


 No.523605

>>523604

Said noone ever


 No.523608


 No.523610

>>523549

Your entire argument hinges on the assumption that this will never ever be expanded, after which you can easily (mis)represent any algorithm as being O(1), since you just defeated the entire purpose of the big-O notation and algorithm analysis by putting an artificial upper cap on the amount of data to be processed.

In any real world scenario a function like this will use or be eventually expanded with many more key-value pairs, after which this approach quickly turns into an unmaintainable mess.

As soon as you stop assuming that it will only use these specific mime types the whole thing falls apart. It wastes the programmer's and the company's time, because adding any more entries would require modifying the code and recompiling the module each time and you would end up with an if-else chain hundreds of lines long that runs in O(n) time. That is a lot of time and performance wasted on a lack of foresight.


 No.523612

>>523603

It never makes sense to take data and turn it into a block of code from a correctness perspective and almost never from a performance perspective. Even without a hash (but you should use a hash), this shit code could have been written in terms of a 2D table that eliminated all that copy paste of code and eliminated chances to fuck up like having an if rather than an else in there somewhere.


 No.523614

>>523612

This. Completely forgot about the fact that you could make a mistake and end up wasting weeks tracking down some weird as shit behavior.


 No.523616

>>523614

You're arguing that it's a CS Grad-tier snippet on the basis that is a mistake was made he would have to track down a bug?


 No.523620

tbf using a HashMap is CS Graduate-tier. 'I learnt about this thing in Data Structures 101 and we should use it indiscriminately'.


 No.523623

>>523616

No. Read it again.


 No.523626

>>523620

What data structure would you use to store a mapping between two strings?


 No.523640

>>523612

It never makes sense to lose sleep over the performance characteristics of a 5-line function that does a switch/case.


 No.523701

>>523549

>Simple, easy to understand

>No mention of simple to maintain

>Why waste the space

>Code and static allocations don't waste space

>Implies O(1) like he knows complexity theory

>Talks about the other solution like it isn't O(1) even though the structure would be statically allocated and obviously O(1) in terms of entry count.

>The number of checks is not large enough to justify using a map container

>Even though the static code to make these checks could be gigantic and naive if not optimized in comparison to the better tested generic alternatives, unnecessarily wasting instruction cache.

TL;DR stop trying to be a contrarian, code like this has no fucking place anywhere.

>>523446

Only the 2 * a was wrong.

>>523620

But it is preferred rather than "I wrote this beautiful unmaintainable 20 line code instead of a 3 line code plus some static ADT that works without a doubt"


 No.523722

>>523701

I just fail to see how

HashMap<String,String> d = new HashMap<String,String>();
d.Add("htm","text/html");
d.Add("html","text/html");
d.Add("json","application/json");
d.Add("css","text/css");
...

string ext = extension(filename);
string mimeType;
if (d.GetKey(ext, out mimeType)) {
return mimeType;
} else {
return "text/plain";
}

is any better than

string ext = extension(filename);

switch (ext) {
case "htm":
case "html": return "text/html";
case "json": return "application/json";
case "css": return "text/css";
...

default: return "text/plain";
}


 No.523724

>>523722

it absolutely isn't


 No.523735

>>523722

You hardcoded the entire list in. In both cases you still repeat code an endless number of times. That alone should alarm you that you're doing something wrong.

In other words, you're still regarding data as code and fail to see the fundamental error in your reasoning.

Now make it so you don't need to recompile the whole goddamn thing just to add an entry.


 No.523738

>>523735

So you want

File f = File.Open("/usr/share/" + PROGRAM_NAME + "/mimeTypes", "r"):
if (f == null)
throw new FileNotFoundException("Could not open mime type map");

HashMap<String,String> d = new HashMap<String,String>();

LineReader lr = new LineReader(f.InputStream);

while (!lr.IsEndOfFile) {
string line = lr.ReadLine();
string[] entries = lr.Split(",");
if (entries.Count != 2) {
throw new Exception("Malformed mime type file");
}

d.Add(entries[0], entries[1]);
}

f.Close();

string ext = extension(filename);
string mimeType;
if (d.GetKey(ext, out mimeType)) {
return mimeType;
} else {
return "text/plain";
}

?

You're right, it is looking like some pretty good-style enterprise Java. I'm glad you've made me a better programmer!


 No.523745

>>523738

Forgot the source of /usr/share/PROGRAM_NAME/mimeTypes:


htm,text/html
html,text/html
json,application/json
css,text/css
...


 No.523752

>>523640

Giant tables if if/else are a very common source of bugs and security holes. If you start one off like that and check back in 10 years you'll find it grew rather than was rewritten to not be shit and probably had at least one bug in that section in its history. When it actually takes less effort and typing to do it right and would be more safe and less shit, that's CS grad territory. An experienced programmer knows better.


 No.523754

File: 1455661704737.jpeg (23.62 KB, 475x389, 475:389, 324.jpeg)

>you now realize that all these kinds of threads do is make people shy to write code


 No.523758

>>523752

>Giant tables

It's like 5 entries, calm your tits.

>Of if/else

The code I presented is a simple switch/case block

>If you start one off like that and check back in 10 years you'll find it grew rather than was rewritten to not be shit and probably had at least one bug in that section in its history.

You refactor stuff when it grows, not before it grows.

Trying to abstract everything to hell and back is what makes CS grad software so shit in the first place, at least in my experience.

If you're not saving something, you're not saving something - just wasting effort and space.

Notice how the “refactored” version was not only needlessly dependent on runtime variables but it also had two extra failure/crash conditions (missing or malformed database) while being less readable and uglier to boot.

There was NOTHING saved by doing that refactor, not even in the slightest.

When the list grows to 500 entries you can make an argument about factoring it out, but not when it's below fucking 10.

>When it actually takes less effort and typing to do it right and would be more safe and less shit, that's CS grad territory.

The switch/case is not only the most readable, elegant and safest approach but also the one that requires the least typing and has the least potential for error.


 No.523759

>>523738

Why the hell are you reading the entire file and constructing a new hash map every time the routine is called? Jesus Christ. You should read the data file only once, or read directly from the file every time, whichever is more convenient to the application at hand. Don't blame your shitty programming on me.

Anyway that's besides the point. Disregarding the embarrassing implementation, this code will retain its size and complexity no matter how many extension/mime type entries you add, and the user of your program won't need to recompile it every time they want to change it.

In contrast your original could grow potentially hundreds of lines long as new entries are added (a fact cleverly disguised by ...-ing your code), and would have to be recompiled each time, not to mention the risk of introducing bugs. Who the hell would want to maintain that shit?


 No.523760

>>523758

>Notice how the “refactored” version was not only needlessly dependent on runtime variables but it also had two extra failure/crash conditions (missing or malformed database) while being less readable and uglier to boot.

Oh, it also involves completely needless disk I/O (which is many orders of magnitude slower than even the original code) and unpredictable runtime semantics / hidden failure conditions (what if the system ran out of FDs? what if the buffering behavior behind the linereader opens up your system to DoS? etc)

It's just shit code, please stop defending it.


 No.523765

>>523758

>You refactor stuff when it grows, not before it grows

You're naive. If you plant a seed like this it grows into a large if/else. Other programmers are not going to take the time to fully understand and refactor code that has worked for years and potentially break something, they're going to copy&paste and move on. Maybe they accidentally delete a character while doing so and no one notices a rare condition now fails due to using "|" instead of "||". This shit happens all the time and is why it's considered bad practice to plant a copy&paste seed.


 No.523766

>>523759

>Why the hell are you reading the entire file and constructing a new hash map every time the routine is called?

Dude, it's obviously fucking pseudocode. I didn't even have a method definition or anything. I'm pointing out what code you would have to run, and have at least somewhere. Heck, none of those are even valid C# or Java ways of reading/processing a file, I just made them up on the spot.

Are you the kind of guy who raises his hand in class and calls the teacher out for having a missing ; in a snippet of pseudocode, too?

You're completely missing the fucking point I'm trying to make here.

The point I'm making is that you took a solution that was elegant, short, simple, robust and self-contained and turned it into a fucking behemoth.

I don't care how much you would have me polish the implementation I pulled out of my ass on the spot, it's NEVER going to be cleaner and more maintainable than what we had to begin with.

>(a fact cleverly disguised by ...-ing your code)

I was just too lazy to scroll up and look at the original image. It was nowhere near the hundreds of lines you seem to make it out to be.

>nd would have to be recompiled each time

_SO_FUCKING_WHAT_?

What makes you think it's a requirement of the program for this function's behavior to change at runtime?

Also,

>You should only read the data file once

>You need to restart the program every time you make a change!

Make up your mind


 No.523770

>>523765

>You're naive.

I'm naive? Jesus christ, I've been working in the programming industry for well over 10 years and worked full-time on projects with hundreds of thousands of lines of code.

>If you plant a seed like this it grows into a large if/else.

At which point you can easily spend the half it hour it takes to come up, test, document and integrate a system for dealing with the shortcomings of the flat approach.

If it takes you 1 minute to come up with a non-scaling solution and then later you find out you need to scale it, you've only lost 1 minute.

If it takes you 30 minutes to come up with a scaling solution where it was completely unnecessary, then congratulations: you've wasted time and made the code more complicated than it needs to be.

If there's one thing I've learned across the years it's KISS. Keep it fucking simple and stupid.

If there's no reason to add extra baggage or complexity, don't.

If you keep your code simple and understandable, you can refactor _everything_ if the need arises.

But know what hinders refactoring? Complicated, overengineered subsystems that serve no purpose other than to avoid nonexistant problems.

Fuck, freshmen programmrs make me so angry


 No.523773

>>523765

>Other programmers are not going to take the time to fully understand and refactor code that has worked for years and potentially break something, they're going to copy&paste and move on.

I think this is your problem more than anything. Stop working with other freshmen programmers who copy/paste shit around instead of being competent in the slightest.


 No.523774

File: 1455662795574-0.png (282.82 KB, 694x801, 694:801, cipher.png)

File: 1455662795575-1.png (347.19 KB, 1758x1000, 879:500, thread.png)

File: 1455662795575-2.png (89.65 KB, 694x801, 694:801, timer.png)


 No.523776

File: 1455662933196.jpg (85.71 KB, 570x720, 19:24, 1455048762633.jpg)

>>523754

>not using these threads to illuminate bad design to improve your own shit-tier code

>being paranoid about your irrelevant code popping up in these threads

>being afraid to learn from your mistakes even if people make fun of you for it

Just write some fucking code already. Stop being a pussy.


 No.523780

File: 1455663062607-0.png (117.87 KB, 694x732, 347:366, new averaging system.png)

File: 1455663062608-1.png (118.07 KB, 694x801, 694:801, tweeter.png)

File: 1455663062608-2.png (111.84 KB, 606x1000, 303:500, enterprise fizzbuzz.png)

Gotta love some of the classics


 No.523781

File: 1455663192522-0.png (140.65 KB, 800x600, 4:3, Graduate Student.png)

File: 1455663192569-1.png (24.49 KB, 652x692, 163:173, webdev.png)

File: 1455663192580-2.png (101.76 KB, 694x801, 694:801, difficulty.png)


 No.523802

File: 1455664655788.png (43.45 KB, 247x394, 247:394, cvydb5he.png)

>>523442

>use an external library for a tiny amount of text parsing

I will fucking cut your throat faggot

Here's a javascript solution because that's all I know:


var fileext = filename.substring( filename.lastIndexOf("."), filename.length );

switch (fileext){
case ".html": return "text/html"; break;
case ".js": return "application/javascript"; break;
case ".xml": return "application/xml"; break;
default: return false; break;
}


 No.523805

File: 1455664821219.png (120.21 KB, 683x1024, 683:1024, equality.png)

>>523760

>it also involves completely needless disk I/O

>reading an executable bloated by all the select/case-s from disk doesn't cost anything

If your version of the executable is stored on disk then you will have to read the data from the disk no matter what. At that point every argument you make against reading from the disk applies to hardcoding it just as much. Where do you think all that data goes when you hardcode it into the program?

>it also had two extra failure/crash conditions (missing or malformed database)

>there is no risk of fucking up a gigantic switch/case statement

>>523766

And your pseudocode reads from a file and constructs a hash table every time it's run. Was I supposed to imagine them all in their own functions? Your code does what it says it does, without ambiguity. Maybe next time you should actually write what you mean.

It was considered to be CS grad tier code in the first place on the assumption that you'd want more than just seven out of the hundreds of mime types out there. Of course if we do assume that it's highly unlikely to grow then you're absolutely right. That would mean it's okay to use CS grad tier code if it saves time and is unlikely to bite you in the ass later. But it's still CS grad tier code.

>What makes you think it's a requirement of the program for this function's behavior to change at runtime?

You just outed yourself. I never said that it needed to change at runtime, what I said is that the user would need to recompile the program every time they wanted to add a new mime type. If one part of your company uses your program then it would be a significant waste of time having to send it back to you just so you can add a mime type, recompile the module and send it back, when the user could have just added a line to a file.

However you wrote your pseudocode function in a way that would make it possible for the program to change its behavior at runtime if you change the file. So you must have intended your design to be as horrendous as it is. I, however, have nothing to do with that, that was entirely your design.

>>You should only read the data file once

>>You need to restart the program every time you make a change!

>Make up your mind

You should consider calming down and putting on a new tampon because your impotent rage seems to be affecting your ability to read. I said that in your version you need to recompile the program every time you make a change, the same thing I've been saying over and over again. Besides, I did end that sentence with "or read directly from the file every time", so your sperging out over this is doubly unwarranted, but don't let that bother you.


 No.523842

>>523805

>Where do you think all that data goes when you hardcode it into the program?

Into a very densely and efficiently packed .rodata segment that's shared by the kernel between running instances of the process image. Imagine a program that adds TLS to a socket. It has many KiB of tables, but somehow you can still start the process up half a million times per second without issue - because the dynamic overhead of doing so is almost zero.

And since we're bikeshedding the fuck out of this, why not stop and talk about dynamic allocation overhead, as well as the implications of having many indirect loads on scattered data...

This is obviously a pointless exercise but suffice to say: putting data in a .rodata segment is categorically more efficient than manipulating it at runtime, albeit not always preferable.


 No.523852

>>523842

That sounds great, you learn something new every day I guess. But surely there is a way to do the same thing without hardcoding all that data into the program. The point (my point, at least) was that we should keep data and instructions separate, which this .rodata segment would probably do if you were working in assembly, but a horrendously long line of if-else-s or case statements in a higher level language doesn't really address this issue, even if it does end up that way.


 No.523865

File: 1455668468816.png (64.72 KB, 759x425, 759:425, ClipboardImage.png)

found this while browsing a mailing list and had a chuckle


 No.523882

>>523802

file extensions are not guaranteed to be the actual file type


$ echo 'word' > file.flac
$ file --mime-type file.flac
file.flac: text/plain
$

>javascript

you have no right to call other people faggots


 No.523894

File: 1455671548613.gif (991.82 KB, 250x250, 1:1, 1444441255061.gif)

>>523865

>"Upgrading" to Windows 10 for more integers

>Not upgrading to Windows 95 for 88 more integers

>Not upgrading to Windows 98 for 91 more integers

>Not upgrading to Windows 2000 for 1993 more integers


 No.523909

>>523626

A HashMap, obviously.


 No.523913

>>523424

oh god I'm happy someone said this.

>autists ITT arguing over the performance characteristics of this code

>autists ITT arguing about extensiblity of code

>some web monkey arguing a mime library (aka retarded black box written by other web monkeys) should be used


 No.523921

>>523913

>".jpg means it's a jpg, right?"

And that's how somebody starts executing some code.


 No.523979

>>523882

neither are advertised mime types. The server or whoever wrote the file can tell you it's whatever mime type they want.

>>523921

Your jpeg library is shit proper mime types can't and won't save you.


 No.524003

File: 1455682767810.png (19.09 KB, 584x211, 584:211, Screenshot from 2016-02-17….png)

>>523754

>>523776

OP here! I write shit code and give no fucks. I'd rather have someone call me a moron than keep being one tbh bruh.

here's the completed function from OP as well. vala's real fun right up until you need data that isn't stored in the sourcefile: I never thought I'd see c# code for some function and feel jelly.


 No.524079

>>523852

What I do in some cases is prepare the data programmatically and #include it in an array somewhere. You could probably do this with hash tables but not in a nice way. Mostly I've done this when it comes to sorting data for a binary search at runtime. You get the benefit of having it in a .rodata segment (or PE equivalent) but still retain some good search properties. Anything you construct at runtime will have a dynamic overhead, and in the case of mapping MIME types it's obvious to me that it should be loaded from disk so you can dynamically extend it. Or better yet: stop using MIME types.


 No.524087

>>523604

This is the cringiest of rules, especially for a function that's just a glorified lookup.


 No.524131

>>523781

if i understand the problem correctly from pic 1, well this is my attempt. took me about 40 minutes. python is my weakest language and i am comfy coding so i am slow. would have been much easier to be able to replace the elements of the string but no such luck in python :( i welcome your criticisms.


#! /usr/bin/env python3

def print_star_x(lines, char = "*", padding = ""):
"""
Prints an 'X' with lines number of lines composed of
the symbol specified by char.
"""
for i in range(0, lines):
line_str = padding + (" " * i) + char + (" " * (lines - 1 - i)) + padding
print(line_str, end = "")
line_str = ("\b" * (i + len(char) + len(padding))) + char
print(line_str)


 No.524138

>>524131

and with it now i think i will use it as a dankpost generator

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happeneholocaust never happened

holocaust never happeholocaust never happened

holocaust never hapholocaust never happened

holocaust never hholocaust never happened

holocaust neverholocaust never happened

holocaust nevholocaust never happened

holocaust nholocaust never happened

holocaustholocaust never happened

holocauholocaust never happened

holocholocaust never happened

holholocaust never happened

hholocaust never happened

holocaust never happenedd

holocaust never happenedned

holocaust never happenedpened

holocaust never happenedappened

holocaust never happened happened

holocaust never happeneder happened

holocaust never happenedever happened

holocaust never happened never happened

holocaust never happenedst never happened

holocaust never happenedaust never happened

holocaust never happenedocaust never happened

holocaust never happenedolocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened

holocaust never happened holocaust never happened


 No.524139

File: 1455704837439.png (40.11 KB, 1187x663, 1187:663, ss (2016-02-17 at 10.25.02….png)

Hi, I'm an EE undergrad


 No.524143

>>523882

If the filename ends with .jpg and the file is not a jpg, then you've fucked up worse than the guy who wrote the original program because you're serving broken files.

>le javascript is le shit therefore I le ignored what you le said


 No.524194

File: 1455712176445.png (30.66 KB, 476x628, 119:157, Untitled.png)

>>524139

Me too!


 No.524212

>>524143

>what are malwares


 No.524215

>>524139

Wouldn't that be shorter to rewrite the Dijkstra algorithm from scratch?


 No.524219

>>524215

Having done it many times, yes - by a very wide margin.


 No.524326

>>523604

>single exit point style

I found the CS grad.

Kill yourself you fucking scrub. Single exit point style is for inept coders who cannot into branching logic. That's the only thing it's good for.


 No.524339

File: 1455726020061.jpg (40.03 KB, 562x437, 562:437, hahaha oh wow.jpg)

>>523802

>return "text/html"; break;

Go back to >>>/g/.


 No.524346

>>524138

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix nood bix nood

bix noodbix nood


 No.524348

>>524339

Bad habit I still haven't learned out of. When I first learned programming I was taught that switch statements always have to end with break or else it gets fucked up. But of course at that point I didn't know any better.


 No.524351

File: 1455726941908.png (30.98 KB, 652x701, 652:701, Speechless.png)

>>523802

...aaand CAPPED!


 No.524353

>>524351

Seriously nigger?


 No.524356

>>524353

It is a worthy piece of code.


 No.524357

>>523770

You also got over 300 confirmed kills?


 No.524360

>>524356

No it isn't, such a trivial "mistake" is a disgrace to this meme.


 No.524368

>>524360

Nigger, take a good hard look at that code.

It is pants-on-head retarded. Completely fucking retarded. No one with any brains would put a break statement after a return. It defies all reason. This is a fucking jawdropper of "No seriously, no one could be THAT fucking stupid, could they?" proportions. It suggests you don't comprehend what return and break statements do.


 No.524369

>>524368

Both return and break stop it from executing, therefore they're both in correct location. The only mistake is that they're both used at the same time, which doesn't even matter because the code functions perfectly fine. It's just 5 characters of redundant yet harmless code, that's about as trivial as a programming mistake gets.


 No.524374

>>524369

Confirmed for >>>/g/

>Both return and break stop it from executing

>stop it from executing

The mental image here suggests you need to code some assembly and build familiarity with jump instruction logic.

>it functions fine so it's okay, guys!

Nigger, the first pic here >>523780 probably runs fine too, but it's still completely retarded because of the excessive and retarded bullshit it gets up to.


 No.524385

>>524374

Keyword here is excessive.

Using a single redundant statement isn't worth a CS grad meme unless you're some turbo autist. The code itself isn't constructed in a retarded way or do anything stupid, it just has an extra statement that doesn't do anything. That's akin to forgetting to remove some object or function or other piece of code after refactoring, it doesn't do anything, it doesn't break anything, it's just there, and it's only a single statement, not some convoluted pile of cancer that this meme is intended for.


 No.524389

>>524353

>>524360

>>524369

>>524385

>insisting this code is tolerable

Are you for real? Holy fuck.


 No.524392

File: 1455729852144.png (136.16 KB, 1120x977, 1120:977, lol.png)

>>524385

>The code itself isn't constructed in a retarded way or do anything stupid

>this is what he actually believes


 No.524394

>>524389

I'm insisting that it's not bad enough to warrant this meme, how hard is that to understand?

Do you make a CS grad meme out of every single programming mistake you come across?

>>524392

Do point what's retarded about it, aside that one thing.


 No.524397

>>524394

>Do point what's retarded about it, aside from what's retarded about it

...


 No.524400

>>524397

You're really not listening at all, are you.


 No.524401

>>524400

You're really not listening at all, are you.


 No.524403

>>524394

>>524400

If you're going to be this thick-headed about your mistakes, please fuck off to >>>/g/ already.


 No.524405

ITT: Why javascriptfags are cancer.


 No.524407

>>524403

You're also not listening, assuming you're a different guy and not just samefagging to waste my time >>524405

If you think a single redundant and harmless word makes the code worth a CS grad meme, you may have autism.


 No.524412

File: 1455730976760.jpg (204.34 KB, 650x650, 1:1, damage control.jpg)

>>524407

>Calling me out only proves you have autism!


 No.524414

>>524412

Nice dodge fam.


 No.524417

autism autism

autism autism

autism autism

autism autism

autism autism

autism autism

autism autism

autism autism

autism autism

autiautism

autismtism

autism autism

autism autism

autism autism

autism autism

autism autism

autism autism

autism autism

autism autism

autism autism


 No.524418

File: 1455731226006.png (62.78 KB, 186x255, 62:85, 1423495640907.png)

>>524394

>Do point what's retarded about it, aside that one thing.

>return "text/html"

>return "application/javascript"

>return "application/xml";

>return false;

what?


 No.524420

>>524417

/thread

/board

/chan


 No.524421

>>524418

I don't get what you're implying.

The fallback should be text/plain? I actually didn't even notice that until now because nobody says anything other than "NO ITS SUPER RETARDED LALALA I CAN'T HEAR YOU"


 No.524422

>>524003

That's very mature of you, OP. I hope this is what /tech/ can be; a board to get called a fag when someone codes like one.


 No.524423

>>524421

Returning different types does not look like a good idea to me.


 No.524426

>>524421

>nobody says anything other than "NO ITS SUPER RETARDED

That's because it is. No one in their right mind would put a break after a return statement.

>LALALA I CAN'T HEAR YOU"

We heard you and your excuses. We just disagree. And the way you carry on, you're only digging yourself deeper.


 No.524427

>>524403

>>524394

>>524397

>>524421

>>524418

>>524423


var mimeTypes = {
html: 'text/html',
jpg: 'image/jpg'
// ..
}

function getMimeType(file) {
return mimeTypes[file.extension];
}


 No.524429

>>524131

>>524138

Nice use of control characters. One can even see the direction of the "brush".

nigger nigger

nigger nigger

nigger nigger

nigger nigger

nigger nigger

nigger nigger

niggenigger

nignigger

nnigger

niggerr

niggerger

niggerigger

nigger nigger

nigger nigger

nigger nigger

nigger nigger

nigger nigger

nigger nigger


 No.524432

>>524423

I prefer to return false than nothing.

I didn't notice the original function had text/plain as default, so I just went with false.

>>524426

You're not listening again. Nowhere did I say that it isn't stupid, my whole argument is that this meme implies a level of stupidity far beyond that of a redundant break statement.


 No.524433

>>524131

>>524138

Nice use of control characters, I can even see the direction the "brush" was drawn.

nigger nigger

nigger nigger

nigger nigger

nigger nigger

nigger nigger

nigger nigger

niggenigger

nignigger

nnigger

niggerr

niggerger

niggerigger

nigger nigger

nigger nigger

nigger nigger

nigger nigger

nigger nigger

nigger nigger


 No.524434

>>524432

And the counterargument which you keep ignoring is that it really is that stupid. Deal with it and move on already, you fucking autist.


 No.524435

>>524434

No, it really fucking isn't.


 No.524437

>>524435

Of course it isn't to you. You're the retard who wrote that code.


 No.524439

ITT: CS grads.


 No.524440

>>524433

>>524429

It does the job for what I interpreted the problem to be.

I would have preferred to use index to change the string characters but python doesn't allow that.

It also looks better in terminal usually because it doesn't post with monospace font which fucks it up for long words where they overwrite each other.

Making the string symmetric instead of using control characters would fix that.


 No.524442

>>524437

And it is to you because you're an obsessed autist who can't tell the difference between a redundant word and an ass backwards solution, because anything faulty triggers your autism just the same.


 No.524443

File: 1455733473860.png (139.3 KB, 955x654, 955:654, How to pwned.png)


 No.524445

I really hope there aren't actual CS grads in this thread who think they're in good company and the stuff they're posting is ACTUALLY their work.


 No.524455

>>522821

If any of y'all autists still care, I checked the latest version of YandereSim and the code in both CS grad memes that I posted is still there. In other words he either fixed something else or he didn't fix anything substantial. Although looking at this thread now it seems someone just might start insisting that there's nothing wrong with his code, lel.


 No.524463

>>524455

I am just worried that that code is in his 'not so bad' category.

Can you make a diff with the older build?


 No.524478

>>524443

The terrifying part is that some people will think useradd is the smart way to go here because it's not reinventing the wheel.


 No.524484

itt armchair jobless "experts"


 No.524491

>>524484

you aren't mad at all


 No.524497

>>524463

Here you go, diff of YandereScript.cs January and February versions, that's where I got the meme material from. http://pastebin.com/XxJQvuGa


 No.524500

>>524497

I meant StudentScript.cs* I suck dicks.


 No.524501

>>524484

butthurt butthurt

butthurt butthurt

butthurt butthurt

butthurt butthurt

butthurt butthurt

butthurt butthurt

butthurt butthurt

butthurt butthurt

butthurt butthurt

butbutthurt

butthurturt

butthurt butthurt

butthurt butthurt

butthurt butthurt

butthurt butthurt

butthurt butthurt

butthurt butthurt

butthurt butthurt

butthurt butthurt

butthurt butthurt


 No.524509

>>524443

>http ALL=(ALL) NOPASSWD: ALL

That was extremely painful to read. But I'm not surprised that it was posted on /r/php.


 No.524541

Hi guys I'm pretty new to programming pls rate my code

(defun fibonacci (n)
(
block nil (
if (< n 2) (
return n
) #|else|# (
progn
(setf r 0)
(incf r (fibonacci (- n 1)))
(incf r (fibonacci (- n 2)))
(return r)
)
)
)
)


 No.524544

>>524541

>lisp

10/10 bretty gud


 No.524547

>>524427

Idiomatic PHP solution:


class GuessTheMimeType
{
protected static $htm = "text/html";
protected static $html = "text/html";
protected static $js = "application/javascript";
protected static $png = "image/png";

public static function getMimeType($filename)
{
$ext = array_pop((explode(".", $filename)));

return isset(static::$$ext) ? static::$$ext : "text/plain";
}
}

[x] Contains repetitive code

[x] Uses explode and/or implode()

[x] Muffles a notice with double parentheses

[x] Uses variable variables

Can I be CS grad now?


 No.524552

File: 1455742948869.jpg (39.31 KB, 528x492, 44:41, 1424601613409.jpg)

>>524547

I-Is that how PHP work?

4 realz?


 No.524554

>>524547

I have to carve through so much legacy PHP at work that my eyes automatically turn to static when they encounter this kind of stuff after 3PM.


 No.524561

>>524547

Needs more OOP


 No.524562

>>524554

It doesn't tick this box, though:

[ ] Hell breaks loose in PHP7

Although the double parantheses trick doesn't work there, so it will be an E_NOTICE.


 No.524563

>>524561

It's PHP, not Java. If anything, it should need less OOP.


 No.524565

>>524541

you should memoise for speed


 No.524573

>>524563

PHP is just making up for the years it didn't support OOP.


 No.524579

>>524443

Is this real? Sauce?


 No.524581


 No.524585

>>524509

I'm a newfig in sysadministration, does that mean that user http can do anything he wants without any password on any computer?


 No.524598

>>524585

Any computer with that configuration. Now guess as what user the web server runs...


 No.524720

>>522694

windows a shit


 No.524794

File: 1455765392534.gif (2.18 MB, 643x539, 643:539, pc principal.gif)

>tfw I am not a programmer, just a janitor

>tfw I code on my shitty little indie game in a shitty engine at home after fapping, playing games and coming from work

>tfw I do not even know trigonometry or any advanced geometric formulas (working on it)

>tfw most of these images are so god damn stupid that I could probably program better than most of them if I actually tried, and I don't even go to college

>so many unnecessary lines, so many overly complicated solutions, functions that are not thought out to be flexible/expanded

>mfw reading this thread

I refuse to believe most of these are taken from actual links/pages or are real, when I see things like OP's opening image I just think someone invents it for meme value and they are fake.

Surely no one can go to college, know more than me, have a programming job, then do shit like that. No.


 No.524808

>>524794

It actually depends. My uni, for instance, focuses mostly on theory, without specifically teaching much in terms of practice. So a lot of people come out of the program not knowing how to code at all. They can, however, tell you about the producer-consumer pattern.


 No.524813

>>524794

Na man I use to program a shitty little indie game before I got my CS degree. Chances are you are more qualified than most.


 No.524816

>>524813

The thing is that I don't wanna humblebrag, I could come off as incredibly arrogant from that post but the fucking stupidity from most of these pics is just too much, they should know their shit better at their level. Maybe we got a bit more experience actually doing something rather than learning things for 4 years and making nothing.

>>524808

I don't get how they can focus on theory so much and not know how to program, after they come from class can't they work on some personal projects? I've seen some courses have some very fucky questions and assignments that should put their brains to work, I can't even do a lot of those actually, how do they pass/do those and then make meme worthy code after that?


 No.524849

>>524497


if (!this.Male)
{
if (this.HairColor == "Red")
{
this.HairTexture = this.StudentManager.Colors[0];
}
else if (this.HairColor == "Yellow")
{
this.HairTexture = this.StudentManager.Colors[1];
}
else if (this.HairColor == "Green")
{
this.HairTexture = this.StudentManager.Colors[2];
}
// and so on...

Someone needs to teach this guy about maps. Or functions, or fucking something. I have a friend who codes like this - and he learned mostly in unity. Is this just a unity thing?

That file was painful to read.


 No.524851

>>524849

Why wouldn't he just make something like assign_hair_texture(gender, hairColor) and inside the function would look inside a gender list and pick a hair texture based on the color, which would be from a list? Instead of all the ifs and elses.


 No.524854

>>524849

As someone who learned to code when he was 12 in ROBLOX, I don't think I was ever of the mindset that this was a good idea.


 No.524855

>>524849

>>524851

My C# is a little rusty but this could be a one-liner.


static class HairTexture { Dictionary<Gender,HairTexture> byGender };

/* later */
this.HairTexture = HairTexture::byGender(this.Gender)[this.HairColor];


 No.524856

>>524854

go fap to pokemon ben


 No.524857

>>524854

I just go by that if you start to feel like there should be a better way, there probably is.


 No.524906

>>524856

fuck off nick


 No.524937

>>524816

>personal projects

A number of them never do those P:

>how do they pass

Like they do for any other course: largely memorizing just what they need to know for the exam.

What I mean is like I'd ask them something related to what they did in their course, even sometimes things directly related, and they'd have no idea. It's like, how can you be close to graduation and have _no_ idea how to program?

That being said, there are still those people who actually know what they're doing to a certain degree. Those people are awesome. The rest will end up in QA and will never be heard from again.


 No.525084

>>524794

>after fapping, playing games and coming from work

In that order, right?

>>524937

> Like they do for any other course: largely memorizing just what they need to know for the exam.

I can confirm that. I am shit at memorizing, always hated how in History we would have to memorize dates and I would be sitting there for hours trying to memorize basic numbers.

I barely managed to pass my CS classes because it was all about memorizing. Here is a graph, reduce it by applying the algorithm you learned in class. What's the fucking point? Shouldn't I be making new algorithms using the ones I have already learned? There would be usually one such question in the exam, but that's the only one where you have to think. Sometimes you might have to prove something, but it's exact fucking same proof we did a dozen times in class.

When I code I absolutely must have a reference at hand. It's not that I don't know or understand the algorithm, but I don't know the details. And guess what, I don't have to, I just look it up in the reference and then concentrate on the actual work: making something useful with it.


 No.525088

>>525084

reversed order actually


 No.525093

>>524131

>would have been much easier to be able to replace the elements of the string but no such luck in python :(

But you can replace stuff in lists.

n = 9
for i in range(n):
s = [" "]*n
s[i] = "*"
s[n-1-i] = "*"
print("".join(s))


 No.525101

>>524541

Terrible time complexity. 2/10 apply() yourself.

return round((((1+5**0.5)/2)**n - ((1-5**0.5)/2)**n)/5**0.5)


 No.525379

File: 1455821139857.png (84.59 KB, 461x660, 461:660, 1449589376178.png)


 No.525757

>>523287

The whole point of MIME types and such is that you can get a more reliable indication of a file's contents than just relying on its extension.

Usually they're determined by scanning the file's contents. In a few scripts I've written, I've used a file's (automatically detected) MIME type as a way of choosing the extension to give it. I've renamed countless .png files to .jpg because apparently people are bad at remembering what type they saved their image as before they upload it.


 No.525771

>>523604

It would make the code slightly easier to reason about, if it wasn't blatantly obvious that it was a lookup table in switch form in the first place. Stop cargo cult programming, and write simple, clean, understandable code. Multiple return points doesn't equate to bad code, and if your function is large enough that multiple return points makes it difficult to read then you should probably cut the function up into smaller pieces in the first place.


 No.525891

>>523610

But... think about this rationally. How many different photographic storage types is he going to be handling? Really?


 No.525917

>>524484

back to india, abu


 No.525922

>>524194

Holy shit I'm in your class, lol. How's your car working so far?


 No.525923

>>524849

>Is this just a unity thing?

Probably more like a beginner thing.

When you start by making games, you're worried more about the game than learning to program more effectively.

The plus side is you get shit done. The downside is your code looks like that.


 No.526054

>>525923

>Probably more like a beginner thing.

According to his site he worked at a video game company for three years before beginning work on Yandere sim.


 No.526064

>>524131

What are the instructions in human language? I don't program but I'm curious about the math in that cool X


 No.526102

File: 1455892208471.jpg (14.52 KB, 387x259, 387:259, Literally me.jpg)

>tfw you're an underage and you can write better code than these retards


 No.526107

File: 1455892831946.webm (Spoiler Image, 6.14 MB, 640x480, 4:3, PIZZA TIME.webm)

>>526102

>admitting you're underage


 No.526142

>>526102

Don't get too cocky, son


 No.526155

>>526107

Giving underage fags attention.


 No.526598

>>524368

>>524369

>>524374

>>524385

I was under the impression multiple return would halt a function as soon as one was reached, but I'm not an ASM guy, so it'd be nice if you could expand on what you're hinting at.

thanks in advance. and it's really awesome that this thread is going gangbusters.


 No.526631

>>526598

This may be oversimplifying a bit, but return is the inverse of call. A jump or "goto" does the same thing as call but doesn't push the program counter to the stack. Return jumps as well but pops the destination address from the stack. So you can jump to a return instruction and processing continues right after the position of the last call. Hope this clarifies things a bit.


 No.526640

>>526631

so what may I take from this:

1) those breaks would have actually executed?

2) multiple return should be implemented at the end of a function so you know your program won't be doing useless shit like evaluating if's that don't apply?

would there ever be a case where multiple return could fuck up catastrophically? like for example using the function to trigger a callback or signal?


 No.526644

>>526598

>>526640

Return statements DO exit the function. Someone in here is blowing this shit way out of proportion. Break statements after return statements don't ruin anything, and they're not:

> It is pants-on-head retarded. Completely fucking retarded. No one with any brains would put a break statement after a return. It defies all reason. This is a fucking jawdropper of "No seriously, no one could be THAT fucking stupid, could they?" proportions.

This guy must be bored out of his mind trying to make something out of nothing.


 No.526661

>>526644

>This guy

This is why you fucks need IDs.


 No.526802

File: 1455948373259.webm (1.08 MB, 1280x720, 16:9, AHHHHHHHHHHHHHHHHHHHHHHHH….webm)

>>522737

FOOLISH

YANDEV

MERCHANT


 No.526812

File: 1455949217934.jpg (Spoiler Image, 81.73 KB, 584x383, 584:383, 1447108343863-3.jpg)

>>524794

He doesn't know the joke is that the stupidity is so understated XD


 No.526843

>>522753

It's as if he was popular for a gimmick and not because he was good at anything


 No.526856

>>526640

>1) those breaks would have actually executed?

I fail to comprehend how you could come to this conclusion with the information presented.

>2) multiple return should be implemented at the end of a function so you know your program won't be doing useless shit like evaluating if's that don't apply?

A function can only return to its caller once, i.e. the first branch to reach a return statement exits the function. How many branches there are matters not.


 No.527025

>>526644

I'm in complete agreement with "that guy". You don't write code that does nothing. It's redundant, it makes your code noisier, and it shows a lack of understanding of the code (which means I'll trust the code less and be more likely to assume parts of it are wrong).

Yes, it's just one token per case, but that one token would not have gone there if you were actually thinking while programming.


 No.527055

>tfw never written code

>tfw reading this shit is like trying to read another language

>tfw don't even know what shit like "float" and "private string" even mean

>tfw can't code at all

>tfw too lazy to learn anything

>tfw no will to learn

>tfw no will to work

>tfw eternal NEET who will never accomplish anything other than organizing my massive pirated anime, vidya, and porn collections


 No.527056

>Try to find some code to share

>Fairly niche product

>Tons of shit are prefixed with the company name

>Most of the horror is based on how bloated the code base is so can't take a short chunk

I think I've managed to find a short chunk that should be indicative of the piece of hell I get to work on. Variable and table names modified for privacy.


if s_table_id and filter_str:
filter_str += " OR a_table.a_id IN(SELECT DISTINCT a_id FROM sta_table WHERE s_table_id = {})".format(s_table_id)

That snippet is from a function approximately 130 lines long and is part of the NEW AND IMPROVED codebase. s_table_id is not ensured to be an integer or escaped in any way. Made by an industry veteran


 No.527060

>>527055

You really should try to learn programming so you later can post your code in this kind of thread


 No.527089

>>527055

post your steam i'll make you learn


 No.527098

>>526142

I won't, I know I write pretty crap code sometimes, but I haven't written stuff this bad for years. Like, there's writing something inefficiently and then there's just flat out doing stuff that doesn't make any sense like >>522737


 No.527099

>>526155

>Not greentexting that

Hello newfriend, would you like to be shown around these parts by an underage?


 No.527100

>>527055

Float means decimal number.

String is a string of letters, so basically just text.


 No.527129

File: 1455985886261.gif (27.35 KB, 715x488, 715:488, asciifull.gif)

>>527100

It should be noted that basically all modern computers use ASCII code for "letters". There are other codes but I don't know of anything that actually uses them.

ASCII means that "152" is not the same as 152. When you tell a program 152 you're telling it the number one hundred and fifty two, it's an integer. When you tell a program "152" it means "a string with three characters, the character 1, the character 5, and the character 2". Each of those characters is not stored as a binary integer but as an ASCII character, 1 is not 1 (00000001) but actually 49 (00110001).


 No.527134

>>527129

muhnicode


 No.527135

>>527129

Slow down, I'm trying to make things simple, you're overcomplicating things.


 No.527138

>>526661

Fuck that. ID's are cancer. How the fuck do ID's even work with multiple IP addresses anyway?

>>527099

Who are you quoting, friend?

>>527100

More accurately, "float" refers to a number whose binary or decimal point is "floating" and can vary from value to value. Generally it's referring to a floating binary point, but there are some exceptions.

>>527129

> It should be noted that basically all modern computers use ASCII code for "letters".

What do you mean by this? What are you referring to as a "computer" here?


 No.527219

>>524794

The meme is that CS grads are bad coders. You put some bad code next to a picture of a CS grad, hilariously implying that this was written by them. Meanwhile, they make megabucks. Capish?


 No.527477

>>527099

Isn`t geen texting just for quoting and stories?

I`m not quoting >>526107 .


 No.528936

>>527138

>What are you referring to as a "computer" here?

A box full of chips, bolts and wires. (And the ghost, don't forget the ghost.)


 No.529059

>>527138

you're better off telling him the grammar not the meaning.

for example: float can be used in the context of casting, function declaration, and variable declaration, and knowing it means decimal point of fixed size is not going to help him understand that shit.


 No.529317

>>527138

>>529059

You are both just adding more confusion.

Float is a floating-point number. It's basically a decimal number like 3.0, 5.7 or 3.14. The important part is that the number of decimal digits can vary (float), hence the float name. And if you are wondering, when the number of decimal digits is fixed we call it a fixed-point number.

Integers are whole numbers like 3, 5 or -7, no decimals here.

A string is a sequence of characters, usually enclosed in quotation marks. The string "hello" is a sequence of five characters 'h', 'e', 'l', 'l' and 'o', in that order.

What's a character? An integer number that maps to a human-understandable character via some arbitrary table. ASCII is a very old standard that uses one byte for every character, see >>527129 for the table. There is nothing in the computer that makes it "understand" those characters, for the computer they are just numbers. It wouldn't make sense to add 'A' + '!', but to the computer that's no problem because they are just numbers. It's human interpretation that gives those numbers their purpose. If we look at the table we see that 'A' = 65 and '!' = 33, so 'A' + '!' = 65 + 33 = 98 = 'b'.

What would happen if our result was larger than the number of characters in the standard? It depends on context, we might get some non-standard character that the computer manufacturer added as an extension to ASCII, the number might loop back around or the program might crash because it doesn't know how to deal with the exception.


 No.529320

>>529317

I was just demonstrating how the definition of float on it's own was useless.

that nigga should read a fucking book if he wants to learn or fuck off if he doesn't.


 No.529430

>>529317

>Integers are whole numbers like 3, 5 or -7, no decimals here.

How the fuck is the 7 in -7 not a decimal, octal or hex? Same for 3 and 5.


 No.529497

>>529430

You know what I mean, there is no decimal point, they are whole numbers, integers.

https://en.wikipedia.org/wiki/Integer


 No.529754

File: 1456273841835.png (84.32 KB, 1000x1000, 1:1, 1413586962790.png)


 No.529796

>>529430

in mathematics, an integer is a subset of the reals

but programming is not mathematics, and often has certain differences (mostly for the sake of optimization)

a floating number is more difficult to represent than a whole number is, and more computationally expensive to operate on.

In other words

int + int is computationally simpler than float + float

so 7 + 7 is simpler than 7.0 + 7.0

despite being mathematically equivalent, they are not computationally equivalent.

and thus, in programming, 7.0 is not the same as 7 (because they are represented using two different rulesets). And so when discussing it from the programming perspective, 7 is not a decimal number. From the mathematical perspective, it quite obviously is.

And some languages expose this difference in the language itself (the strongly-typed languages) and others hide it (the dynamically-typed languages). There are benefits/losses to either route.


 No.529823

>>529796

Thanks!


 No.529908

>>526064

it's just (1 * line_number) spaces before your word

then print the word

then (line_max - 1 - line_number) spaces after the word

then erase (line_number + length(word)) characters, then print the word again

and then go to the next line, and loop

with the loop going from 0 to line_max

the erasing is just so, if the word is multiple characters, the second printing of the word overrides the first printing when the X begins to "collide" near the center

which causes the "layered" effect you see here >>524138, with the second word being "on top" of the first


 No.530047

File: 1456318729814-0.gif (62.48 KB, 863x808, 863:808, LC3_h1.gif)

File: 1456318729814-1.gif (24.95 KB, 1114x695, 1114:695, LC3_Instructions.gif)

>>527138

>What do you mean by this? What are you referring to as a "computer" here?

A computer is anything with the appropriate combination of transistors that takes an input and gives you an output based on that input. That's pretty vague though. Is a single transistor switch a computer? I would say yes, it pretty much is. An extremely restricted computer with the smallest instruction set architecture possible. It only has two outputs, on and off, and two inputs, "enough voltage" and "not enough voltage".

What you typically think of as a computer though doesn't have just a few transistors. It has literally billions. They're all arranged in specific ways so that you can input dozens or even hundreds of instructions and get an output based on those. That is what programming is. Programming is writing those instructions. At some point the processor needs to be told

Here's an instruction set for a "fake" computer. Nobody makes a real LC-3 computer, it's just a really nice simplified teaching tool for this kind of stuff. The code in the second picture is the "Instruction Set". That's literally all of the things, and only those things, that this computer is capable of doing. All programs that can ever be compiled no matter how complicated are broken down into these simple instructions.

Take a look at the ADD instruction.

>0001 DR SRI 0 00 SR2

What the DR, SR1, and SR2 mean are "Destination register", "source register 1" and "source register 2". These registers are just locations in memory where you store numbers. One single instruction might look like this

>0001 001 010 0 00 011

The processor gets this instruction and goes

>0001, okay I'm going to ADD

>001, okay the shit I'm adding goes into Register 1

>010, okay the first number I'm adding is stored in Register 2

>0 00, this is just filler not used in the ADD instruction

>011, okay the second number I'm adding in stored in Register 3

This is kind of fucking hard to write by hand though. It's all binary. So we invented assembly language. Assembly language is literally that binary code, but we just used letters instead of binary because humans can't read that shit. The same instruction in assembly would look like,

>ADD R1, R2, R3

This is what's going to happen when you, say in C or some "high level" language, program a statement to add two simple numbers,

>x = 2+5;

Although this is a liiiiiitle different because the location of the variable x isn't a register, but somewhere else in memory, so really it's two instructions,

>ADD R1, R2, R3

>STR R3, offset

Where offset is literally "the number of steps from the current memory location to the destination memory location". Doing that step by hand is a pain, but it's pretty fucking easy for compilers to automatically figure it out.

So you can see how a few simple lines in a programming language like C could actually "represent" many many lines of assembly. Even something like a single line of

x = 10/4;

may actually compile down into a dozen or several dozen individual Assembly steps to divide the number. Or if you're lucky and your processor actually has a dedicated division arithmetic unit it will be just a single instruction, and only take up a single CPU cycle instead of dozens.


 No.530050

>>530047

Actually I lied, it's not two instructions to add two numbers in LC3. It's more because you have to set the values of the registers you're adding first too. So simply saying x=2+5 will give you code that, logically, needs to say

>Set the value of this register to 5

>Set the value of this other register to 2

>Add those two registers together, put the result into yet another register (or one of the same registers it'll just overwrite)

>Take that result register and then store it in the correct memory location

So it's really FOUR instructions to do basically one of the simplest things imaginable.


 No.531445

/* Assignment 5: Reverse an array */
char a[N];
int i, j, tmp;
for(i = 0, j = N-1; i < N; ++i, --j)
{
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}


 No.531464

>>531445

kek

so close but so far


 No.531492

>>523423

>>523446

>>523459

>>523701

I assume there's code to find the other root and to handle negative and imaginary roots. What about loss of significance?


 No.531728

>>531445

Great code.

It took me some time to understand what was wrong.


 No.532468

>>529796

Floats are not more computationally expensive to operate on, it is actually the opposite. That's literally the whole point of floats besides representing decimals, multiplication and division in floats take MUCH less complexity given the amount of bits of a number. Go take a look how many cycles an integer DIV instruction takes in a state of the art x86-64 processor, you will be surprised, it is the most expensive arithmetical operation by far.

Their downside is arbitrary precision, which makes them also not good to represent integers, including multiple other reasons too, but none of them are computational complexity, the addition and subtraction is almost the same with some constant overhead.

>>530047

A computer doesn't need transistors to be a computer. A computer is anything that takes an input in some way and produces an output (both interpreted as information), using somehow a predetermined recipe or program to make it so. A Turing machine doesn't need transistors for example. You can even say a block of wood is a computer since it takes any physical data and returns the same data without changes, effectively computing the identity function on the data.


 No.532486

>>532468

>Floats are not more computationally expensive to operate on, it is actually the opposite.

Jesus..


 No.532672

>>532468

>You can even say a block of wood is a computer since it takes any physical data and returns the same data without changes, effectively computing the identity function on the data.

Complete lunatic confirmed.


 No.532678

>>532672

A black penis is a computer, since it takes any woman and returns a cumdumpster.


 No.532703

>>531445

It doesn't say you have to return the reversed array, the array does reverse during operation.

Congrats on your B.Sc, anon.


 No.532737

>>532678

I'd argue it was this way before.


 No.532774

>>532737

Perhaps it's just a convenient interface to woman.asCumdumpster()


 No.533044

>>532703

It also didn't say the array to be reversed needed to be initialized :^)


 No.533053

>>523781

here is my solution in C:


#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
int in = atoi(argv[1]);
for (int i = 0; i < in; i++) {
for (int j = 0; j < -abs(((in-1) / 2)-i)+((in-1) / 2); j++)
printf(" ");
printf("*");
for (int j = 0; j < (abs(((in - 1) / 2) - i) * 2) - 1; j++)
printf(" ");
printf(abs(((in - 1) / 2) - i) ? "*\n" : "\n");
}
return 0;
}

any way this could be improved?


 No.533079

>>533053

>any way this could be improved?

Disregarding things like even numbers and error handling:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
int in = atoi(argv[1]);
for (int i = 0; i < in; i++) {
int halfway = in / 2;
int indent = halfway - abs(halfway - i);
printf("%*c", indent + 1, '*');
printf("%*s", (halfway - indent) * 2 - 1, "");
if (i != halfway)
putchar('*');
putchar('\n');
}
return 0;
}

printf has its own indenting feature, so we can use that. Also, if you find yourself using the result of a mathematical expression more than once, put it into a variable.

In things like "(abs(((in - 1) / 2) - i) * 2) - 1" I would consider making a variable even if you never used it anywhere else, simply because the mathematical expression you have there is difficult to intuitively grasp. Breaking it into smaller pieces by adding a variable greatly helps.

In my code you can see that "halfway" is the index of the character halfway into the figure being drawn, while "indent" is how far it's indented by spaces on that line. This makes things like "(halfway - indent) * 2 - 1" a little easier to read. It's still not something you can immediately look at and recognise, but you have more of a starting point than just the shape size and the current line being printed. You can think about it for a second or so and conclude that it's the distance from the middle, doubled (because it's symmetric around the middle) and minus one character (because the shape is an odd number wide).


 No.533084

>>533079

Thanks a lot for the help, this is some pretty nice code. The only thing I dont understand about your solution is the syntax for printf here:

>printf("%*c", indent + 1, '*');

>printf("%*s", (halfway - indent) * 2 - 1, "");

I've never seen anything like %*c or %*s before. How do I use them?


 No.533279

>>533084

printf can specify the width of something it prints and pad it out with spaces.

printf("%40s\n", "Hello");
The above will print a line containing the word "Hello". The entire line will contain 40 characters, "Hello" will be at the very end of the line, and the rest will be filled with spaces.
                                   Hello
Like that.

The "%*s" syntax is an extension of this. It allows you to specify the width of the print in your argument list, rather than hard-coding it in your format string.

printf("%*s\n", 40, "Hello");
The above will give the same output as the first piece of code. Except, in this form, it's easy to swap out the 40 for some variable and change the number of spaces on the fly.

A simple demonstration, including the cheeky use of "%2d" in printing the width:

#include <stdio.h>

int main()
{
for (int i = 1; i < 20; i++) {
printf("Width %2d: (%*s)\n", i, i, "Hello");
}
return 0;
}


 No.533280

It might also interest you to use "-i" in the printf in that example rather than "i" and see what happens.


 No.533282

>>522753

>CamelCase

What's wrong with that?


 No.533291

>>533282

Autists don't react well when they see something they personally don't like.


 No.533293

>>533282

ThereIsNothingWrongWithCamelCase


 No.533296

>>533282

It's harder to read for non-native English speakers (because the words aren't as clearly delimited), and it's poor style to make fields camelcase in every language except C#, and I'd argue that it's poor form to use C# at all.


 No.533304

>>533296

>bad for non-native English speakers

Sweet! Unfortunately I'm a fan of kebab-case (no kebab), but I'll see what I can do to introduce IndiansGoHome case into inferior languages :^)


 No.533306

>>533304

#problematic_speech


 No.533311

>>533296

That's a pretty bad point to be perfectly honest. Some of the most readable code I've ever seen was in pikestyle, where everything is shortened and pretty much only type names have capitals. There's no input_file_descriptor, nor inputFileDescriptor, just infd. It's shorter to write and as a mnemonic (which is all it really is) it's just as descriptive.


 No.533325

>>533304

>religion-of-peace-case

Is Lisp halal?


 No.533396

>>533311

Pikestyle just makes it a bitch to get into a library.


 No.533573

>>533279

That's not part of the standard, is it?

>>533296

I'm a non-native speaker and I don't find camelCase harder to read than snake_case.


 No.533594

>>533573

>That's not part of the standard, is it?

It's documented in `man 3p printf` so it's POSIX compliant, but I haven't checked the C standard itself.


 No.533619

>>533279

never knew you could do that, thanks for sharing


 No.534187

>>522765

>>522737

i'm impressed at how bad this is while being operational


 No.535560

>>534187

Autists write awful code but they are so incredibly focused and dedicated that they can make it work anyway.


 No.535649

>>524547

php doesn't even use real arrays by default so


$mime['html'] = "text/html";

works fine too


 No.535668

>>532486

>>532672

He's somewhat right on the floating point case though.

Multiplying a binary32 floating point number entails adding two 8-bit exponents together and multiplying 2 23-bit mantissas which results in a smaller CSA reduction tree. Since these two operations can be done in parallel it's genuinely cheaper time-wise to multiply floats.

It's much more apparent in division since that's an iterative algorithm using a table lookup. So what you end up with is an 8-bit integer subtraction and a 23-bit division instead of a 32-bit one. It's not an entirely linear progression but you are chopping almost a third off of the linear time part.

Addition is horrendous though. Like just absolutely awful. I think it scales lg(n) like a normal integer adder with a prefix network but I can't remember. Intel claims they can do binary32 and binary64 addition in 3 cycles on Core2 and newer (vs 1 cycle 32-bit integer addition on literally all processors ever and 1 cycle 64-bit integer addition on all processors with 64-bit register files).


 No.535685

>>535668

>He's somewhat right on the floating point case though.

He's fucking not. Test it yourself instead of LARPing.


#include <iostream>
#include <stdint.h>
using namespace std;

int main(int argc, char *argv[]) {
#ifdef RETARD
volatile float x = 1;
#else
volatile int x = 1;
#endif
for(uint64_t i = 0; i < 1000000000; ++i) {
x *= 12345;
}
cout << x << endl;
}

foo@foo:~$ g++ -O3 foo.cc && time ./a.out

-775753727

real 0m2.678s

user 0m2.676s

sys 0m0.000s

foo@foo:~$ g++ -O3 -DRETARD foo.cc && time ./a.out

inf

real 0m3.339s

user 0m3.336s

sys 0m0.000s


.L2:
movl 12(%rsp), %edx
imull $12345, %edx, %edx
subq $1, %rax
movl %edx, 12(%rsp)
jne .L2


.L2:
movss 12(%rsp), %xmm0
subq $1, %rax
mulss %xmm1, %xmm0
movss %xmm0, 12(%rsp)
jne .L2

model name : Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz

Fucking webdev javascript IDF.

>inb4 that's because Intel isn't as smart as anons on /tech/ and implemented it wrong


 No.535715

>>535685

M8, I really don't want to draw comparisons of a floating point and fixed point ALU for you. Especially the dividers. It'll take hours and then presumably an eternity to explain it to you. Just give it a rest already, and if you're actually interested in how digital arithmetic works, read a book: http://www.amazon.com/Digital-Arithmetic-Kaufmann-Computer-Architecture/dp/1558607986


 No.535846

>>535715

>gets BTFO

>keeps LARPing

>anon on /tech/ explains why Intel implemented it wrong


 No.535946

>>535846

Nah. Why don't you just keep pretending that you didn't just benchmark the how many shadow registers your particular OOO pipeline could allocate in those two exact cases or how many fxp multipliers are available compared to how many fp multipliers are.

Your line of argumentation is like me claiming attribute((packed,aligned(32))) is standard C because GCC compiles it.

Are you seriously going to gloat when you've never even written any multipliers and probably have no idea how one works? Chess, pigeons, and all that.


 No.536020

>>535946

Nice LARP. Go ahead and cycle-time it with cpuid + rdtscp to clear the pipeline (read the docs, faggot) and you'll still see floats are still FUCKING SLOW no matter what excuse you want to use.


 No.536241

>>536020

Intel aggressively pipelined the FPU, a unit for which most people care more about throughput and less about latency, to save power? Well color me surprised.

It's nice to know that the >>>/g/ spirit is alive and well, so let's see if I can explain this so that people may laugh at you.

Floating point multiplication is deceptively simple. you have two numbers of the form (-1)^s*2^e*1.m which means multiplication becomes 2^(s1+s2)*(1.m1*1.m2) with sign selection separately. Let's ignore subnormals, Inf and NaN for now. This means you need a 23 bit fxp multiplier for the mantissa and an 8 bit fxp adder for the exponent. A 23-bit multiplier would entail generating 23 23-bit partial products, which you push through a 23 level carry-save adder tree to end up with a 46 bit partial sum and after adding that you need to subtract from the exponent to divide down to a 23-bit sum again. Assuming you do some clever prefix networking you can calculate almost all the IEEE required nonsense in parallel with this and mux at the end, increasing your logic depth by only 1.

Compare that to a purely fxp multiplier. Your CSA tree will be 32 levels deep and your final product will be 64 bits wide. The critical path will be bit 0 through carry 63 so having to only carry through 54 bits is quite a relaxation. Furthermore it's not exactly true that the CSA tree will be as deep as the number of bits you put in - with a bit of trickery we can get that down a couple of levels but I'm too lazy to calculate the actual depths.

So why do some DSPs still use fxp? (the vast majority doesn't but the last one I worked on did). Because FP requires a lot of area and power if you want it to be fast and since area inherently, just by existing, costs power it's really not that useful when you're trying to not use so much power or have multiple data paths with limited area and so on. Of course this problem basically goes away if you ignore IEEE requirements like subnormals but generally when you want FP you want all of it.

But actually let's just stay on your level of argumentation: talk to me when you have your own work committed to silicon. I bet you've ever even synthesized an ASIC before.


 No.536267


 No.536477

>>536241

>Well color me surprised.

I guess so, seeing as your first and second excuses were wrong and this is now your third attempt.


 No.536492

>>536477

Okay m8. Stay strong. People will tell you that you shouldn't presume to lecture people on multiplication when you don't know how to do it but you stay strong.


 No.536498

> Float multiplication is more expensive in this specific program I wrote for this specific architecture running on this specific chip model.

> Therefore, float multiplication is more expensive in the absolute.

> PS: I also did not verify whether or not the chip itself was performing any optimizations on my non-FP loop compared to my FP loop.

That's some solid fucking science there.


 No.536513

>>536498

>float multiplication is actually faster, I just can't point to a single modern architecture where it isn't the opposite

>I'll just make lots of excuses for why objective test cases disagree with me and provide no test case supporting my view

>I honestly am unable to see how obviously full of shit I am

LARPer. Test case or GTFO.


 No.536540

>>536513

				; to compile this code:
; nasm -f elf64 test.asm
; gcc -o test test.o

extern printf

SECTION .data ; data section
str1: db "Results with integer multiplication: %d", 13, 10, 0
str2: db "Results with floating-point multiplication: %d", 13, 10, 0
time1: dq 0
time2: dq 0
int1: dq 42
int2: dq 1234567
float1: dd 42.0
float2: dd 1234567.0

SECTION .text ; code section

global main ; make label available to linker (Go)
main:

; setup stack frame
push rbp ; save old base pointer
mov rbp,rsp ; use stack pointer as new base pointer

; initialisation
mov rbx, [int2]
fld dword [float2]
fld dword [float1]

; integer multiplication
align 16
rdtsc
mov [time1], rax
mov rax, [int1]
%rep 50
imul rbx
%endrep
rdtsc
sub rax, [time1]
mov [time1], rax

; float multiplication
align 16
rdtsc
mov [time2], rax
%rep 50
fmul st0, st1
%endrep
rdtsc
sub rax, [time2]
mov [time2], rax
finit ; reinit the FPU

; print results
mov rsi, [time1]
mov rdi, str1
xor rax, rax
call printf
mov rsi, [time2]
mov rdi, str2
xor rax, rax
call printf

; takedown stack frame
mov rsp,rbp ; use base pointer as new stack pointer
pop rbp ; get the old base pointer

; return
mov rax,0 ; error code 0, normal, no error
ret ; return


 No.536541

>>536540

Compile it on a 64 bits Linux distro.

The results are never the same (because fucking magnets, how do they work?), but on my machine, floating point multiplication is typically 4 times faster than integer multiplication.

Results with integer multiplication: 89
Results with floating-point multiplication: 24


 No.536545

>>536540

>>536541

You need a serializing instruction like cpuid to clear the pipeline otherwise the instructions you're testing will likely be out of order and happen before or after the rdtsc. You should also be using rdtscp and not rdtsc to get rid of the randomness. I already mentioned both in >>536020 and to read the documentation. The documentation:

http://www.intel.com/content/dam/www/public/us/en/documents/white-papers/ia-32-ia-64-benchmark-code-execution-paper.pdf

I'm pleased by the effort, though. More code, less talk.


 No.536546

>>536540

Btw, that code also has stalls that will make it hard to time correctly. I'd recommend timing only 1 instruction instead of repeating 50 times on the same registers as that's simpler to test and is the core of this argument.


 No.537105

>>535649

Yes, it uses ordered maps, but then you don't get to use variable variables:


return static::$mime[$ext] ?? "text/plain";

is boring compared to


return static::$$ext ?? "text/plain";

Which looks completely drunk with the ::, $$ and ??


 No.537124

File: 1457214301260.jpg (113.83 KB, 808x499, 808:499, iHBwrqa.jpg)

CS Undergrad here who also works part time as a Web Developer

I only started programming last year but I am learning a ton and the skill is fun and challenging.

Seeing these memes makes me worry that all I will produce is shitcode.

What steps do I take to avoid being a shit programmer?


 No.537142

>>522694

Java 8 has switch statements on Strings.


 No.537152

>>537124

>Seeing these memes makes me worry that all I will produce is shitcode.

>What steps do I take to avoid being a shit programmer?

Apart from obvious "read a book":

Step 1: Stop being such a fucking pansy

Step 2: Write some shit code

Step 3: Get criticized for it, absorb valid criticism and improve


 No.537166

>>537124

youre going to write shit code mostly because you dont give a fuck. It might not be "new averaging system" bad, but itll be ugly and slow becase you can't give it 100% every single time and dont want to waste time on something that isn't very important ESPECIALLY if it's a real fucking boring job like a wordpress site.


 No.537335

>>537124

>CS Undergrad

>Web Developer

>started programming last year

It's already too late, anon.


 No.542381

>>523913

sure smells like NIH in here.


 No.542414

File: 1457895443909.jpg (7.44 KB, 480x360, 4:3, hqdefault (1).jpg)


 No.543214

File: 1457994228132.jpg (39.99 KB, 600x800, 3:4, Minigirl.jpg)

>>523802

It's your fucking neck deserve to be cut for determining MIME by file extension.

Allright nigger. What mime type is "afa4a90b23b9edbc83dabbcb6a67870e"? No ideas?

Also, does that shit - https://github.com/file/file - which is example of proper file type determination - looks like (>tiny amount of text parsing) to you, moron?

Also "text/*" without charset clause is worthless. "application/xml" and "application/javascript" are too.

Also returning unrelated types (string and bool) from function. If language does not check types, it does not mean you should write such shit.

Also javascript. I assume it's serverside, so go choke on smoothie.


 No.543341

File: 1458005979148.png (131.39 KB, 989x314, 989:314, 2016-03-15-010540091880555.png)

>>543214

when the alsoposting game strong


 No.543342

but I do agree completely


 No.543373

>>543341

It's called audisme, anon.


 No.543539

>>536545

Made this, tried to use SIMD to make a more fair comparison between DQ integers and doubles.

If I add multiple repetitions floating point doubles seem to consume 20% more cycles.


; to compile this code:
; nasm -f elf64 test.asm
; gcc -o test test.o

extern printf

%define iterations 5000000
%define repetitions 1

%macro MEASURE 0
rdtscp
sal rdx, 32
or rax, rdx
lfence
%endmacro

SECTION .data
str1: db "Results with integer multiplication: %lu", 13, 10, 0
str2: db "Results with floating-point multiplication: %lu", 13, 10, 0

align 16
int1: dq 42
int2: dq 1234567
double1:dq 42.0
double2:dq 1234567.0

SECTION .text

global main
main:

push rbp
mov rbp, rsp

xor r12, r12
xor r13, r13

mov rdi, iterations
.loop:
movdqa xmm0, [int1]
pshufd xmm1, xmm0, 0b01001110
movdqa xmm2, [double1]
pshufd xmm3, xmm2, 0b01001110

; integer multiplication
MEASURE
mov rsi, rax
%rep repetitions
pmuludq xmm0, xmm1
%endrep
MEASURE
sub rax, rsi
add r12, rax

; float multiplication
MEASURE
mov rsi, rax
%rep repetitions
mulpd xmm2, xmm3
%endrep
MEASURE
sub rax, rsi
add r13, rax

dec rdi
jnz .loop

; print results
mov rsi, r12
mov rdi, str1
xor rax, rax
call printf
mov rsi, r13
mov rdi, str2
xor rax, rax
call printf

mov rsp, rbp
pop rbp

mov rax, 0 ; error code 0, no error
ret


 No.543541

>>543539

Forgot to add, with the code as is they take the same amount of time roughly.


 No.543754

>>543373

I looked that word up and it's apparently a french word for discrimination against deaf people.

Not entirely sure what to make of that.




[Return][Go to top][Catalog][Post a Reply]
Delete Post [ ]
[]
[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]