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

/dpt/ - Daily Programming Thread

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

Thread replies: 392
Thread images: 39

File: 1435541846284.jpg (1MB, 1920x1411px) Image search: [Google]
1435541846284.jpg
1MB, 1920x1411px
/dpt/ - Daily Programming Thread

What are you working on, /g/?
>>
>it's a hasklel spergs out about a feature his language omits episode
>>
>>57700909
kawaii
>>
>>57700909
konijinkontje
>>
4th for Clojure.
>>
Assistance with C++ templates requested.
>>57700504
>>57700667
>>
>>57700962
Well if you're gonna keep the template remove the =int part. Don't start with a specialization.

Also you may be interested in this later:
https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
>>
so im running a C# program that references a DLL file from a separate project.
when i export the project into an exe it works just fine, but when i try it on a different computer i get this error
 
System.IO.FileNotFoundException: Could not load file or assembly 'SudokuWrapper.dll' or one of its dependencies. The specified module could not be found.
File name: 'SudokuWrapper.dll'


the the DLL file is clearly in the same folder. i try dragging the DLL file into the exe and running it that way but i get the same error.
I put copy local to true in the DLL project but i still get this error.
>>
File: shot0033.jpg (310KB, 1920x1080px) Image search: [Google]
shot0033.jpg
310KB, 1920x1080px
/dpt/-chan, daisuki~

Ask your much beloved programming literate anything (IAMA)

>>57700954
What have you written in clojure?

>>57700909
Thank you for using an anime image.

>>57699810
Programming is one of the most difficult branches of applied mathematics; the poorer mathematicians had better remain pure mathematicians.

Also, https://youtu.be/FKFH_-QogN0?t=16m35s (go at 16m35s if you watch embedded)
>>
> let x = 1 + 2
> :sprint x
x = _
> seq x ()
> :sprint x
x = _


???
>>
>>57701000
>remove the =int part
Then the compiler complains that it can't deduce the type from the call signature. Naturallly, since there's nothing in the call signature to deduce the type from.
>>
>>57701006
I'd like to add that in the C# project the way i get it to work with the dll is I right click on the project node in solution explorer -> add -> Reference...
Then i use the file manager to locate and select the DLL which is in a separate project.
I know that this is the cause of the issue because other computers obviously don't have the file path that i have, which is why i thought setting copy local to true would fix the issue but alas, it didn't.
>>
>>57701075
Yeah so use a template for a function where it matters.
This has nothing to do with a header only library.
I just don't see why you decide to introduce stuff for no real reason.
>>
If you saw the posts yesterday about average functions, please post some solutions that properly round two ints' average. (away from zero).
>>
>>57701075
Like the other anon says, you're using a template where it doesn't make sense.

If you absolutely must, you can indicate the type to use when calling it like so:
PrintFoo<int>();
>>
>>57701046
> What have you written in clojure?
Nothing major. I'm not an actual programmer. I'm a 'wet' scientist.
>>
say I had a massive switch block with 100 cases

would it be a good optimization to run the program for a long tme and see which case gets "chosen" the most and put those in desc order?
>>
File: averaging 2 integrals.png (13KB, 474x178px) Image search: [Google]
averaging 2 integrals.png
13KB, 474x178px
>>57701127
this doesn't round, but for that you can do
round . avg
>>
>>57701127
>>57701156
*In pedantic c.
>>
>>57701156
(%) is the ratio constructor (i.e. a king of (/)), NOT modulo
>>
>>57701127
int avg(int a, int b){
double c=(double)a+(double)b/(double)2.0;
return (int)c;
}
>>
File: gentlesnake.jpg (124KB, 500x496px) Image search: [Google]
gentlesnake.jpg
124KB, 500x496px
why is x86 such a pile of shit?
can anyone explain the reasoning behind having only 4 registers etc?
there are other languages with more freedom and better features, why did the tech industry chose x86?
>>
Two things this weekend:

1) Working through a Data Science specialization on Coursera. It's all R programming and working with data sets.

2) OS homework due tomorrow by midnight. A small project (<250 loc) that interacts with the file system in various ways. Not too difficult, but I feel bad because I wanted to learn more C in this class, but due to time constraints I'm doing all the projects in Java. Where's Goku's time chamber when you need it?
>>
File: Untitled.png (472KB, 663x507px) Image search: [Google]
Untitled.png
472KB, 663x507px
>>57700909
Extension for Windows Firewall allowing to handle outbound connections and create rules automatically
>>
>>57701092
>This has nothing to do with a header only library.
It is of course possible that i'm taking an entirely wrong approach.
How do i implement a header library the right way then, according to you?

>>57701128
>PrintFoo<int>();
That's even worse, for this use case.
>>
File: maxresdefault.jpg (175KB, 1920x1080px) Image search: [Google]
maxresdefault.jpg
175KB, 1920x1080px
>>57701127
from num in nums.avg
select num
:[] :^) :&
>>
>>57701247
That's because your use case is shit.
>>
File: 33.png (277KB, 648x486px) Image search: [Google]
33.png
277KB, 648x486px
post a screen shot of your programming environment
>>
>>57701224
http://yarchive.net/comp/linux/x86.html

if you remove the segmentation memory model, which is now the case, x86 is the best ISA after VAX. VAX now being dead, x86 is the best.
>>
>>57701247
>How do i implement a header library the right way then, according to you?
https://github.com/nothings/stb/
This. He's an experienced programmer who prefers header only libraries.
I like his libraries too.
He does it perfectly.
And it's just 'write the fucking code'.
>>
>>57701224
Well, we use x86-64 now which has more registers
>>
>>57701206
are you FUCKING kidding me
>>
>>57701312
Better than "average int" assholes deserve.
>>
File: le shocked carl.png (56KB, 742x770px) Image search: [Google]
le shocked carl.png
56KB, 742x770px
>>57701312
>>
File: Table_of_x86_Registers.png (353KB, 3055x1075px) Image search: [Google]
Table_of_x86_Registers.png
353KB, 3055x1075px
>>57701224
>only 4 registers

Umm...
>>
>>57701329
t. I can't solve the problem
>>
>>57701403
t. someone who doesn't know how to use t.
>>
>>57701403
Of course you can't because you can't average (C) integers.
What you most likely aim to do is average integers. Which is an entirely different problem. And that's not possible on computers due to limited memory.

It's a completely arbitrary standard put up by idiots. Like you.
>>
>>57701127
Rate my (untested) solution guys
int avg(int a, int b) {
double result = a/2 + b/2;
result += ((a % 2) + (b % 2)) / 2;
return result;
}
>>
>>57701132
Most compilers turn switch statements above a certain length into binary search trees, so I doubt that would do anything.
>>
>>57701435
whoops i meant "double avg(", not "int avg("
>>
>>57700909

can you compute something like (999^999^999) mod (a number)?
>>
#include <stdio.h>

typedef struct {
int numerator, denominator;
} ratio_t;

ratio_t divide(int x, int y) {
ratio_t result;
result.numerator = x;
result.denominator = y;
return result;
}

int gcd(int x, int y) {
if (y == 0) return x;
return gcd(y, x % y);
};

ratio_t simplify(ratio_t r) {
int k = gcd(r.numerator, r.denominator);
return divide(r.numerator / k, r.denominator / k);
}

ratio_t inc(ratio_t r) {
ratio_t result = simplify(r);
result.numerator += result.denominator;
return simplify(result);
}

ratio_t dec(ratio_t r) {
ratio_t result = simplify(r);
result.numerator -= result.denominator;
return simplify(result);
}

ratio_t addInt(ratio_t r, int i); // TODO

ratio_t average(int x, int y) {
if (x == 0) return divide(y, 2);
if (y == 0) return divide(x, 2);
if (x == y) return divide(x, 1);
if (x == -y) return divide(0, 1);
if (x < 0 || y < 0) return dec(average(x + 1, y + 1));
return inc(average(x - 1, y - 1));
}
#define n 5
int main(void) {
int tests[n][2] = { { 7, 0 }, { 3, 4 }, { -3, 7 }, { 192, 33 }, { 396, 728 } };
for (int i = 0; i < n; ++i) {
ratio_t result = average(tests[i][0], tests[i][1]);
printf("%d/%d\n", result.numerator, result.denominator);
}
return 0;
}
>>
>>57701000
>>57701277
Use static, not template, derp.
Thanks guys. I'm glad i bothered to ask /dpt/ for help.
>>
File: image.png (215KB, 1680x1050px) Image search: [Google]
image.png
215KB, 1680x1050px
>>57701262
Still exploring the deepest, darkest corners or Racket.
>>
>>57701485
this is >>57701156 btw
i would love to test it on int_min and int_max but it would take at least int_min or int_max operations
>>
>>57701488
>Use static
Why? It has nothing to do with your stated issue.
>>
>>57701127
int AverageAndRound(int a, int b)
{
return Math.Round((a+b)/2d);
}

>>
>>57701433
Good points. Stay mad.
>>
>>57701469
Yes.
Key points:
x*y mod n = (x mod n)*(y mod n) mod n
x^(2n) = (x*x)^n
x^(2n+1) = x * (x*x)^2


>>57701492
Nigga why use such a beautiful language and such an ugly af font?
>>
>>57701485
Recursive in C.
>>
>>57701539
I'd like to see you average two integers
>>
>>57701506
What? It has everything to do with my stated issue. And it's how Sean T. Barrett solves it, it looks like to me at least.

What do you think my stated issue was?
>>
>>57701349
neat image
saved
>>
>>57701492
you should use haskell with sublime text in starbuks you know?
>>
>>57701127
I'm op. I posted the solution a couple days ago, and I think one person saw it. It was only 3 lines, 2 assignments.
>>
>>57701562
The average of 2 and 4 is 3.
>>
File: 2016-11-26-210530_503x314_scrot.png (10KB, 503x314px) Image search: [Google]
2016-11-26-210530_503x314_scrot.png
10KB, 503x314px
>>57701469
>>
>>57701605
Then post it again.
>>
>>57701190
please, just this once, can i get spoonfed.
I did enough "just figure it out" tasks already this is LITERALLY the last thing i need to do.
pls
>>
>>57701492
what is that challenge about? I see from some time but havent found the source
>>
>>57701608
Non-standard extension
>>
File: table.png (111KB, 3055x1075px) Image search: [Google]
table.png
111KB, 3055x1075px
>>57701599
optimized image to save space in your computer
>>
File: magician.jpg (3MB, 2448x3264px) Image search: [Google]
magician.jpg
3MB, 2448x3264px
>>57701127
return a/2 + b/2;

>me on the right
>>
>>57701633
https://www.reddit.com/r/dailyprogrammer/comments/5e4mde/
and
https://www.reddit.com/r/dailyprogrammer/comments/5emuuy/
>>
>>57701570
You're trying to make a header library, I guess, but it seems that you don't actually understand much of the syntax you're attempting to use.

'template<...>' makes a C++ template, in which a function will be generated new (at compile time) for each different template arguments you give it.
template<int X>
void foo () { std::cout << X << std::endl; }

foo<1>(); // generates foo<1> function
foo<2>(); // generates foo<2> function
foo<1>(); // calls the earlier generated function


'static' makes a symbol local to that file, so that you can redifine it with a different name in another file without it clashing.
// foo.c
static int x = 3;
// bar.c
static int x = 4;
/* different 'x' variables */

Since #include literally just pastes code into files, you can declare functions with 'static' in a header and include them into arbitrarily many files, and each file will get its own local copy of the function.

'inline' makes a function hinted by the compiler to be inlined (meaning the function body gets expanded instead of a call actually being done). In the (common) case that a function isn't inlined, it will just be a generated like normal function, except that if the function is generated in multiple different files, they will be joined as to not take up excess space in the executable.
>>
>>57701647
That's one of the worst solutions, I love it. It not only gives incorrect rounding, but also gives completely wrong answers.
>>
File: because why not.jpg (8KB, 243x138px) Image search: [Google]
because why not.jpg
8KB, 243x138px
>>57701645
you know what
I just save em both
>>
>>57701492
>>57701671

I'm going to try this in Haskell
>>
>>57701691
who cares
>>
>>57701599
The original is an svg. I only converted it to sate 4chan's uploader. Have the original:

https://upload.wikimedia.org/wikipedia/commons/1/15/Table_of_x86_Registers_svg.svg
>>
>>57701722
>Average of 5 and 7 is 5.
You should
>>
Why the fuck are there so many classes for Java I/O? I'm trying to learn how it works so I can save the state of my text game but it's a fucking mess.
>>
>>57701739
> python3
> 5/7
> 0.7142857142857143



why bother averaging numbers in C, when you can do it in python?
>>
>>57701703

Thanks, I really couldn't afford to take up that extra 200 kilobytes.
>>
File: a.jpg (69KB, 620x412px) Image search: [Google]
a.jpg
69KB, 620x412px
>>57701759
you know who is a mess?
>>
>>57701127
any programming languages?
do you have a test case?
>>
>>57701776
you're welcome!
>>
>>57701790
In C, I have a program that tests them.
>>
>>57701691
return (int) ((double) a / 2 + (double) b / 2)

>>57701739
ez
>>
>>57701759
(disclaimer: I'm not a java programmer and never use it) It's not uncommon to have a lot of writing methods for many languages because there are a lot of ways to write (even linux itself has several different system calls for writing to a fd). For GENERAL purposes, though, you want a writer that is buffered (so that you're don't get shit performance). From a 2 second google, this is probably what you want:

https://docs.oracle.com/javase/7/docs/api/java/io/BufferedWriter.html
>>
>>57701820
>I have a program that tests them.
post code
>>
>>57701827
Takes the floor, not rounding.
>>
>>57701687
>'template<...>' makes a C++ template, in which a function will be generated new (at compile time)
Which solves the problem. Although rather uglily, as demonstrated by my original solution.
I was looking at how gml does it, and they used templates for everything, although i suppose, with better cause than i had.

>'static' makes a symbol local to that file, so that you can redifine it with a different name in another file without it clashing.
Which also solves the problem. So why do you say it has nothing to do with my problem?

Are you saying i should inline everything instead, and that will work as well? I'm going to try that.
>>
I have been writing C and Java for years and I want to switch to C++. I can obviously just Google a tutorial to learn from it, but there is obviously a ton of overlap.

How would you go about learning it given how I already know a good chunk of it. What projects would you recommend?
>>
// true value = average + remainder/2
typedef struct result {
int average; // truncated
int remainder; // remainder * 2
} result_t;

result_t average(int x, int y) {
int z = x%2 + y%2;
result_t result;
result.average = x/2 + y/2 + z/2;
result.remainder = z%2;
return result;
}
>>
>>57701861
show me an incorrect result
>>
>>57701872
Some book, titled "C++ for [Java/C] Programmers" or similar.
>>
>>57701830
What does buffered mean in this context?
>>
>>57701832
I_IO.Default_Width := 12;
Open(Input_File, Mode=>In_File, Name=>"INPUT");

for I in Function_Names'Range loop
Reset(Input_File);
Put_Line(Function_Names(I).All);
Failure_Count := 0;

while not End_Of_File(Input_File) loop
I_IO.Get(Input_File, A);
I_IO.Get(Input_File, B);
C_Ada := Ada_Average(A, B);
C_C := Function_Array(I)(A, B);
if C_Ada /= C_C then
Put("Failed");
I_IO.Put(A);
I_IO.Put(B);
Put(" with output =");
I_IO.Put(C_C);
Put(" :: Expected");
I_IO.Put(C_Ada);
New_Line(1);
Failure_Count := Failure_Count + 1;
end if;
end loop;

Put_Line("Total Failures : " & Integer'Image(Failure_Count) & "/21");
New_Line(1);
end loop;
>>
>>57701889
5 and 6 takes the floor, outputting 5.
>>
>>57701897
It means that when you write to it, you're writing to a buffer that wont flush it's contents unless the buffer fills, or it otherwise has to in order to work. So instead of writing bits to the file arbitrarily, it does it in some multiple of the block size.
>>
File: img (2).png (26KB, 3050x1074px) Image search: [Google]
img (2).png
26KB, 3050x1074px
>>57701703
>>57701776
So wasteful. Why save all the color?
This image still contains the relevant information.

Though 32-bit and 64-bit may seem similar to the not so observant they're actually different colors.
>>
>>57701945
yeah obviously if the return has to be an int
there is no better solution than this
>>
>>57701930
>ada
i am so sorry.
>>
>>57701966
You can have a solution that outputs a correctly rounded number. If you believe 5 and 6 rounds to 5, you must also agree .99 rounds to 0.
>>
File: What I need.png (846KB, 812x637px) Image search: [Google]
What I need.png
846KB, 812x637px
Hey /dpt/.

I have a quick question:

Do you know if it's possible to align labels within a GridPane in JavaFX using CSS?

Previously I have made a HBox for each label, and then aligned the labels right inside the HBox. This approach is not a problem, but I would like to do it in CSS if possible.

Here's a screenshot, I'd like the labels to align so the end of the text is next to the corresponding button.
>>
>>57701947
Thanks. So Java I/O naturally reads/writes one byte/character at a time unless you use a buffer?
>>
>>57701966
Shouldn't 5.5 round to 6 by convention? Not 5.
>>
>>57701984
Is it too late now to say sorry?
>>
>>57701996
>Do you know if it's possible to align labels within a GridPane in JavaFX using CSS?
Yes that sounds possible
>tell me
No I don't care.
>>
>>57701993
The answer is incorrect anyway, 6 is just as wrong as 5
>>
>>57702064
That's great, anon. Good for you.
>>
>>57702076
>output int
>>
>>57702076
It's as correct as it can be
>>
>>57701996
What are you making?
>>
>>57701984
Who are you sorry for?
>>
>>57701127
int average(int x, int y) {
return x/2 + y/2 + (x%2 + y%2)/2;
}
>>
Why do we only have really boring memes.
Average 2 ints is lame. Either impossible or trivial depending on point of view.

Other than that all we have functional programmers jerking off all over the thread. It's disgusting.
>>
>>57702118
Just a random school project, it's supposed to be a program for holding and displaying information about animals in a zoo, as well as amount of stored food and costs. This CSS and stuff isn't obligatory but I'm too fond of exploring.
>>
>>57702142
Decent, but doesn't meet the rounding criteria in full.
>>
>>57702001
I'm not sure about java, just talking about the general case. But generally, the file-writer will do what exactly you ask of it. So if you do `write(my_file, "hello, world!", 13);` it will write 13 bytes to the file by calling the OS's write system call. The OS will then have to make that one block size big, by loading the block you will write to off the disk, masking the chunks that you are not going to write to, combining them, and then writing the whole block back to disk. This is obviously expensive as it sounds. So it is better to buffer until you have say 8KiB (so you don't have to read from disk to write, as you will write in multiples of any block size in the wild), or you are done writing, which ever comes first. This buffer class is just doing that busy work for you.

You may be wondering "Why not just buffer by default", and the answer to that is not every thing you can write to is a regular file, so buffering isn't always desired.
>>
>>57702170
It's very possible
>>
>>57702170
What makes it impossible?
As memes go, "average two ints" is somewhat educational.
>>
>>57702114
that's what I#m trying to say
if I round down or up is irrelevant, because either is wrong
it won't become more correct or anything

if your calculation relies on the correctness of the average, you won't ever return an int
>>
>>57701127
int avg(int a, int b)
{
return (((long) a) + b) / 2;
}
>>
>>57702187
oh shit i fucked up
nvm
>>
>>57702170
>make function x recursive
that's another dank /dpt/ meme
>>
>>57702238
You aren't rounding, you're taking the floor. It doesn't matter how useful it is, its an interesting challenge.

>>57702244
Doesn't round
>>
>>57701671
>>57701492
sounds like it's suited for prolog
>>
>>57702187
>rate me
i can't read haskell code
>>
>>57702291
it was type level bullshit but i typed the wrong thing so it was wrong
>>
one line factorial in python
fact = lambda x: x if x < 2 else x*fact(x-1)


post more one liners
>>
>>57702333
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
>>
>>57702218
>>57702231
Average -8 and 10 for instance. Doesn't work with doubles even. You need a bigger floatingpoint representation. And then Arbitrary-precision arithmetic will run out of space. And since int is not even defined by the language it's not portable.
>somewhat educational.
Not at this point.
>>57702277
That's far more interesting but I haven't seen it in months.

I want memes that are low effort to post but high mental challenge.
>>
>>57702193
Sounds like fun, keep it up!
>>
>>57702363
>Average -8 and 10
1
>>
>>57702280
>Doesn't round

int avg(int a, int b)
{
return (((long) a) + b) / 2 + ((b - a) % 2 == 0 ? 0 : 1);
}
>>
>>57702386
int avg(int a, int b)
{
return !((((long) a) + b) / 2 + !((b - a) % 2));
}
>>
>>57702194
By "away from zero" you mean e.g. -4.5 should be rounded to -5?
int half (int x) {
return (x >= 0) ? (x + 1)/2 : (x - 1)/2;
}

int average (int x, int y) {
return x/2 + y/2 + half (x%2 + y%2);
}


>>57702218
Not that anon, but my experience is that goal posts are generally moved a lot or rules are made up to retroactively invalidate solutions. A common one is using doubles when the question is just "average two ints" and then getting the reply of "you're wrong, doubles not allowed". It's childish.
>>
>>57702381
Sorry I picked the wrong numbers.
I don't do head counting.

There's numbers that don't go to integers and have too many digits for double.
>>
>>57702386
-5, -6 -> -4
>>
>>57702363
>Not at this point.
It is for noobs. And there's always noob. I, myself, haven't been hanging around /dpt/ for terribly long.
But yeah, the meme could stand to not be repeated quite as often.
>>
>>57702366
Learning new stuff is always fun, and I definitely will!

If you want to give it a go (for learning purposes), I can translate the assignment. I also have others that forces you to learn JavaFX, CSS, HTTP-communication, socket communication... Which are all useful things to know.
>>
>>57702436
I've done it with no doubles, and no conditionals. At this point I'd be happy with someone else having a solution at all.
>>
File: 1442196622289.png (102KB, 229x215px) Image search: [Google]
1442196622289.png
102KB, 229x215px
>>57702404
man I get real aids when I think about the fact that there are languages people have or even WANT to work with that don't allow this
>>
I'm making an application right now in Java that will use basic animated graphics that respond to code. I've never done something like this before, only ever back end coding and basic user interface, but people make apps with all the time in Java so there must be some common way of doing it.

What is the method and where can I learn about it?
>>
>>57702544
Why don't you post your superior solution for others to learn from?
>>
>>57702436
>>57702544

I just tested this, this is the best solution posted, since it works.
>>
>>57702590
JavaFX
>>
>>57702513
Yeah and it's practically every thread.
By comparison the "make this function recursive" or "make this function not recursive"
Is much more educational for newbies i promise.
Personally those transformations aren't that interesting but there's certain constraints we have to abide by here like being language agnostic.
Though the average C ints isn't.

It just really makes me feel bad to see that thing over and over. And we give it so much attention.
>>
justing making my irc bot more functional.
>>
File: wire defusal problem.png (246KB, 2178x904px) Image search: [Google]
wire defusal problem.png
246KB, 2178x904px
>>57702291
Ok here it is, fixed, and with some comments
>>
>>57702595
I'll post mine when this his bump limit, unless someone figures it out first.
>>
>>57702544
>>57702648
I can improve it even further for no conditionals.
int average (int x, int y) {
int z = x%2 + y%2
return x/2 + y/2 + (z + (z > 0) - (z < 0))/2;
}
>>
>>57702693
Fair enough.
>>
>>57702691
The interesting parts are the bottom two pictures

On the left, I define:
The set of valid colours
The set of valid transitions
Cutter, which represents a valid stateful operation.

On the right is the input.
The valid defusal raises no errors, whilst the other two raise type errors.
>>
>>57702701
Is this really faster than just using a double?
>>
>>57702744
Probably, yeah.
>>
>>57702691
That's pretty fucking cool.
>>
>>57702661
>And we give it so much attention.
It's a problem that's simple to propose and it's very easy to make it complicated.
>>
I'm having some issues with my tic tac toe program I'm making for my c++ class. It compiles just fine through gcc/g++, but I'm getting some weird errors when I'm running it. For instance, when player 2 chooses say column 2 row 1, it throws me an error saying that space is already being used, even though it's not. Also it says that Player 1 has won after 2 turns. And after it wins a legit game, the game keeps playing. I have my code pasted here http://pastebin.com/ETWx1wcM. I would love some help/guidance please.
>>
>>57701127
My test harness when I was autistically trying that shit out:
(a, b - inputs, c = expected value, d = result from function)
#include <stdio.h>
#include <limits.h>

extern int avg3(int, int);

int avg2(int a, int b) { return a/2+b/2+(a%2+b%2)/2; }

int avg4(int a, int b)
{
int c;
if ((a^b) < 0)
return (a+b)/2;
else
return b > a ? a+(b-a)/2 : b+(a-b)/2;
}

int avg5(int a, int b)
{
return ((a^b)>>1) + ((a&b) | ((a|b)&1));
}

int avg6(int a, int b) {
return a/2 + b/2 + (a&1 || b&1);
}

int avg7(int x, int y)
{
if ((x>0) == (y<0))
return (x+y)/2;
return x/2 + y/2 + (x%2 & y%2);
}

int main(void) {
int i, a[][3] = {
{ INT_MAX, INT_MAX, INT_MAX },
{ INT_MAX, INT_MAX-1, INT_MAX-1 },
{ INT_MIN, INT_MIN, INT_MIN },
{ INT_MIN, INT_MIN+1, INT_MIN+1 },
{ INT_MIN, INT_MAX, 0 },
{ 3, 8, 5 },
{ -3, -8, -5 },
{ 11, -4, 3 },
{ -11, 4, -3 },
{ -3, 2, 0 },
{ 3, 5, 4 },
{ -3, -5, -4 },
{ 2, 4, 3 },
{ -2, -4, -3 },
{ -1, 2, 0 },
{ -1, -2, -1 },
{ -1, 1, 0 },
};
int (*fn)(int, int) = avg7;
puts(" a b c d");
for (i=0; i<sizeof(a)/sizeof(a[0]); ++i) {
int d = fn(a[i][0], a[i][1]);
printf("%11d %11d %11d %11d", a[i][0], a[i][1], a[i][2], d);
puts(d==a[i][2] ? " - OK" : " - FAIL");
}
return 0;
}


avg3:
.code
avg3 proc
xor eax, eax
add ecx, edx
setl al
shrd ecx, eax, 1
adc al, -2
adc ecx, 0
mov eax, ecx
ret
avg3 endp
end


avg3 and avg7 are the only ones passing all tests.
>>
>>57702701
Someone else figured it out
c_temp = (long)a + (long)b;
return ((c_temp/2) + (c_temp & 1) - (c_temp & 0x8000000000000000)*(c_temp&1))
>>
>>57702744
>faster
No this is all stupid.
Using two casts to float and doing a floating point division way faster than doing all these as integers. I bet. I could check.

If you cared about speed you'd write something that does multiple of them at a time in an array.
>>
>>57702866
Oops, forgot the bitshift.
>c_temp = (long)a + (long)b;
>return ((c_temp/2) + (c_temp & 1) - (c_temp & 0x8000000000000000 >> 62)*(c_temp&1))
>>
>>57702805
Thanks, it's not my idea, but I was messing around with indexed monads after some other guy brought them up.

I saw the problem and thought this was a good example for an "indexed category".
It is literally like being able to write a state transition diagram into your program as a type.

It would be nice if more languages supported this (or if Haskell had full dependent types).


You could do something similar in an OOP language:
struct White {
purple();
red();
green();
orange();
};
...

begin<White>().red().green().white();
// fine
begin<White>().orange().green().white();
// orange does not have member "green"
>>
>>57702871
>Using two casts to float and doing a floating point division way faster than doing all these as integers.
No way.
>>
boys i want to specialize in something cool that could eventually give me a nice niche job, like i remember a guy from google working there because i spent his time fucking around and hacking with the ssh protocol, i would like to have my specialization aswell, i am kinda good at everything but i am tired of being general purpose
>>
>>57702922
We're talking about this to confirm?: >>57702701
>>
>>57702363
>Average -8 and 10 for instance.
Different sign is easy, (x+y)/2 in integer arithmetic will always work.
>>
>>57702871
Casting to doubles doesn't solve the problem, so that doesn't matter
>>
template <typename T, size_t N>
constexpr size_t countof(T(&)[N])
{
return N;
}


What's happening here?
>>
>>57702953
If much rather know if
>>57702915
Or
>>57702701
Is faster
>>
>>57703030
It's a function that accepts a reference to an array and returns the number of elements in it.
>>
>>57703030
It accepts an argument, but doesn't actually use the argument. The only reason it accepts an argument, is so that you can easily decide it's type
In order to explicitly say

countof<T, N>
you would have to already know N

so instead, it uses ad hoc polymorphism / function overloading
the compiler works out which N you're calling it for and returns that
>>
File: Koala.jpg (763KB, 1024x768px) Image search: [Google]
Koala.jpg
763KB, 1024x768px
>>57702951
pls respond
>>
>>57703047
The second one uses a modulus operator, so it's probably slower.
>>
>>57703030
That function is only legal anywhere the length of the array is already statically known. It just uses the unification involved in template argument inference to automatically look it up.

For example:
int stuff[738];
// 100 lines of code
for(int i = 0; i < countof(stuff); ++i) {
// ...
}
>>
>>57703334
a % 2 is just optimized to a & 1 anyway.
>>
How does anyone get anything done in rust?

Why do I have to do bullshit like

path.file_stem().unwrap().to_str().unwrap().to_string();

Why do I have to know about 6 different kinds of strings like str, String, OsStr just to deal with fucking filenames and comparing them to string literals?

Why isn't there an easy way to just collect a bunch of Options/Results and deal with all of them later? Shit like and_then() makes you think you can, but it only takes a function because fuck you. The best you can get is some abortion like

let names = paths.filter_map(|entry| {
entry.ok().and_then(|e|
e.path().file_name()
.and_then(|n| n.to_str().map(|s| String::from(s)))
)
}).collect::<Vec<String>>();


Gee, I love making a bunch of anonymous functions just to call a method in and_then. Why the fuck isn't this built in?
>>
>>57703302
Teledildonics microcontrollers.
>>
>>57703456
The fuck. Is Rust lazily evaluated or some shit?
>>
>>57703456
you don't, Rust is purposefully cucked by its creators to make everything require about as much boilerplate as in java.
>>
>>57703456
What do you mean collect and deal with later?
Surely you can just keep the option.

Or do you mean this:
You've got a list of options or results, and only want to keep a list of successes.

If so, then you can write that function yourself.
Those functions exist in the Haskell standard library, called catMaybes (Data.Maybe), lefts and rights (Data.Either)

rights would be successes
>>
File: Screenshot_775.png (51KB, 1084x514px) Image search: [Google]
Screenshot_775.png
51KB, 1084x514px
My school requires me to make an programming alotgritm for a payroll was going good till this part came.

Print The last name and ID of the employee who paid the highest salary. Assume the highest is unique.

We are using psuedocode so it's stuff like if then else while not repeat etc.
What do i have put for it to find and print the worker with the highest pay?
>>
>>57703524
invoke, r8 my solution >>57702691
>>
>>57703548
think about it
>>
>>57703495
No. unwrap takes an Option<T> or Result<T, E> or something and gives you the T if available and panics if not. It's basically an assertion by the user of the API (since they might know some additional properties about the input) that you'll never get None or Err(...) or whatever the alternatives are.
>>
>>57703456
Ada's the only sane solution
>>
>>57703614
It's a nice addition, you should be glad you aren't writing Agda or Idris and having to prove Fermat's Last Theorem in order to compile your program
>>
>>57703249
>>57703296
>>57703379
I found this function looking for solutions to a simple exercise because I was confused by the given answer.

int main()
{
constexpr size_t new_size = strlen(cstr1) + strlen(" ") + strlen(cstr2) + 1;
char cstr3[new_size];

strcpy(cstr3, cstr1);
strcat(cstr3, " ");
strcat(cstr3, cstr2);

std::cout << cstr3 << std::endl;
}


strlen is not a constexpr function, right? So the firslt line is invalid?
>>
File: ZKRzsLg[1].png (11KB, 620x173px) Image search: [Google]
ZKRzsLg[1].png
11KB, 620x173px
can someone explain to me in this language what are you supposed to do with the + 1 ?

I see here he just pushes another 'a' to the pushdown automata's stack but I don't quite get it.
>>
>>57703551
bretty cool, but the logic feels backwards in a way.
>>
>>57703696
Yeah, I get what you mean.
I can change "To" to "From", which makes a lot more sense.
>>
File: wf7.png (76KB, 1151x1051px) Image search: [Google]
wf7.png
76KB, 1151x1051px
Started to clean and tighten up the asm core for my Forth compiler.
Added tail call elimination and a minor optimization to compiling literals (check if the value fits in 32 bits unsigned or 32 bits signed and pick the smaller mov encodings instead of the gigantic 10 byte mov reg, imm64 every time).

Code generated for those three functions:
foo:
40D000 | C3 | ret

bar:
40D001 | E9 FA FF FF FF | jmp wf.40D000

not-tail:
40D006 | E8 F5 FF FF FF | call wf.40D000
40D00B | 48 8D 5B F8 | lea rbx,qword ptr ds:[rbx-8]
40D00F | 48 89 03 | mov qword ptr ds:[rbx],rax
40D012 | B8 01 00 00 00 | mov eax,1
40D017 | C3 | ret


The tail call optimization is quite ingenious (credit goes to Charles Moore in his colorforth), so simple and elegant on x86 - check if the last instruction you compiled was a call instruction, if so add 1 to the opcode byte (0xE8 is call, 0xE9 is jump) to patch it and skip compiling the ret.
>>
>>57703702
hm, yeah that would probably work. it almost feels like the Prolog way of doing things right now (i.e. use unification to find the thing that fits versus write the code to solve for the thing that fits).
>>
Does anyone here know anything about node.js? I'm trying to learn how to use servers and sockets but when I send the server a 2 character long string, it interprets it as a 3 character long string, which completely fucks me over when I'm trying to recognize input. If I print the string to the console, it's just the same I sent with a space behind it, and if I try to do
if(dt === ' aa')
it won't recognize the 'aa' I sent. Does anyone know about any extra characters that the socket could be receiving?
>>
>>57703650
I _think_ compilers might be _allowed_ to evaluate not-explicitly constexpr expressions at compile time, and put them into constexpr variables, but I'm not sure.
It's definitely not standard.

>>57703664
Could you give more details?
>>
>>57703722
Oh nvm I just forgot to check for \n
>>
>>57703723
Well it is a context-free language and that is the pushdown automaton that recognizes it. It makes perfect sense to me until the stack apparently contains -1 number of a's.

The stack should count the number of a's (gets to 2) then when it receives b's it starts removing an a from the stack for every b it gets. Since it gets 3 b's, so the stack should be empty. Then it goes to the final acceptance stage...but why does it push an a into the stack ? (a -> ε)

does the +1 at the end imply an additional a somehow?
>>
File: cuck rust.png (73KB, 2048x1024px) Image search: [Google]
cuck rust.png
73KB, 2048x1024px
>>57703456
>How does anyone get anything done in rust?
They don't. They just sit around on Starbucks.
>>
>>57703636
The exact same thing can be accomplished in a language like if proofs can be postulated.

Say you have something like this (borrowing some Agda):
data Nat : Set where
zero : Nat
succ : Nat -> Nat

NonZero : Nat -> Set
NonZero zero = ⊥
NonZero (succ _) = ⊤

pred : (m : Nat) -> NonZero m -> Nat
pred zero p = ⊥-elim p
pred (succ m) _ = m


If you postulated a "proof" of NonZero zero, you could pass zero into pred, which would involve an actual call to ⊥-elim, which you could implement to panic.
>>
>>57703456

Well, now instead of unwrap, you now should use the ? operator.

But yeah, I agree. They need to quickly make error handling a lot better in rust.
>>
File: 2016-11-27-00:23_1366x768.png (162KB, 1366x768px) Image search: [Google]
2016-11-27-00:23_1366x768.png
162KB, 1366x768px
>>57700909
>What are you working on, /g/?
Documenting a network protocol with markdown tables.
>>
>>57703334

Modulus operator with a constant gets optimized by a compiler to some bitshifts and subtracts, IIRC.
Modulus operator with a power of two constant gets optimized to an AND instruction.

The only time a compiler should ever be forced to generate a DIV instruction is if

a.) It was told not to optimize
or
b.) You are using modulo with a non-constant
>>
>>57703533
problem is the standard library is ill-equipped for dealing with itself and there's super verbose syntax (no do notation, no operators, etc.)
but "Rust is not a functional language, we don't need catMaybes!"
>>
>>57703879
? is a different thing entirely. Unwrapping isn't bad, it has a different purpose: >>57703614
>>
File: IMG_20161120_004426.jpg (93KB, 480x480px) Image search: [Google]
IMG_20161120_004426.jpg
93KB, 480x480px
Making a shitty programming language for fun today
>>
>>57703047
pastebin.com/ya3PiBd3

Sorry I'm late. I had some questions of my own.
MSVC decided to call something called __allmul in one of the cases that's just a call to a 64-bit floating point (double) multiply function in the debug version of averageBitshift I couldn't find out why it does that at all.

I'l check out what I'm interested in now.
Any suggestions or corrections you want are apprechiated.
>>
>>57703988
>one of the cases
For the lazy it's the /Od of the bitshift version.
>>
>>57703947
>and there's super verbose syntax
The worst offender is the fucking double colon(oscopy) sepples-style scope resolution operator.
Why the fuck didn't they just use dot like any sane person would?
>>
>>57703947
>tfw any language with affine types and borrowing will now be called a Rust clone even though those concepts for resource management and safety have been around for a long time
>>
>>57701046

>one of the most difficult branches
hardly, look at any mathematics course and there's way harder stuff than just predicate calc
>>
>>57704011
Thing::OtherThing<'a>::<&'a More::Stuff<&'a Things<'a>>>
>>57704051
:^(
i wish we could start all over from the beginning and bring Rust to its former glory
>>
>>57703456
This happens when a bunch of safespace sheltered SJWs try to design a language.
>>
>>57703912
Modulo by a constant involves division by a constant. y%x = y-((y/x)*x) where / is integer division.

For constant x, y/x will typically get optimised to (y*((2^n)/x+1))>>n, i.e. multiplication by (2^n)/x+1 and taking the high word of the result.

But you can't do any better than that in the general case.
>>
>>57703456
This is a big sour grapes post.

>Shit like and_then() makes you think you can, but it only takes a function because fuck you.

What the fuck else would it take? It has to have an input (the old value) and an output (the new value). This is BY DEFINITION, a function. If you're not talking an input value, then why the fuck would you use map? Just use "if .is_ok() {}".

And download clippy while you're at it. It will stop you from embarrassing yourself with stuff like
 .map(|s| String::from(s)) 
when you can just write
 .map(String::from) 
.

F for effort.
>>
>>57703704
>writing a forth compiler in assembly using gvim on windows

How is it like, being a world class autist?
>>
>>57703456
>to_str().unwrap().to_string();

Hah what, what does that actually do? What really is the difference? I've never used Rust or anything like it.
>>
>>57704175
Fuck off and take your literally gay language with you.
>>
>>57704197
The compiler will be re-written in Forth once it's self-sufficient.
And vim is the best editor, why wouldn't you use it?
>>
What would be the best way of implementing a save system in Java for a text based quiz?
I.E. it saves the round number, the player number, the scores etc.
>>
>>57704244
>literally gay
>literally

You're both literally and illiterately retarded.
>>
>>57702805
Really? It just seems like needlessly complicated mental masturbation to me.
>>
>>57704332
Rust is still gay.
>>
>>57704445
No, Rust is fine. It's Mozilla that is pozzed.
>>
>>57704343
Where's your solution?
>>
>>57704321
Binary file I/O.
>>
How do I enjoy programming again?
>>
>>57704584
Haskell
>>
Why don't you use Sublime? Emacs, Notepad++, Atom, etc. is for runts.
>>
>>57704584
By watching this:
https://www.youtube.com/watch?v=csyL9EC0S0c

>>57704597
He asked how to enjoy programming, not how to masturbate over type theory.
>>
>>57704605
Vim has everything I need and sublime has nothing more I want.
>>
File: maxresdefault[1].jpg (80KB, 1920x1080px) Image search: [Google]
maxresdefault[1].jpg
80KB, 1920x1080px
How would you guys generate an image like this? Not the triangle but specifically how would you generate the points that make up the triangles in a determinate way.
>>
>>57704626
Do you not enjoy masturbating?
>>
>>57704626
>Haskell
>type theory
>>
>>57704626
>awkward body language
>covering arms
>scratching head
>soft British accent but lacking good speaking mannerisms
>failed attempt at a hipster tier beard
>comments are disabled for this video
>>
File: 1479052727117 (1).jpg (656KB, 1500x975px) Image search: [Google]
1479052727117 (1).jpg
656KB, 1500x975px
im doing some css for a bullshit web dev course
>>
File: Capture.png (15KB, 798x442px) Image search: [Google]
Capture.png
15KB, 798x442px
>>57704532
>>
So is there anyone here that has a job and is self-taught?
>>
>>57704673
that's not programming
>>
>>57704672
>cant even watch the video before forming an opinion

Yup. You'll go far in life. He calls Jeff Atwood out an idiot, if that helps.
>>
>>57704715
I didn't state an opinion about the video because I hadn't watched the video and I won't watch the video. I HAVE however seen him and how he looks and speaks, so I formed an opinion on that an posted it. I couldn't really care less about the contents of the video, the guy just needs to stand straight, shave and stop turning around and lookin shifty.
>>
>>57704343
>>57704679

Imagine if you could encode Association as a data type, and turn bad defusals into type errors
>>
>>57704747
> the guy just needs to stand straight, shave and stop turning around and looking shifty.

Agreed. But it's hardly uncommon for a programmer to be a beta nerd, so I'm not sure what you expected going in.
>>
>can't do
int x = 1;int y = !x;
in java
gay
>>
>>57704761
But why???
>>
>>57704772
hey you can be the most beta fuck on the planet but that shouldn't cause you to literally turn around and face the other way when speaking to a small audience or be too afraid to enable comments on a fucking youtube video. At least, if you are, stating very strong opinions as your title is probably not a great idea.
>>
>>57704475
>rust is fine

Show me one real use case of this meme language that is not related to mozilla or experimental / recreational.
>>
>>57704790
the compiler is literally preventing you from blowing yourself up
>>
>>57704679
The Haskell is no more complicated than that. Type-level element test was implemented since it isn't part of any library and a GADT was used instead of a fold. The rest is just so that do notation can be used for the test cases.
>>
>>57704630
>>57704605
Some day you will try VSCode and never look back.
>>
>>57704808
Dropbox is using it in production. That good enough for you?
>>
>>57704824
> Stefan Cosma @stefanbc
Pushed my first commit using @code in under 15s.

omg 15s for a commit
>>
>>57704824
VS code doesn't have enough C++ features and runs a full web browser in the background. I use it for web dev on windows though, but Vim is superior for real programming.
>>
>>57704789
int y = (x != 0);
>>
>>57704846
Dropbox hops on every meme bandwagon ever, so no.
>>
>>57704789
>>57704884
int y = (x == 0);

Sorry, I rushed that reply and the ! threw me off.

>>57704900
>moving goalposts
>>
>>57704846
>listed in their website as "using it"

So dropbox's backend is written in Rust? What exactly are they using it for?

>>57704871
I stopped using vim altogether because of all the cool useful shit they keep adding to vscode, and for a "web technologies" editor, it runs great (it runs great period actually). I don't like using different editors for different things, and the vim extension for vscode is good enough for me.
>>
>>57704810
And in the other code a call to f would prevent the same thing.

You're just moving computations around for no good reason and to the detriment of readability.

>>57704818
>The Haskell is no more complicated than that.
Debatable. You understood what was happening in that code without (probably) knowing the language. The same cannot be said for anyone who glances at the Haskell code.
>>
>>57704789
Why would you want to in any language lmao
>>
>>57704907
That wasn't me.

This is me
>>57704910

Stop arguing and humour me. What are they using Rust for?
>>
>>57704915
Most of the interesting stuff is one for one, there's a bunch of boilerplate because haskell wasn't created dependently typed, but if you look at my To type family, it's nearly exactly the same as your association list (except reversed, I've since changed that though).
>>
>>57704915
All you're saying is that Mathematica is easier than type-level Haskell. Which is true, but it's got nothing to do with the solution itself.
>>
>>57704789
y = x^1;

why do I have to use this stupid hack for something this easy

>>57704884
>>57704907
both don't work, you can't convert boolean to int
that's my entire point
you can't convert booleans to int without a cast
that's because of javas mental retardation
at least the above code works

>>57704916
I have an integer that can be 0 or 1 and when I have 1 I need 0 in another variable for other stuff and vice versa
lmao
>>
>>57704824
Too slow and bloated.
>>
>>57704954
>I have an integer that can be 0 or 1 and when I have 1 I need 0 in another variable for other stuff and vice versa
oh, I had no idea Java could not cast 0 -> false

lmao
>>
>>57704910
>So dropbox's backend is written in Rust?
Not exclusively, but yes part of it.

>But Go’s “memory footprint”—the amount of computer memory it demands while running Magic Pocket—was too high for the massive storage systems the company was trying to build. Dropbox needed a language that would take up less space in memory, because so much memory would be filled with all those files streaming onto the machine. So, in the middle of this two-and-half-year project, they switched to Rust on the Diskotech machines. And that’s what Dropbox is now pushing into its data centers.

from: https://www.wired.com/2016/03/epic-story-dropboxs-exodus-amazon-cloud-empire/
>>
>>57704954
>I have an integer that can be 0 or 1 and when I have 1 I need 0 in another variable for other stuff and vice versa
y = 1-x
>>
>>57704963
>I have used Atom and think all web meme editors are the same

I'm telling you, you will be blown away if you ever let your ego stop controlling you for a second and give it a go.

But you do whatever you want.

>>57704977
Interesting. Thanks for the link.

>diskotech
lel
>>
>>57704950
No all I'm saying is that Haskell is gay.
>>
>>57704999
What if you wanted something other than a simple association list?
>>
>>57704977

It now all makes sense.
>>
>>57704635
>edge detection of distinctly colored zones
>separate all detected zones into triangles
>connect all triangles
>separate the new zones by averaging colour somehow
>repeat until some threshold
>>
Guys how do you take the average of something?
I'm going insane here.
>>
>>57705010
You mean like a complicated association list?
>>
>>57705035
Go to bed, Yuropoor.
>>
>>57705065
shart in mart
>>
>>57705071
Import some more Syrian rapists.
>>
>>57705065
>lol i doxxed you by looking at a filename
>>
sorry for being a newfriend, but how do I post code?
>>
>>57705046
Yes. Like a complicated association list.

Anyway, you could have something like a type indexed by a state, and then use state transitions as parts of a stateful computation
...

in one example, you can have a variable that's statically typed, but changes its type throughout the computation
>>
>>57705085
Import some more Mexicanrapists.
>>
>>57705099
< code > < /code > Without the spaces.
>>
File: trump_wins.png (334KB, 400x573px) Image search: [Google]
trump_wins.png
334KB, 400x573px
>>57705106
Sorry, they have to go back.
>>
>>57705118
Isn't it with "[" and "]"?
>>
>>57705127
No.
>>
>>57705127
it was le epic trellface
>>
>>57705104
>a variable that's statically typed, but changes its type throughout the computation
Sounds like you could just do away with the static typing and save yourself a headache.
>>
>>57705127
It is. That guy is a jerk.
>>
>>57705120
Why is it always just about the jews?
11 million died from concentration camps IIRC.
>>
>>57705142
No, in that case it's basically function composition. You obviously have better performance, and actual safety, from static typing.
>>
>>57705139
>>57705144
The faggot didn't even read the sticky.
>>
>>57705150
11? Last I heard the numbers went up to 60 quadrillion
>>57705161
ROFL-LMAO TROLLED
>>
>>57705178
nice one m8, I hope you're proud
>>
>>57705161
I have no knowledge of AHK beyond spamming mouse clicks, so what does that do?
>>
>>57705162
I don't buy it. Static typing is just a meme created by CS professors for grant bux.
>>
>>57705169
I browse /g/ for like 5 years now and I haven't read that shitty sticky
>>57705185
wasn't me, I only LMAO'd
t. Anon 57705178
>>
^+Space::
Send ^x
clip := clipboard
clip_array := StrSplit(clip)
i := 1
sp := " "
While(i <= clip_array.MaxIndex())
{
char := clip_array[i]
Send %char%%sp%
i++
}
i := 2
While(i <= clip_array.MaxIndex()) {
char := clip_array[i]
Send `n%char%
length := -3 + 2 * i
While(length > 0)
{
Send %sp%
length--
}
Send %char%
i++
}
Return


it memeifies text
>>
>>57705127
<'s are for html
[' is bbcode
Clearly you want it to show up as code tags in a normal browser not a bbcode viewer.
>>
>>57705218
not to confuse with your mother and gf: a bbc-lover
>>
>>57705217
So it does like T h i s? kek
>>
>>57705199
Why are static languages consistently dozens of times faster?
Why do static languages often contain many less bugs?
>>
>>57705150
The "six million" was actually a meme pre-WWII. Even google agrees:

https://books.google.com/ngrams/graph?content=six+million+Jews&year_start=1850&year_end=2000&corpus=15&smoothing=0&share=&direct_url=t1%3B%2Csix%20million%20Jews%3B%2Cc0
>>
>>57705236
Don't get your programming panties in a bunch I'm just having fun
>gf
I definitively have a girlfriend. Like every programmer I'm so productive I can maintain healthy relationships and do programming at the same time.
>>
>>57705254
*programs written in
>>
>>57705267
xddd
>>
>>57705217
You use it by selecting text and then hitting ctrl+shift+space

>>57705250
no, like
t h i s 
h h
i i
s s
>>
>>57705254
Did your CS professor tell you that? Wake up sheeple.
>>
>>57705281
Oh shit that sounds hard to do
>>
File: file.png (108KB, 878x336px) Image search: [Google]
file.png
108KB, 878x336px
>>57705260
So much knowledge of memes has been lost.
>>
>>57705281
>>57705250

^Space::
Send ^x
clip := clipboard
clip_array := StrSplit(clip)
i := 1
sp := " "
While(i <= clip_array.MaxIndex())
{
char := clip_array[i]
Send %char%%sp%
i++
}
Return


this one does it in only one dimension
>>
>>57704998
I have tested vscode and it is too slow and bloated and it offers nothing over vim.
>>
>>57705315
the only tricky part was getting the formula for the offset
length := -3 + 2 * i
>>
What's the C best practice for naming the file which includes the main() function?

I have mostly been seeing two approaches: main.c or (program_executable_name).c
>>
>>57705385
>best practice
Name it start.py
>>
File: 1479211409748.png (90KB, 512x512px) Image search: [Google]
1479211409748.png
90KB, 512x512px
TL;DR
if I dont alter global variable, do I need to declare it in a function at the beginning?


so
quick question about global variables
I dont use them often, but need to use it now
I think that if I dont actually change value of the variable, that I am not assigning to it anything, I dont need to have it declare as
globa op_faggot_today
at the begining of my function

correct?
though I am thinking of still keeping it there, to know right away that a global variable is being used in that function...
>>
>>57705394
Just fuck my autoindent up.
>>
>multiple gigabyte
>>>text editor
the ultimate meme software
rather use word than type my shit in vaginal studio

>>57705385
doesn't matter you can name the executable in the makefile/gcc command, what name the main has is irrelevant
>>
>>57705385
Those are the only valid choices. The difference between them is minimal.
>>
>>57705385
The only reason to NOT call it main, is if your project has multiple mains.

TL;DR call it main.c until you have a good reason to change it.
>>
>>57705417
I know it's arbitrary, but I want to know what the most common/best convention is.
>>
Do you place TODOs in your code comments?
>>
>>57705511
no, as its not the place I look for todo
>>
>>57705511
Yes. All the time.
It's practically the only comments I do.
Comments get outdated.
Todo's don't or they're easily ignored. Outdated comments confuse people

Write your code in a way that lets it itself say what it does.
>>
How do we solve the issue of competing threads?
Do we lock a mutex?
>>
>>57700909
writing my irc bot. for some reason i keep making web robots but oh well need to start on a bit torrent client like really bad just don't know where to start?

  for i in soup.find_all('a', 'title'):
if new == 1:
string = str(i.get('href')) + '\n'
combine = reddit + string
if combine in compare_list:
print('not new')
break
>>
>>57705540
>I wrote 2 text based games with lots of if else and few loops
>>
>>57705553
Best case scenario is the threads don't compete.
>>
>>57705511
if I take shortcuts that need to be fixed later I will. I don't for stuff that could be better or issues found later.

>>57705553
Single writer principle.
>>
>>57705553
Design your software to not allow threads to compete. If it is unavoidable, make it minimal and use data structures with O(1) time locks (like hash table lookups or array access).
>>
>>57705578
>I am a bad programmer and project this onto everyone else
>>
>>57705511
I just keep a TODO file. If there's something alarmingly important I can't fix right now I might leave a comment.
>>
>>57705593
>commenting = bad programmer
>>
>>57705623
>self-documenting code = unattainable
>>
>>57705579
Well we've seen there been both race conditions and simply unchecked behavior.
>>57705580
Extremely hard to achieve on 4chan
>>57705585
Anon this only works for the trivial cases.
>if it's unavoidable...
This does not work at all, it's just timebombs. If it works 'ok' in most of these situations then a mutex would be very cheap to use.
Ignoring the /dpt/ analogy I'm making here.
>>57705540
No I've written larger stuff. At most you should write documentation for your internal API's for convenience's sake. Like doxygen comments.
>>57705623
>>57705635
Stop assigning.
>>
>>57705593
If you never comment your code you probably have only written basic stuff without any potential interaction with others. Commenting algorithms or certain accessors in libraries and in OOP is very useful, and documentation is very important at work.
>>
>>57705659
>OOP
This having been a consideration in your mind makes you a bad programmer.
If you're writing OOP you should just delete your code and tell others to program for you.
>>
>>57705659
I write self-documenting code.
>>
>>57705635
"Self-documenting code" is a meme.
>>
>>57705635
in non trivial projects?
absolutely
>>
>>57705650
>Extremely hard to achieve on 4chan
Huh? You mean threads on 4chan? I'm being meme'd.
>>
>>57705691
>>57705702
Maybe if you use shit languages.
>>
>>57705679
Again, a good sign you haven't written anything of importance, had a job in programming or done group projects outside school. OOP is widely used in larger code bases for many markets and fits the model for most GUI applications and a lot of networking software. Regardless of what you prefer, sticking to one singular paradigm or avoiding one in particular, especially one as large as OOP, instead of adopting good principles, is only possible when writing fizzbuzzes.

>>57705688
Not when writing anything of importance you won't. Workarounds, collaborations, access control, it all needs commenting.
>>
>>57705719
>putting yourself in a position where you have to work with abhorrent programmers
>>
>>57705735
>not having a job
>not having your own flat
>not earning an income
>not collaborating with other programmers, hosting projects
lame

must be boring writing fizzbuzz in haskell all day
>>
File: nope.webm (1MB, 600x510px) Image search: [Google]
nope.webm
1MB, 600x510px
>>57705735
>>
>>57705748
>>57705758
What if I were to tell you I don't program for a living and yet I'm not a NEET?
>>
>>57705758
Kek, what interview is that?
>>
>>57705765
Then one would as what do you do for living?
>>
>>57705719
>OOP is widely used
Yeah it's widely used among bad programmers.
Have you seen large scale software that uses OOP? It's absolutely insane.
At best you're talking about people who use 'OOP'. Which is data with member functions and some light dynamic dispatch from very sparse use of inheritance. If peolpe actually do object oriented design, the UML crap. Just bring a shotgun to work and paint your resignation letter on the wall.

OOP achieves nothing it promises.
>>
>>57705780
Sport coach and student.
>>
>>57705778
she was asked about goblet of self documenting code
>>
>>57705788
why would you think you know more about good practices and practicalities of coding than people who do it for living for years?
>>
>>57705814
Because I write code the way I do for its merits and not because Mr. Goldberg said it's the best way to keep Pajeet from fucking my shit up.
>>
https://www.wolframalpha.com/input/?i=interpolate+(10,-2),+(9,1),+(8,2),+(7,3),+(6,4),+(5,5),+(4,6),+(3,9)

How do you write this function without shitty spaghetti code?
no math functions etc allowed
is switch case my only option?
>>
>>57705846
Yeah assuming those middle points are linear just branch it. It's the best way
>>
>>57705846
poly :: (Num a, Integral i, Foldable t) => t (a, i) -> a -> a
>>
>he fell for the OOP IS SHIIITTTT meme
>>
>>57705956
>he fell for the OOP is good meme
>>
>>57705937
what meme language is that and let me guess, poly is some math function
>>
>initial commit of git was only 1076 lines (not counting long readme)

huh
>>
>>57705975
Most of the world did I guess, sorry we arent falling for your functional programming meme. No one likes your F# meme language you hippie.
>>
>>57706017
Where are you getting FP from? I didn't mention it.
>>
>>57705982
that's the type signature
i'll write the function for you

poly :: (Num a, Integral i, Foldable t) => t (a, i) -> a -> a
poly t x = foldr (\(k,i) s -> s + (k * x^i)) 0 t


example - your case:

polyInfo :: (Fractional a, Num i) => [(a, i)]
polyInfo = [(-1/1260, 7), (13/360, 6), (-251/360, 5), (533/72, 4), (-16799/360, 3), (31421/180, 2), (-37762/105, 1), (322, 0)]
-- from wolfram alpha

myFunc = poly polyInfo
>>
>>57706087
What does this generate?
>>
>>57701245
looks nice
>>
>>57706087
tl;dnr

>given a list of (coefficient, exponent) pairs, and an x value

>>57706101
poly, given a list of (coefficient, exponent) pairs, generates a function (the polynomial function with those terms)

e.g.

f x = 3x^2 + 4x - 3
f = poly [(3, 2), (4, 1), (-3, 0)]
>>
>>57706087
can you do this in lisp?
>>
>>57706161
Anon. What are you on about.
What are the instructions involved?
What is the cost of this?

I don't think he has issues writing down a polynomial in code.
Or maybe I'm misunderstanding and he is having issues with that. In which case I excuse myself.
>>
>>57706176
You can do something extremely similar, certainly something with similar behaviour.

All you do is this
>given a list of (coefficient, exponent) pairs
>given an x
>map the list using (coefficient * x ^ exponent)
>sum the resulting list

pairs I assume can themselves be two element lists
>>
>>57706161
That's not remotely the same thing as polynomial interpolation of a set of points.
>>
>>57706224
No, it isn't. It constructs a polynomial.
He gave a link to wolfram alpha which included the coefficients and exponents.
I assumed he had that particular polynomial in mind.
>>
>>57706240
I see
not that I don't understand it but it seems complicated for my purpose

thanks anyway, will remember this for another time
>>
>>57705846
Is this what you actually wanted?
https://wikimedia.org/api/rest_v1/media/math/render/svg/433b27e79887d28e6590657219ec0ff643a7fd84
>>
https://github.com/salvadorp2001/board.js/blob/master/board.js
rate my code from pajeet to 10
>>
>>57706348
What do you actually want?
That specific polynomial function?
Wolfram alpha literally tells you

f(x) = -(x^7)/1260 + 13(x^6)/360 ... etc
>>
>>57706373
>>57706351
That I could do myself even, but thanks, and I know that wolframalpha tells me the function

desu it's really fucking early in the morning here and I should get some sleep, I should have actually explained my problem to you guys before you waste your time on me

I actually just wanted to map those x to those y somehow but it doesn't seem to get any easier than what you have already posted here
>>
>>57706490
So you just want to implement the function wolfram alpha gives you?

It shouldn't be that hard, the code should literally just look like

myfunc(float x) {
return 4 * pow(x, 5) - 3 * pow(x, 2) ... etc
}
>>
I'm currently reading some stuff for my Discrete Maths class, and this stuff about Graph Theory could be pretty good to look into.

Anyone know a good technical book on Graph Theory as applied to software development? Preferably with examples.

Note: I have NOT been too good with the overall Mathematical theories in this class, so I'd prefer something that focuses on practicality and is less abstract.

Ideally, it would be nice to have a book that almost guides you in developing programs and module dependencies USING Graph Theory, but really just a good, reasonably-priced book on the topic, with emphasis on programming.

Alternatively, I'll be taking a Software Engineering course next semester. Do most SE course texts have decent focus on Graph Theory, and I can probably rely on that?
>>
>>57706367
>going 80+ characters on one line

Newlines are your friend.
>>
>>57706538

Look at CLRS and you'll get a good grip on algorithms which make use of graphs. That's less masturbation and more focused on actual uses, there.
>>
>>57706550
Shit, I didn't even realize that. Does node.js handle styling acceptably or is it a python shitfest?
>>
My biggest issue with Rust at the moment is strings. Holy shit, what a mess. Yeah, UTF-8 strings that store the length instead of being null-terminated are great but they're not a panacea. Why the fuck do Rust developers pretend they've made the one string to rule them all? God forbid you need to do FFI and have to use null-terminated UTF-16 in this language.
>>
File: Code001.png (63KB, 1554x326px) Image search: [Google]
Code001.png
63KB, 1554x326px
Pic related is my code. Why won't the color of the links change when I hover the mouse over them? HTML/CSS. To the right of the picture is the link in their test environment.
>>
>>57706490
Ok see:>>57706522
first.
The reason I responded with >>57705890
was because I saw that as obvious and assume you were like "what?! ~5 calls to pow()? That's way too much for this simple thing".
So I recognized that you probably just wanted an approximation where you fit the curve well at the ends and just compute the kx+m for the middle. kx+m (being just 10-x in this case) being way cheaper to compute and you'd figure out an appropriate second degree polynomial for both the ends.

So I assumed a bit much. Potentially confusing you.
>>
>>57706625
>make a string type for your new language
>standard null terminated utf 8

>>Holy shit, what a mess. Why the fuck do Rust developers pretend they've made the one string to rule them all?

>cry
>>
>>57706589
javascript doesn't have significant whitespace, if that's what you mean...
>>
>>57706683
That's exactly what I meant. Thanks
>>
>>57705781
nicely meme'd
>>
>>57704060
when programming you're actually putting math to use, there is no hand-holding and you're literally inventing new algorithms and such. school math is just getting spoon-fed things that have already been studied with plenty of hand-holding available to you.
>>
>>57701492
Gave me an excuse to exercise my Forth implementation.
: bit-masks[ -1 ;
: bit 1+ dup 1 swap lshift constant ;
: ]bit-masks 1 swap 1+ lshift 1- constant ;

bit-masks[
bit #white
bit #black
bit #purple
bit #red
bit #green
bit #orange
]bit-masks #aLL

#all value allowed

: reset #all to allowed ;
: allowed? allowed and 0= abort" BOOM" ;
: cut create , , does> dup @ allowed? 1 cells + @ to allowed ;

#white #black or invert #white cut white
#green #red cut red
#white #green #orange or or invert #black cut black
#red #black or #orange cut orange
#orange #white or #green cut green
#purple #green #orange #white or or or invert #purple cut purple

\ reset ok
\ black purple black black ok
\ red green white green ok
\ orange ok
\ white BOOM
\ -> white
>>
>>57706854
I get your point and perspective. Programming is in many way abstract enough that you can make it as complex as you want. In the real world you can't fuss about with math and randomly invent new things. You build a bridge on the shoulders of giants or your ass is on the line when it falls.

But there's other disciplines that do the same. Especially in research. They may not be programmers directly but they do make algorithms for programmers to deal with often.
>>
What is the easiest way to get input from GPIO pins on my Raspberry Pi in Linux? I'm thinking I just have to read and write to /sys, but it doesn't pull to 3V3 (I think it might just be a different pin layout)
>>
>>57706581
ok, thanks, I'll check it out.

Is there any issues with the 1st Ed, (b/c it's way cheaper than the 3rd), though?
>>
>>57706652
There's a web dev general on /g/ - this is a programming specific thread. However, I believe you may have to remove the space between a and the :specifier
>>
>>57707202
Sorry, add a space.
>>
File: Pseudo-classes.png (30KB, 1117x676px) Image search: [Google]
Pseudo-classes.png
30KB, 1117x676px
>>57706652
pseudo-classes are definitely in the wrong order.
Try this.
(needed to recheck to find correct order)
>>
Hey /dpt/, I'm a freshman in college studying to be a SE, and I'm currently writing a resume that I'm hoping will land me an internship this summer.

What are some of the things I should/shouldn't talk about? Any advice or tips from some seasoned vets would be appreciated.

Thanks.
>>
New thread: >>57707481
Thread posts: 392
Thread images: 39


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

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


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