[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 28
File: goto-il-1.png (107 KB, 624x432) Image search: [Google]
goto-il-1.png
107 KB, 624x432
/dpt/ - GOTO Edition

Friendly reminder that if statements, loops, and constructors are all syntactic sugar for GOTO.
Friendly reminder that functions, generators, and the "return" statement are all syntactic sugar for GOTO.
Friendly reminder that GOTO is a turing-complete operand and is the only operator required for programming.
>>
>>51470789
first for go
>>
>>51470789
First for F#
>>
I really really like this image.
>>
>>51470789
third for XOR
>>
>>51470821
It's all yours my friend
>>
>>51470812
Looks like Go is faster than F#
>>
>>51470828
thanks lori
>>
File: bugs in the program.png (6 KB, 991x26) Image search: [Google]
bugs in the program.png
6 KB, 991x26
>>51470789
how?
>>
Cast your vote if you haven't done that yet.
https://strawpoll.me/6069029

Make sure to read the question carefully.
>>
File: C.png (136 KB, 2000x2126) Image search: [Google]
C.png
136 KB, 2000x2126
>>
File: 1446244063159.png (187 KB, 600x450) Image search: [Google]
1446244063159.png
187 KB, 600x450
>>51470789
Is this a new meme?
>>
>>51470874
>Haskell - Employed (3 votes)
fucking kek'd

>>51470877
me too thanks
>>
>>51470872
overflow
>>
So, here's the thing. When I started programming I didn't directly see or notice GOTO statements for a while. I was being mentored by someone and when we first experienced a GOTO statement, he was almost stunned, as if the person coding had some how written "NIGGER" in the code. I asked what the big deal was and he explained that GOTO statments are retarded and that you should never use them.

From what I've read further, a lot of people seem to share this sentiment, but why exactly? I can kinda understand that it *might* make code a little harder to follow, but I just don't understand the malice towards it.
>>
[CODE]OBSOLETE GARBAGE
B A
S R
O B
L A
E G
T E
E [/CODE]
>>
>>51470874
>lisp not mentioned
>not even as an example for other
fuck you m8
>>
failure cases are one of the still applicable uses of goto
not like anyone on /g/ would know anything beyond fizzbuzz in java
>>
>>51470872
You forgot to initialize.
>>
>>51470915
It's still considered the other group, though.
>>
File: ezgif-2034144198.gif (4 MB, 340x222) Image search: [Google]
ezgif-2034144198.gif
4 MB, 340x222
>>51470874
>C++ - unemployed
>>
File: m72tska.webm (331 KB, 600x360) Image search: [Google]
m72tska.webm
331 KB, 600x360
Ask your much beloved programming literate anything.

>>51470789
>Friendly reminder that if statements, loops, and constructors are all syntactic sugar for GOTO.
>Friendly reminder that functions, generators, and the "return" statement are all syntactic sugar for GOTO
Couldn't be more wrong.
>>
>>51470892
Your mentor is a retard.
Read this: https://blogs.oracle.com/oswald/entry/is_goto_the_root_of
>>
>>51470892
>as if the person coding had some how written "NIGGER"
lost

I'm a newb, I've started learning programming three months ago, and I remember seeing articles on the web that GOTO is something that you should be ashamed of if you've ever used.

I remember when trying to learn Fortran 8 years ago, goto were sometimes very neat to use.

And there are Labels in Java that are similar to Goto.
>>
File: tripfag enters thread.gif (3 MB, 370x208) Image search: [Google]
tripfag enters thread.gif
3 MB, 370x208
>>51470706
All tripfags think of themselves as a personality.
>>
>>51470808
you mean GoTo sempai?
>>
>>51470906
nicememe

>>51470892
Look at the pic in the OP. The code in the red box caused a massive security hole in OS X and iOS that compromised the security of millions of people for a remarkable amount of time.
All because of a misplaced "goto".

The reason that goto is hated isn't only because it produces spaghetti code, but because it's by nature unsafe. There's no way to really trace when a goto happens. There's no way to follow, from a programming point of view, where the execution went.

Goto is totally fine if you're using it for really simple stuff, such as error handling in languages that don't support trycatches.

Other than that, there's not much use for them and they're downright dangerous when used carelessly.
>>
>>51470892
Your mentor is a fucking retard who can't program.
>>
>>51470957
when i lived in poland, we had ducks, they were fucking cute
>>
>>51470866
>>51470384
how is being an anarcho-christian-libertarian-capitalist-statist not a contradiction on itself?
>>
>>51471024
I once met a fellow who styled himself as an anarcho-monarchist.
Crazies will do anything to remain relevant.
>>
File: Untitled.png (51 KB, 1380x900) Image search: [Google]
Untitled.png
51 KB, 1380x900
>>51470957
Couldn't be more wrong.
>>
>>51470985
>All because of a misplaced "goto".
No, it's because the programmer who wrote that shit was so dumb that he repeated a statement twice and didn't know what block statements are for. The goto statement occurs by default because the if statement is written incorrectly. It's only dangerous for people that don't even know if statements.
>>
>>51470978
? i wasn't using a trip.
>>
>>51471068
Thanks for explaining to the class how if statements work.
>>
>>51471071
I'm talking about GTP.
>>
File: csegfault.jpg (30 KB, 360x399) Image search: [Google]
csegfault.jpg
30 KB, 360x399
>>51470877
>>
File: what is even this guys problem.jpg (68 KB, 788x603) Image search: [Google]
what is even this guys problem.jpg
68 KB, 788x603
>>51471048
>auto main(int, const char **) -> int
>>
>>51470985
Autoformat your fucking code, so the semantics don't go out of sync with the implementation, or just use Python, or a vaild merging algorithm, if there's one thing this whole thing taught us, it's that. Sure, with some braces, the problem would have been less damaging, but still, duplicating a line, whether it's a function call, an incremental assignment or what, can have unintended consequences, the only answer you can really give is to proofread more, and therefore to make your code more readable with format and KISS. I heard an ingineer say that we needed a special dsl for low-level crypto application, which would be both theoretically and humanly safer than C, and I agreed
>>
>>51471087
well those were my words, not his.
>>
>>51471093
#define forever while(isfaggot(you))
>>
File: musthavelastone.webm (750 KB, 426x426) Image search: [Google]
musthavelastone.webm
750 KB, 426x426
>>51471048
You are confusing concepts with their implementations.

Syntax sugar is when you add new syntactic constructions to a programming language without extending the semantics.

For example, a Tuple in ML is syntax sugar for a Record where the fields are implicitly named 1,2,3,...,n.
The semantics for Tuple are exactly the same as the semantics for Record since a Tuple is actually a Record.
At the end, you have unchanged the semantics of your programming language, therefore Tuple are syntax sugar.

Another example in C are the arguments followed with [] which are the same as pointer arguments (same semantics).

You can not implement the if, while or return statement with just the goto statement and syntax sugar (because of typing, for example).
>>
https://github.com/golang/go/wiki/SliceTricks
What is this bullshit? I just want something like std::vector.
>>
>>51470789
Naked if statements are a crime against humanity

It's a good thing that Go has outlawed that nonsense
>>
>>51470874

TIL: most people on /g/ are unemployed
>>
>>51471164
>Another example in C are the arguments followed with [] which are the same as pointer arguments (same semantics).
You probably also think that their sizes will be exactly the same.
>>
>>51470957
Thanks for the offer! :-)

I'm well employed in IT, and I have a degree and a number of certifications, but I haven't programmed anything in more than 10 years.

Right now, alot of the problems I have could be solved if I had a little more programming skill.

Interestingly enough, my kids are showing alot of interest in MIT's 'Scratch' and I think its a brilliant way to teach kids.

So, my question is: Is there a development environment like scratch that could help small children and linguistically challenged idiots like myself?

Peace
>>
>>51471176
http://blog.golang.org/slices
>>
>>51470789
this is why brackets are shit. If it was a whitespace language like ocaml this would be much easier to catch. Or more likely wouldn't have happened in the first place.
>>
>>51471217
Probably also a lot of students.
>>
>>51471224
code.org, probably the best site for young child.

https://code.org/mc
https://studio.code.org/hoc/1
>>
>Trying to make a calculator in assembly
I don't understand how I'm supposed to be multiplying and dividing. I can see how multiplying or dividing by 2^n you just shift the decimal point right or left over n times but I don't understand how I'm supposed to do it for any number.
>>
>>51471224
learn python
>>
>>51471280
mul
>>
>>51471293
Its certainly at the top of my list.
What is the easiest way for me to get started with development?
>>
>>51471280
Binary is cool because you can uniquely decompose the multiplicator into a sum powers of two in order to generalise bitshift multiplication

Try to wirk it out! Renember : (a+b)*c = ac+bc
>>
>>51471386
*sum of
*work

No bully pls
>>
>>51471386
>sum powers of two in order to generalise bitshift multiplication

I'm not sure what the second equation is supposed to suggest, but (for multiplication) would it be practical to lets say, subtract the number you're subtracting by 2^n, store the amount of times I did that in a variable (x), then if there's 1 left, store the number you're subtracting from in variable (y), shift that number x times to the left, then add y.
>>
File: lain.png (844 KB, 815x638) Image search: [Google]
lain.png
844 KB, 815x638
Still working on my "Living in the fast Lain" VN, in which you play as 19 y/o Lain Iwakura, a Japanese exchange student in her first year at MIT. You meet Stallman, and fall in love. You mean Torvalds and learn truths. You find Jobs and get robbed.

Anyone have any suggestions?
Github:
https://github.com/gitgood/Living-in-the-fast-Lain
>>
>>51471498
Does it contain nudity?
>>
>>51471510
It might. Do you want it to?
>>
Isn't that the goal of all VN's? Building a relationship and having sexy time.
>>
>>51471447
I'm not sure I understand and I think you are going down the wrong path of overcomplication there desu. I must mention tho that the simple algorithm I'm thinking of isn't the most efficient one, and that WP has a whole huge page about optimising multiplication on chips, but let's start with the naïve version shall we ? Iterate over the bits of the multiplicator from the LSB, counting your steps, and you'll see a pattern form
>>
>>51471379
install gentoo
>>
>>51471548
I mean, ideally it would have lewd scenes but I'm not 100% on board with photoshopping stallman in to pornographic situations at the moment
>>
>>51471591
I'll give it a try. Lucky you, you've taken my VN virginity.
>>
>>51471379
install and run python
https://www.python.org/about/gettingstarted/
https://docs.python.org/2/install/
http://docs.python-guide.org/en/latest/starting/installation/
there are lots of (free) guides, docs, books, etc., so just google it
>>
>>51471623
There's no real point trying it at the moment, unfortunately. I'm trying to get it as done as I can really quickly then refine the story line, but it's slow workings.
>>
>>51471280
Didn't you learn "long multiplication" and "long division" in school? Those algorithms work just as well in binary, and they're much simpler, as the multiplication table is 2x2 rather than 10x10.
>>
File: goto.png (26 KB, 740x201) Image search: [Google]
goto.png
26 KB, 740x201
>>
> teaching programming freelance
> C++ (good semantics, start with the safer aspects, always compile with warnings, and go deeper slowly. Haters gonna hate but IDGAF)

What can I answer if a student asks me what the difference is between a pointer to a scalar object and a pointer to the zeroth element of a singleton array?

string x;
string y [1];
char cheap_random; // undefined value, if this offends you, get over it
string* p = cheap_random % 2 ? &x : y;
cout << *p << p[0]; // 100% ok
p[1]; //don't
--p; // don't either
>>
>>51471865
one points to something we know and one points to something we don't
>>
can someone help me spot the segmentation fault?

// Function printInReverse prints sublistToPrint in reverse to the standard output.
void printInReverse(BestIncreasingSublist sublistToPrint, Mountain *mountainArray, BestIncreasingSublist* seeker, BestIncreasingSublist* target)
{
if(seeker->next == target)
{
printf("%s %i\n", mountainArray[seeker->mountainArraySpot].name, mountainArray[seeker->mountainArraySpot].elevation);
printInReverse(sublistToPrint, mountainArray, &sublistToPrint, seeker);
}
else if(&sublistToPrint!= target)
{
printInReverse(sublistToPrint, mountainArray, seeker->next, target);
}
}


the main at that section looks like this
    BestIncreasingSublist result = findLongest(sublistArray);
BestIncreasingSublist* seeker = new BestIncreasingSublist;
printf("main: calling printInReverse\n");
printInReverse(result, mountainArray, seeker, NULL);
>>
>"To deal with the need to manage all types of resources and to release them as soon as they can be released, best-practice C++ code relies on a language feature called deterministic destruction.

>In C++, one way that objects are instantiated by users is to declare them in the scope of a function, causing the object to be allocated in the function’s stack frame. When the execution path leaves the function, either by a function return or by a thrown exception, the local objects are said to have gone out of scope.

>When an object goes out of scope, the runtime “cleans up” the object. The definition of the language specifies that objects are cleaned up in exactly the reverse order of their creation (reverse order ensures that if one object depends on another, the dependent is removed first). Cleanup happens immediately, not at some unspecified future time."
-Jon Kalb, el al

Thoughts? Is Sepples wasting lots of cycles or is it Doing The Right Thing™ ?
>>
>>51471896
Well, it just does automatically what you would have to do manually anyways.
>>
>>51471865
>what the difference is between a pointer to a scalar object and a pointer to the zeroth element of a singleton array
One has a different address than the other.
Other than that, nothing.
>>
public class Constants {
Constants(){}
public static System.Text.RegularExpressions.Regex REGEX_IMAGE { get { return new System.Text.RegularExpressions.Regex(@"http://images\.4chan\.org/\w+/src/\d+\.(?:png|jpeg|jpg|gif)"); }; }; };


I'm not sure if C# is the best or worst language I've ever used.
>>
>>51471896
RAII vs garbage collection, at least it's deterministic, as he says.
>>
>>51471093
>blames the language for his own mistakes
>>
>>51471661
>>51471567
Okay I'm retarded, my language has a built in multiply and divide, just for integers though.
>>
>>51471224

Trying to go one step up from scratch is basically java/python.

java/python at their core are extremely simple languages with IDE's that will nanny you accordingly.
>>
>>51471948
yes. yes, it is anon.
>>
>>51471896
>hur dur how does the stack work
Every language that can use the stack including C does this.
>>
>>51471893
That's what debuggers are for m8. Also it's not a bad idea to use assert() to check preconditions in functions (pointer arguments shouldn't be null, etc). Saves a lot of time if something goes wrong.
>>
>>51471985
The C runtime automatically destroys resources when the stack frame is exited?
>>
File: mosaic.png (1008 KB, 984x927) Image search: [Google]
mosaic.png
1008 KB, 984x927
Nice la
>>
>>51471928
>>51471891
Thanks anons

>>51471896
Clearly so much better anon. Put some life into those stack frames. An object must start with a constructor, and die in a destructor. That's what I tell'em. Add in copy/move constructors, the reverse order if they haven't guessed it themselves, and you're done!
>>
>>51472018
Not C. But C++ does for the most part, providing there's a destructor that instructs it to.
>>
>>51472018
GNU has a extension for it actually.
>>
>>51471948
how is that good? people laugh at java for that kind of syntax. kinda funny that they don't say the same shit about C#...
>>
>>51472018
The runtime doesn't.
Objects allocated on the stack naturally and automatically get de allocated when the stack frame exits because that's just how the stack works.
>>
>>51472132
. . .
hmm, i just wonder.
>>
>tfw the C standard says nothing about stacks
>>
>>51471896
>Is Sepples wasting lots of cycles
No, because you'd have to do it anyways.
>>
>>51471896
http://www.oreilly.com/programming/free/files/c++-today.pdf
>>
>>51472182
Automatic storage and function calls pretty much imply an abstract model of a stack, methinks
>>
>>51471948
well its definitely much not worse than java
>>
>>51472221
>methinks
Fuck off.
>>
>>51470789
printf("asdf");
5;
printf("asdf");


Why are meaningless expressions valid C code? Is there a specific reason for this?
>>
>>51472221
The host CPU is free to not implement a stack and C will run just fine.
>>
>>51472270
Everything has both a value and a potential side effect. You just showed there that you might want to call something and discard its value but use the side effect (printf), and when you call "5;" you're discarding a value and using no side effect.
>>
>>51471923
Yeah I guess, I'd probably forget to sometimes.

>>51472022
>chkd
do move constructors 'move' things from one frame to another anon?
>>
>>51472291
Yeah, C will run just fine until you call a function or declare a local variable.
>>
>>51470789
>GOTO is a turing-complete operand

How do you do conditional jumps without ifs, genius ?
>>
>>51472050
I see.

>>51472085
I didn't know that thanks.

>>51472193
Yeah the other anon said as much. Makes sense I guess.
>>
>>51472317
if (condition) goto block;
>>
>>51472102
Java's syntax is bad because it's garbled. C#'s isn't garbled, it's just VERY explicit. Overloading is a huge part of C#, so in order to prevent ambiguity you can specify more or less everything you want to.

namespace get { public class Constants {
Constants(){}
public static System.Text.RegularExpressions.Regex REGEX_IMAGE { get { return new System.Text.RegularExpressions.Regex(@"http://images\.4chan\.org/\w+/src/\d+\.(?:png|jpeg|jpg|gif)"); } } } }


Could easily be rewritten as:
using System.Text.RegularExpressions;
namespace get { public class Constants {
public static Regex IMAGE = new Regex(@"http://images\.4chan\.org/\w+/src/\d+\.(?:png|jpeg|jpg|gif)") } }


Which is cleaner but more or less the same thing. The `Constants(){}` and code relating to the `get { return new[...]` is just for disambiguation.
>>
>>51472349
>without ifs
>>
>>51472291
>The host CPU is free to not implement a stack and C will run just fine.
Wow that's interesting. I guess it's hard for me to even imagine a computer not using a stack.
>>
>>51472270
C is compiled, not interpreted, so it'd be silly to implement a system that runs through every code fork to see what has meaning and what doesn't.
>>
>>51472353
while (condition) goto block;
>>
>>51472317
label:
while(wtv) {
try {
AssertEquals(x, y);
} catch(Error e) {goto label}
}


your move, atheist
>>
>>51472317
In C++, the `switch` statement is quite literally a reinterpretation of the `if` statement using GOTO as a base.
>>
>>51472388
>>51472390
>implying while isn't syntactic sugar for if+goto
>>
>>51472182
>>51472291
>>51472314
Hmm, how would one go about doing a stack-free implementation of a language with called procedures? I mean, Touring machines don't have stacks technically so I suppose you could do it, I just can't think how.
>>
>>51471498
You have made yourself officially unemployable. Congrats.
>>
>>51470957
Why does my A* run slower than Dijkstra? Is the heuristic non-admissable, and if so why?

https://github.com/enfiskutensykkel/a-star
>>
>>51472401
You asked for no ifs. There are no ifs in those snippets.

Your move, atheist.
>>
>>51472304
They copy destructively, and if you have a resource, it was here and now it's there, so it clearly "moves", of course you have to explain it in details and it is my job. The 'if they gaven't guessed it already' was meant solely for reverse order which can be considered common sense (depends on people, that's fine if you dont)
>>
>>51472401
>implying if isn't syntactic sugar for for(;;)+goto
>>
>>51472388
>>51472390
>>51472398
>>51472417

>X is just syntactic sugar for Y, I swear!
>You don't need anything but Y!
>Look at these examples where I use X!
>>
>>51472401
cmp eax
jnz block
>>
>>51472314
You are a retard.
>>
>>51472434
>jnz
>jump IF not zero

That's a branch, so that counts as an if.
>>
>>51472298
But everything else usually is a statement, a command to the computer. "5", however, is just... 5. It doesn't instruct the computer anyhow, unlike a print statement or assignment, so why does it have to be allowed? Yes, some instructions also hold a value (non-void functions) but they're still instructions too, unlike 5.
>>
>>51472413
Allocate every frame on the heap. It would make every function call a continuation, but in practice that's not needed so a stack is more efficient.
>>
>>51472435
So tell me, how do you call a function and return without a stack?
Go on, enlighten me.
>>
>>51472413
> touring machines
What a pleb who goes on holiday
"beach.jpg"

> mountains captcha
> and what's more, I live in Switzerland
>>
>>51472503
Oh come on it was a simple fucking mispelling
>>
>>51472480
The compiler won't generate any code for it, you're right, so why worry about it?
>>
>>51472486
See >>51472485.
Use the heap. The stack is an optimization.
>>
>>51472486
>So tell me, how do you call a function and return without a stack?
You don't need a hardware supported stack.


Lets say you have a register R0 containing addresses. When you call a function, the return address is stored in R0. When you return, the address is loaded from R0.

Your C implementation therefore implements its own software stack, copying addresses to and from R0.
>>
>>51472422
Thanks. Yea I get the reverse order thing from Kalb's comments, I just wasn't sure about move construction as it pertains to stackframe lifetimes.

Thanks anon.
>>
>>51472480
Not all statements are instructions.
Labels, for example, are not instructions, but are valid "statements" in a sense.

Forgive my C++ faggotry, I'm not that familiar with stock C:
#include <iostream>
int main(){
std::cout << "Hello, world!" << std::endl;
0;
a:
b: true; c:
1;2;3;4;5;6;7;8;9;d:e:f:g:h:i:j:k:l:m:n:o:p:
if(){}
};
>>
Covariant return types
>>
>>51472577
Yes, they are.
>>
>>51472533
>Use the heap as if it was a stack.
That's called a stack fucktard, a really inefficient stack.

>>51472545
>call foo()
>call bar() within foo()
>return from bar()
>return address from foo() clobbered form bar()
>return
>...
Nice "stack" you have there.
>>
>>51472602
You didn't even read my post retard.

I clearly said copying the return address to memory and then popping it off again, as in your own software implementation of a stack.

There are plenty of architectures that doesn't support stacks in their instruction set, where you manually need to keep track of your stack pointer.

>That's called a stack fucktard, a really inefficient stack.
The point was you don't need a hardware stack.
>>
>>51472513
Yeah obviously, but seems weird it would still allow that.

>>51472565
Hmm, I don't think a label can be a statement at all because the definition of a statement is that it instructs the computer to perform some action. Label is more like just meta-information for the compiler that it uses when turning code into assembly statements. I might be wrong.
>>
>>51472602
>That's called a stack fucktard, a really inefficient stack
And that's why it's dumb to not usually use a linear stack.

However, if you want to create a continuation, you need to either allocate the frame on the heap or copy the frame to the heap when the function yields, so that you aren't constrained to FIFO like with a linear stack.
>>
>>51472602
>>51472628
Since you're too stupid to comprehend this.

Use R1 as dedicated stack pointer

Before calling function:
increment R1 by size of address
copy value of R0 into memory at position [R1]
call foo

On return
return/leave
decrement R1 by size of address
copy from memory at [R1] to register R0

Voilá, you have a software stack for return addresses.
>>
Is this accurate or is this guy full of it?

http://www.lextrait.com/vincent/implementations.html
>>
>>51472628
>The point was you don't need a hardware stack.
No, original argument was that C does not need a stack at all which is wrong.
>I clearly said copying the return address to memory and then popping it off again
No you didn't.
>When you call a function, the return address is stored in R0. When you return, the address is loaded from R0.
So R0 contains the return address of the current function, but since R0 can only hold one value because it is a register, any previous value gets overridden.
>>
>>51472689
He is a retard.
>>
>>51472702
>No, original argument was that C does not need a stack at all which is wrong.
No, it was not, you fucking cocksucker.
The original argument was that the C standard says nothing about stacks and the next was that you don't need a hardware stack.
>>
>>51472679
That isn't what you described at all in your other post.
>>
>>51472702
>No, original argument was that C does not need a stack at all which is wrong.
C does not need a stack at all, C doesn't care how you handle stuff.

>No you didn't.
Yes, I did:
>>51472545
>Your C implementation therefore implements its own software stack, copying addresses to and from R0.
>copying addresses to and from R0.
>copying addresses to and from

>So R0 contains the return address of the current function, but since R0 can only hold one value because it is a register, any previous value gets overridden.
Jesus christ how can you possibly be this stupid?

Just see >>51472679 already
>>
>>51472710
Why?
>>
>>51472741
It is, see >>51472744

It's clearly what "copying to and from R0" meant. Just because you're too stupid to infer that, doesn't mean that was exactly what was implied.
>>
>>51472744
>C does not need a stack at all
Than explain how you call a function without a stack.
Protip: a software stack is a stack, using the heap as a stack is a stack.
>>
>>51471164
Syntactic sugar is a super broad term. For example, list comprehensions and do are considered to be syntactic sugar in Haskell. In fact, they get translated down to more complex monadic expressions at compile time, but they're semantically distinct from their normal equivalents. In that sense, C's loops would be the same. For example:
int n;
for (n = 0; n < 10; n++) {
printf("%d\n", n);
}

is equivalent to:
int n;
n = 0;
while (1) {
n++;
if (!(n < 10)) break;
printf("%d\n", n);
}

and, again, that is equivalent to:
int n;
n = 0;
loopTop:
n++;
if (!(n < 10)) {
goto loopBottom;
}
printf("%d\n", n);
goto loopTop;
loopBottom:;

obviously they're all a bit different, but you can easily define it in terms of rules:
for a for loop, make the declaration, open up the while (1) loop, put the incrementing bit first, then put the negative check (to break out), and finally put the body in.
When converting to a goto loop, you can say to open the loop up with the n = 0; bit then add the top and bottom gotos. Inside of them you increment and then add the negative check (as before), but with
goto loopBottom;
instead of just breaking, and finally but the body followed by the goto for the top of the loop.
In fact, if C macros allowed you to do just a little more these could be easily implemented in terms of macros.
>>
>>51471100
What does that code even mean
>>
>>51472781
if a heap could stack stacks how much stack would a heap stack if a heap could stack stacks
>>
C++ is the best language
>>
>>51472824
*D
>>
>>51472639
At first glance that's true, but then you realize that conditionals make that impossible.

string in;
std::cin >> in;
if(atoi(in) == 0) goto a:
if(false) a: std::cout << "Where's your god now?" << std::endl;


Common logic states two things:
1: Metainformation in the source code, such as preprocessor directives and labels, shouldn't make it into the assembly.
2: The contents of a statement starting with if(false) should never run.

My little example here shows how those two things prove each other false. The compiler CAN'T just discard the if(false) statement because it's possible that it'll be run anyway due to the label, which means that it has to be compiled, which means that the label (or, more accurately, the goto) has to end up in the binary somehow.

I'm not super familiar with assembly but I'm pretty sure that the compiler will compile this into code equivalent to the following:
string in; std::cin >> in;
if(atoi(in) == 0) std::cout << "Where's your god now?" << std::endl;


because GCC is far smarter than you will ever be, but you get the general idea.
>>
>>51472798
n_ram / sizeof_stack
>>
>>51472781
>Than explain how you call a function without a stack.
You don't fucking get it

From C's perspective, it doesn't fucking matter how you handle return addresses and local variables, which is why it isn't mentioned in the C standard.

Under the hood, you could store frames in a hashmap like data structure using a call counter as key.

Initialize call counter to 0

Everytime you call a function, increase call counter

Everytime you leave a function, decrease call counter

Store necessary data for every function (like return address) in a hashmap or array like structure (inb4 that's a stack hurr durr).
>>
>>51472849
>Under the hood, you could store frames in a hashmap like data structure using a call counter as key.
>
>Initialize call counter to 0
>
>Everytime you call a function, increase call counter
>
>Everytime you leave a function, decrease call counter
I.E. a stack.
>>
>>51472849
>inb4 that's a stack hurr durr
Yeah that practically is, and it's true that you need something stack-like at some point, but that doesn't change the fact that the standard doesn't demand this and the other guy is retarded.
>>
>>51472781
You don't have to use the heap as a stack. You allocate a frame every time you call a function, and free it when the function returns.

That it ends up looking like a stack is inevitable, since C doesn't have continuations. Point is, you haven't implemented a stack at all.
>>
>>51472831
>no preprocessor
It's shit
>>
>>51471498
Can you include a code of conduct please? I don't feel safe contributing to a project without one.
>>
>>51472878
>inb4 that's a stack hurr durr
>>
>>51472878
Say you had a computer that had a built-in feature that took care of the bookkeeping of function calls. You wouldn't need to use a stack at any point, just instruct the computer to call functions when turning your C code to assembly.
>>
>>51472884
>You don't have to use the heap as a stack. You allocate a frame every time you call a function, and free it when the function returns.
that's called using the heap you fucking retard.
>>
>>51472901
This
>>
>>51472913
Yes, I know. I'm the one who originally pointed out that you can just use the heap to store frames and the other guy said "that's a stack hurr durr".
>>
>>51472906
inb4 all you want but that's a stack.
>>
>>51472878
if you never decrease the counter it's not a stack :^)

Plus you could implement it as hash tables also probably.
>>
>>51472917
>>51472901
Guys that's just unfun, even ironically
>>
Aren't stacks just ordered strings, and heaps are just unordered string arrays?
>>
>>51470883
I'm one of the employed Haskellers, though I also work on other codebases. AMA
>>
>>51472824
It's got a lot of syntactic and other warts, but yea, agreed.
>>
>Arguing over 0s and 1s
>>
>>51472932
>if you never decrease the counter it's not a stack :^)
>>Everytime you leave a function, decrease call counter
>>
>>51472925
Stack's doesn't allow random access, only push and pop (and maybe peek). So *technically* it's not a stack, even though it is stack-like.
>>
>>51472945
How does it feel to know that the entire world is beneath you, for you have done what they will never be able to accomplish?
>>
>>51472940
I propose an entirely new programming language based on strings. Called STRINGS, it will be all strings, all the time.

>programming at a whole new level
>>
>>51472967
>Stack's doesn't allow random access
they do though.
mov eax, [esp + 24]
>>
>>51472985
If you implement a string as a list of characters then that's just Lisp, though
>>
>>51472945
What's your biggest Haskell project? Where did you learn Haskell? Are you one of those guys who would do anything to make their code 2 chars shorter neater and 2 times less readable, or are you one of the good guys? Do you think Haskell is more intuitive than imperative languages for beginners?
>>
>>51472965
Yes, if you don't do that, it's not a stack and C works just fine.

>>51472985
tcl?
>>
>>51472960
You CIS scum and your binary-only logic.
>>
>>51472985
You must have missed the discussion we had about a week and a half ago about strings.

To sum up, literally everything that could possibly be expressed is a string, because it can be expressed using some series of characters in an expressible language.

We're programming in the real world now, anon. And it is glorious.
>>
>>51470789
>Friendly reminder that if statements, loops, and constructors are all syntactic sugar for GOTO.
>Friendly reminder that functions, generators, and the "return" statement are all syntactic sugar for GOTO.
>Friendly reminder that GOTO is a turing-complete operand and is the only operator required for programming.
This is totally wrong, the GOTO as well as loops, if statements, etc are all implemented by the JMP statement in assembly and use a destination address which is usually a memory address or an offset to some memory addrress. Functions have their own registers in the CPU for keeping track of the stack address and the return address. This is why FUNCTIONAL PROGRAMMING is for efficient than imperative.
>>
>>51472987
Then it's not a proper stack anon

https://en.wikipedia.org/wiki/Stack_(abstract_data_type)
>>
>>51472994
>and C works just fine.
No it won't if you don't decrease the call counter.
>call bar() from foo()
>return from bar()
>return from foo()
Will fuck everything up if you don't decrement call counter.
>>
>>51472992
>>51472945
Also do you ever get stuck trying to form a clear picture of Haskell's semantics and patterns? Like how the do notation works in relation to monads, or what are good patterns of thought for writing complex recursive functions? It happens to me pretty often as an almost-intermediate Haskell hobbyist.
>>
>>51472987
Using the stack pointer is not the same thing as random accessing the stack. A true stack only supports push and pop as the other anon said.
>>
>>51472990
>>51472994
yup probably

>>51473004
HAH. And it's even programmed by typing in STRINGS to the STRINGS editor too.
>tfw i finally catch up
>>
>>51473001
>0
>1
>NULL
>EOF
>>
>>51472985
>it will be all strings, all the time.
So shell?
>>
File: 1387402504905.png (14 KB, 471x411) Image search: [Google]
1387402504905.png
14 KB, 471x411
>>51473056
>not using trinary logic
you're triggering me anon...
>
>>
>>51473088
>not recognising EOF
OPPRESSION! RAPE!
>>
>>51473065
Seems legit
>>
    Integer a = 1000, b = 1000;  
System.out.println(a == b); // false
Integer c = 100, d = 100;
System.out.println(c == d); // true


Javafags will defend this.
>>
>>51473096
Equal Opportunity Filesharing?
>>
>>51473004
>yfw every expressable string can be represented as a natural number.
Also I AM a robot.
>>
>>51473108
Please don't tell me this is real.
>>
>>51473108
>== for objects
Integer is a class.
>>
>>51473108
>it's the same way in Python
Python fags will argue against this.
>>
>>51473111
End Oppressing Fascists

>>51473108
Not Java fag, but the integer objects for values [-1023,1024] is cached in the JVM

http://pastebin.com/3QtGsVTQ
>>
>>51473121
>mfw the real world is written in binary
>mfw no face because my face is written in binary
>>
>>51473144
Extra Organic Fruit?
>>
>>51473122
See >>51473144
>>
>>51473108
woooo, caching is bad
>>
>>51473108
Integer != int
it's like saying, 'a' == "a" in other langs...
>>
>>51473145
Actually you're face is written in modulo-18 arithmetic anon. Six quarks with three things inside.
>>
File: Disgust.jpg (1 MB, 2024x2665) Image search: [Google]
Disgust.jpg
1 MB, 2024x2665
>>51473108
>separating declarations with commas AND semicolons
>>
>>51473156
Or you could just use the o1.equals(o2) method like you're supposed to.
>>
>>51473144
>let's make everything an object on the heap instead of having value types
>oops, that's not very fast so let's now cache thousands of integer objects in the VM
You can't make this shit up
>>
>>51473148
Endorsed Obama Frivolers
>>
>>51473136
>types and classes are separate objects

Why are you using this meme language and not based C#?
>>
>>51473144
Lol what a joke language.
Did the Java devs ever think of maybe implementing integers as you know, actual integers?
>java cannot reliably compare two integers.
Top lel.
>>
>>51473188
>you can't choose to wrap types as objects if you so desire

Why are you using this meme language and not C++/'C'++?
>>
>>51473188
It's the same for C#, the difference is C# probably overrided the == operator to use the equals method for fucking everything.
>>
>>51473176
>javafags need to use a function call to compare two integers
>>
>>51473195
>Did the Java devs ever think of maybe implementing integers as you know, actual integers?
Actually, they did
int != Integer

The former is a native type, the latter is a object wrapper type.
>>
>types aren't also values in his language
Are you even trying?
>>
File: i-see-what-you-did-there.png (18 KB, 510x304) Image search: [Google]
i-see-what-you-did-there.png
18 KB, 510x304
>>51473204
>C++/'C'++
>>
>>51473195
>>51473213
Integer != int, shitposter-san.
>>
>>51473216
Who the fuck in their right mind uses an Integer over an int?
>>
>>51473213
>javafags need to use a function call to compare two objects
FTFY

You're basically doing a comparison of object references.

It's like in C or C++

int* a = new int(2);

int* b = new int(2);

a == b; // false
*a == *b; // true
>>
>>51472992
>What's your biggest Haskell project?
a server
>Where did you learn Haskell?
with a few friends who were interested in functional programing and type safe languages
>Are you one of those guys who would do anything to make their code 2 chars shorter neater and 2 times less readable, or are you one of the good guys?
heh, I like to think I'm one of the good guys. In Haskell, the type signature is more important that then implementation so I find that I dont need to read code. If I see a function with signature
 Anon -> FourChan -> Thread 
, I dont need to look at the implementation details to that Anon goes to 4Chan and makes a thread and I shouldnt expect any other effects.
>>
>>51473235
You generally don't, but wrapper classes do come in handy from time to time.

Integer.parseInt(String s) for example.
>>
>>51473242
>he thinks "new" exists in C
>>
>>51473242
The point is that you need a function call to compare two wrapped integers (which are needed when you're doing things like generics) because == just compares references.
>>
>>51473235
lazy people i.e. programmers
>>
>>51473257
this is a terrible example

>>51473235
the only reason to use them is generics
>>
>>51473257
>Integer.parseInt(String s) for example.
Java has no way to parse a string to a normal integer?
>>
How's that .NET(tm) app going in your Microsoft(r) Visual Code(tm) editor Dpt? I mean you are using Microsoft(r) Visual C# arnt you?
>>
>>51473259
No, I don't. Now go choke invalid write of 4 bytes
>>
>>51473195
>>51473177
pretending to be retarded?
>>
>>51473269
Can you dereference a reference in Java?
>>
>>51473286
Putting everything on the heap is not a good strategy.
>>
>>51473269
>The point is that you need a function call to compare two wrapped integers (which are needed when you're doing things like generics) because == just compares references.
Yes that is exactly what I said.

>>51473283
Integer.parseInt returns an int, not an Integer.
>>
>>51473257
Is there any reason to use that when you have String.valueOf( Int x )?
There's some useful wrappers, e.g. BigInterger, but I've never understood the point of Integer, Double etc.
>>
>>51473296
Meanwhile putting everything on the stack is the epitome of good programming practice.
>>
>>51473309
wait fuck I'm retarded
>>
>>51473295
No, references are automatically dereferenced when you access members on it.

Basically, Java has no dereference operator. And the . operator is in reality equal to ->
>>
>>51473249
>I don't need to read code

Ladies and gentlemen, THIS is why Haskell is the future. I've been trying to fucking tell you this entire time, but no, I'm "a meme" and "use meme languages".
>>
>>51473295
You can "unbox" wrappers like Integer. Otherwise, every object is by default put on the heap and you can only deal with their references. Java doesn't have value types except for the basic primitives.

>>51473305
>Yes that is exactly what I said.
Alright, well you should know that this is bad unless the JVM can somehow inline it.

>>51473312
You're never forced to only use the stack, you always have a choice.
>>
>>51473283
>Java has no way to parse a string to a normal integer?
you just quoted it senpai
>>
>>51473249
>>51473340
And it only gets better when you consider languages with more expressive type systems (dependent types, linear types).
>>
File: false.jpg (60 KB, 638x479) Image search: [Google]
false.jpg
60 KB, 638x479
>>51473312
>>
>>51473344
>Alright, well you should know that this is bad unless the JVM can somehow inline it.
Why do you think the JVM caches values [-1023, 1024]? That's exactly why.
>>
File: _027.png (193 KB, 2560x1044) Image search: [Google]
_027.png
193 KB, 2560x1044
>>51473284
I'm writing C# on Linux using Mono right now. Happy?
>>
File: tfw no paladin gf.jpg (498 KB, 1200x1350) Image search: [Google]
tfw no paladin gf.jpg
498 KB, 1200x1350
>>51470789
>tfw submitted my assignment i've been working on for 2 weeks
>tfw that inkling of doubt that it didn't go through even after double checking
>>
>>51473367
>that wasted horizontal space
really, anon?
>>
>>51473296
Are you not aware that there are value types in Java?
>>
>>51473378
It comes in handy a LOT, just...not right now.
>>
>>51473344
>>51473295
>>51473335

Well, technically you can if you fiddle around with the sun.misc.Unsafe library.
>>
File: tttttttt.png (2 KB, 323x68) Image search: [Google]
tttttttt.png
2 KB, 323x68
Halp!

I have a 3d vector, that is the normal vector of a plane. The vector is normalized. Then im drawing a quad in opengl on the xy plane. I need to get 2 angles from the vector so i can use it later, also i need it to rotate this plane i drew on the x,y plane with two glRotate commands so that the vector is normal to this plane.

I have trouble at finding the right angles and axes. Right now im using pic related. Mook is a nigger and i cant post this code...

Whats the correct way to get the 2 angles to rotate this plane?
Whats the correct axis for glRotate to rotate around?
>>
>>51473387
If you're fine with using plain old ints and floats and never being able to do aggregation, then yeah, I guess so.
>>
>>51473395
What is this meme language you're using?
Thread replies: 255
Thread images: 28

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

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.