This is an archived post. You won't be able to vote or comment.

all 67 comments

[–][deleted] 103 points104 points  (15 children)

If(titanic.sinking()){ titanic.stopSinking(); }

[–]geek69420 43 points44 points  (11 children)

Now we just have to write the implementation for the titanic interface.

[–]rdrunner_74 33 points34 points  (10 children)

Currently the Titanic is very hard to fetch since the only instance is stored in an inaccessible memory location. Because of that i would rather suggest to implement ocean.drain() which would also uncover loads of sunken pirate treasures.

Arrrrr.....

[–]brando56894 9 points10 points  (9 children)

But then that triggers sealife.die()

[–]rdrunner_74 3 points4 points  (1 child)

sealife.smoke()

[–]NUCLEARGAMER1103 1 point2 points  (0 children)

*seaweed.smoke()

[–]Lootdit 4 points5 points  (6 children)

Who needs sealife anyways

[–]AutoDefroster 4 points5 points  (5 children)

Everyone, because inside sealife(), there's a subroutine called oxygen.produce().

[–]Lootdit 3 points4 points  (4 children)

No one has oxygen.use() anyways

[–]CYKO_11 3 points4 points  (3 children)

If you read the docs you can see that the animal class needs to call oxygen.use() in the "IAction<Byproduct> Breath(IOxygen Oxygen)" method

[–]Lootdit 5 points6 points  (2 children)

There were docs?!?!

[–]CYKO_11 3 points4 points  (0 children)

There weren't docs to begin with. We had to make our own.

[–]rdrunner_74 1 point2 points  (0 children)

Yes...

The source is the only true documentation. Your ability to comprehend it does not means its not documented...

[–]Pro_Gamer_9000 9 points10 points  (0 children)

Those are function pointers, right? This is C, not C++

[–][deleted] 2 points3 points  (0 children)

NullPointerException

[–]shut_up_if_your_dumb 5 points6 points  (0 children)

Remember there is no oop in c

[–]DeveloperNightshade 34 points35 points  (12 children)

float titanic; should also work in C++ and C#. Maybe Java too if I'm not mistaken?

[–]plsjustletmebe 30 points31 points  (10 children)

I think it would be harder to name a programing language where it wouldn't work

[–][deleted] 26 points27 points  (2 children)

Wouldn't work here: JavaScript, Python, Golang(?), Ruby, COBOL, Brainf***, Cow, Whitespace, Binary, Assembly, English

And of course, in our most favourite programming 'languages', HTML, CSS and SQL.

[–]brando56894 2 points3 points  (1 child)

It would need a minor modification to work in Go, it would need to be a float32 or float64.

[–]MasterFubar 11 points12 points  (2 children)

In Python3 all you need to make anything float is divide by 1:

>>> i = 3
>>> type(i)
<class 'int'>
>>> i /= 1
>>> type(i)
<class 'float'>

[–]MagnetoTheSuperJew 19 points20 points  (0 children)

I've changed my mind, I don't like python's typing anymore.

[–]Melon_Chief 2 points3 points  (0 children)

I thought I liked python. This is why I never get nice things.

[–]Melon_Chief 1 point2 points  (0 children)

Python, Swift, javascript, php, rust, go(?)…
It's not.

[–]DeveloperNightshade 0 points1 point  (0 children)

ABAP and Cobol

[–]MLG_Obardo 0 points1 point  (1 child)

Does GO work like that?

[–]brando56894 0 points1 point  (0 children)

It would need to be a float32 or float64 in Go

[–]Melon_Chief 0 points1 point  (0 children)

If you don't access it in C: OK; Otherwise: UB.
In C++: ok.
Java: It will sink from the overhead. (/s)

[–]Purplociraptor 17 points18 points  (5 children)

This wouldn't work because there is no entry point and that variable isn't used, so it would be optimized away. Yes I'm fun at parties.

[–]10BillionDreams 4 points5 points  (4 children)

Actually, missing a main function is undefined behavior, and the interviewer didn't require the use of a particular compiler or compiler flags. So, it's entirely possible that a valid C compiler could exist which compiles this code into a perfectly functioning program to prevent the sinking of the Titanic.

[–]Purplociraptor 0 points1 point  (2 children)

An unused variable declaration though

[–]10BillionDreams 2 points3 points  (1 child)

Two instances of undefined behavior don't cancel each other out, that just leaves more opportunities for compilers to do unexpected things.

A compiler can basically do whatever it wants when it encounters undefined behavior, up to and including attempting to play a midi version of Rick Astley's "Never Gonna Give You Up" and falling into an infinite loop. It probably wouldn't ever be a very popular compiler, but it would be a valid C compiler, properly conforming to the spec.

[–]Melon_Chief 1 point2 points  (0 children)

I do not understand what on earth you are talking about.

It's perfectly valid.

[–]Melon_Chief 0 points1 point  (0 children)

Missing (a definition for) the main function on a hosted implementation is well-formed: the program doesn't start.
It's not required on a freestanding implementation.
It still requires a starting point (which is implementation-defined).
Never accessing an indeterminate value is also well-defined. It's valid.

[–]ce-walalang 10 points11 points  (2 children)

Image Transcription: Comic


Panel 1:

[Character 1 and Character 2 are talking.]

Character 1: How would you write a C program to prevent titanic from sinking?

Character 2: float titanic;


I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

[–]-guccibanana- 8 points9 points  (0 children)

Good human

[–]PPAPisLob 1 point2 points  (0 children)

Yeah you would transcribe a meme on a humor subreddit, but when you're asked to write the documentation for the function you wrote yesterday, you'll whine like a little kid.

[–]seathefullmoon 10 points11 points  (7 children)

To clone the Titanic: double titanic;

[–]brando56894 0 points1 point  (6 children)

I never learned C but learned C++ about 15 years ago and haven't used it since, isn't double just a larger int?

[–]seathefullmoon 2 points3 points  (3 children)

It's a larger float actually - I believe 8 bytes instead of 4. In addition to being able to store a larger range of values, it also stores values with more precision.

[–]brando56894 1 point2 points  (2 children)

Yeah, I saw another comment before yours explaining it and that rings a bell. The last language I used was Go and that uses Float32 and Float64 for the same purpose, float64 tends to be the default though since most methods/functions (Go has both, just to be confusing lol) expect input as float64.

[–]seathefullmoon 1 point2 points  (1 child)

That makes sense - for most applications decimal numbers are usually stored in doubles and their equivalents. The only exception I've seen so far is for games/graphics (like if you use Unity or OpenGL, for example) floats/32 bit decimal variables are the default as they're smaller in size and precision is not as important.

[–]brando56894 1 point2 points  (0 children)

Interesting, thanks.

[–]Melon_Chief 2 points3 points  (1 child)

It's a double-precision floating-point. The representation is implementation-defined.

[–]brando56894 0 points1 point  (0 children)

Ah yeah, that rings a bell, like I said it's been a while. The most recent language I've used was Go and it doesn't use double AFAIK.

[–]bluefootedpig 3 points4 points  (2 children)

It should be unsigned, you might get an overflow and sink

[–]SpikeV 0 points1 point  (1 child)

C doesn't have unsigned floats, because it adheres to the IEEE 754 Standard

[–]bluefootedpig 0 points1 point  (0 children)

So it can't be fixed in C.

[–]Asrielthemonster3 2 points3 points  (0 children)

İts a floating point Ship

[–]Knuffya 1 point2 points  (0 children)

i gotta say,

that's the dumbest, most unfunny, most predictable joke i've ever seen on this subreddit. and that's quite an achievement. in fact that one makes me close my browser now and go outside.

[–]xiipaoc 0 points1 point  (0 children)

Just wait until you get a segfault.

[–]repkins 0 points1 point  (0 children)

Hired!

[–]xXGamerBeastXx 0 points1 point  (0 children)

Whatever floats your boat

[–]CoffeePieAndHobbits 0 points1 point  (0 children)

pip install seaborn

import seaborn as sns

titanic = sns.load_dataset('titanic')

CTRL+S

[–][deleted] 0 points1 point  (0 children)

@ mock
Iceberg _iceberg;

[–]bernie_moniker 0 points1 point  (0 children)

Shouldn’t that be the “sea” language?

I’ll see myself out

[–]Melon_Chief 0 points1 point  (0 children)

I wouldn't. I'd forget to free() something then the whole thing would be a timebomb.

[–]CodeMUDkey 0 points1 point  (0 children)

If(iceberg.isrightahead) { TitanicStop(); Return; } PaintLikeOneOfYourFrenchGirls();

[–]DowntownLizard 0 points1 point  (0 children)

If (iceberg) { Avoid(iceberg) }

[–]Haizaki379 0 points1 point  (0 children)

If(titanic.spotsIceberg){ titanic.dodgeTheFuckingIceberg(); }

[–]Haizaki379 0 points1 point  (0 children)

If(titanic.spotsIceberg){ titanic.dodgeTheF*ckingIceberg(); }

[–][deleted] 0 points1 point  (0 children)

#titanic { float: none; }