[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: 327
Thread images: 20

File: dpt_flat.png (102KB, 1000x1071px) Image search: [Google]
dpt_flat.png
102KB, 1000x1071px
Old thread: >>57028549

What are you working on /g/?
>>
Why do the mods just randomly delete threads?
>>
>>57034845
Other one didn't have anime
>>
>>57034845
The other one was posted before the bump limit, so it was invalid.
>>
Interesting project to learn LLVM while doing it?
I'm quite familiar to Flex/Bison.
>>
>>57034864
>>57034871

Lord have mercy on our souls.
>>
>>57034830
Guess I need to learn about unit tests, fuck doing everything by hand when I make a little change.
>>57034864
Seems a valid reason.
>>
File: 1475798170602.jpg (51KB, 514x536px) Image search: [Google]
1475798170602.jpg
51KB, 514x536px
I feel i don't know shit about anything

Does anyone has ever dealt with this before?
>>
> tabs vs spaces
here we go again
>>
>>57034900
>I feel i don't know shit about anything

Welcome to the club.
>>
>>57034942

Wut?
>>
>>57034900
>I feel I don't know shit
>has anyone ever dealt with this before?

No, no one has ever realized their own ignorance on a topic ever before. You're literally the first person to be overwhelmed by the vast amount of information within a subject.
>>
File: spoopy.jpg (53KB, 600x500px) Image search: [Google]
spoopy.jpg
53KB, 600x500px
>>57034958
>>
why do programming language FFIs let me call "C functions"? What the fuck even is a C function? C doesnt exist at that level, it gets compiled away. there's only machine code.

why the fuck do we even need a {C runtime"? whatever the fuck that is. windows programs keep moaning over muh precious C runtime dll. why. the ABI is processor architecture + OS system calls. no need for all this faggot ass shit. am I wrong?
>>
>>57034992
You're confusing instance with type.
>>
>>57034965

How do i step back from it? I wanna work on my shit.
>>
>>57034998
C _does_ exist at that level
https://en.wikipedia.org/wiki/X86_calling_conventions#cdecl

System calls are too low level, it's much easier to interact with a higher level C ABI
>>
multithreaded HTTP video streamer in C
>>
>>57034900
just you
>>
>>57035012
what advantages does multithreading have when dealing with HTTP streaming? Wouldn't that be a pretty huge bottleneck?
>>
>>57035012

lib?
>>
>>57034900
Carmack got btfo by ndk
>>
>>57035026
You could buffer in multiple chunks if the server you were connecting to could/would only supply X speed over any single connection. That's how almost all files are downloaded nowadays anyway
>>
>>57035020

thanks
>>
>>57035012
I'm working on something similar, except it is a decentralized streaming platform, and all of the streams are "channels" that people can watch live
>>
>>57034998
>why the fuck do we even need a "C runtime"?
Because most programs make use of the C standard library, and there is some other stuff the runtime does like zeroing static variables when the program starts.
>the ABI is processor architecture + OS system calls
No, the calling convention and system call convention (among other things).
>>
>>57035011
>>57035011
>a calling convention among many

such C, much source, wow

there's really no reason an FFI shouldn't support at least all of those

also syscall is just a bunch of calling conventions as well, C functions are thin wrappers. if you're writing a VM no need to call that shit
>>
>>57035041
Is that the only multithreading aspect of the program?
>>
>>57035005
Realize that jumping into the middle of a subject will do nothing but hurt you. Focus on the foundation, since without it, you won't get anywhere at all.

By that, I mean don't program your first "hello world" program in Java and skip right to learning how byte buffers and data communications work.

If you need to learn the foundations of something like data communications for whatever project you're doing, then start with the basics. Wikipedia isn't a good source for that, books and other online resources are.
>>
Does anybody else here have experience using unity as an easy to use 3d renderer for a non-game application?
I want to open a command prompt from Unity (or have a command prompt open before the "game" even starts) but I don't know how to do that, does anybody have any ideas? Unity help boards are full of retards who say "IT CAN'T BE DONE" the second that they don't instantly understand how to do something

>>57035058
IDK anon, I made that post as an explanation on how it might benefit but I wasn't the original poster
>>
Hello friends.
I have a c++ question.
How would I best be able to get a random object from a vector with a specific variable value. ie. random Car with paintJob == 1.
>>
>>57035026
Search "concurrency" on wikipedia
>>57035028
simply pthreads, sockets, and I write the header + data on my own
>>57035047
that's too bloated and complex for me, I like to go by the unix philosophy
>>
>>57035097
count the number of objects that have paintJob == 1 and generate a uniform int distribution with 1 to the number of objects and pick that one (in order).
>>
what have you programmed in cinnameg today, anons?
http://www.cs.ecu.edu/karl/cinnameg/9-0/lin/Overview/overview.html
>>
>>57035119
I get that having modularity is good, but I don't see that getting over the speed of HTTP unless you are doing some mean encoding
>>
>>57035125
What about:
Shuffle vector and pick the first one with paintjob == 1?
>>
>>57035171
ordering of the std::vector can be important for some reason (stack?), and you can put mine in std::for_each functions
>>
>implementing kd-trees
The explanations on how KNN search works makes me want to shoot myself.

At least the wiki article on Ant Colony is pretty good.
>>
>>57035164
there's some compression being done and I don't need more than say 5 or 8 to be connected to the stream, and I am mooching off c9,io for a big connection lol (I use their 50gb connection cap and make a new account) they push out about 1gbps and thats plenty for what I do
>>
anime thread! yay!
anime!
anime!
anime!
anime!
anime!
anime!
>>
>>57035217
>implementing kd-trees
Why? Use an implementation someone else wrote.
>>
i'm a complete noob in php, but i need to run this piece of code from the terminal

<?php

/*
* Following code will create a new product row
* All product details are read from HTTP Post Request
*/

// array for JSON response
$response = array();

// check for required fields
if (isset($_POST['name']) && isset($_POST['price']) && isset($_POST['description'])) {

$name = $_POST['name'];
$price = $_POST['price'];
$description = $_POST['description'];

// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

// mysql inserting a new row
$result = mysql_query("INSERT INTO products(name, price, description) VALUES('$name', '$price', '$description')");

// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "Product successfully created.";

// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";

// echoing JSON response
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";

// echoing JSON response
echo json_encode($response);
}
?>


someone told me to do the second solution here
https://stackoverflow.com/questions/5655284/how-to-pass-parameters-from-command-line-to-post-in-php-script

but i don't get how to do it. i tried what i thought it was saying to do and it didn't work for me. can someone help me do this?
>>
>>57035383
Because they're not written for Java, and if they are, they have complicated overhead that I want nothing to do with.

I tried Boost Graph Library once, never again.
>>
>>57035428
Why not run the algorithm without kd-trees then? Relatively underdetermined data works faster without it anyways. Use cross-validation over multiple k's for some better accuracy. k-nn is really only useful for run once shit because of how expensive testing is, although I'm guessing this is for a class and not real world.
>>
>>57035420
php yourscript.php 'name=x&price=y&description=z'
>>
>>57035459
It is for a class, although KNN is only something I'm using because it's a useful optimization.

I have 100,000 points to find some 20 neighbors for.
>>
>>57035520
How big is your feature vector? Try it without kd-trees, if it doesn't run at the performance you want then try kd-trees. "Premature optimization is a waste of time." - Sane person
>>
>>57035569
The prompt claims "m-dimensional", but is actually 4D. I'm trying to write an m-dimensional solution so I can show off my algorithms peen to potential employers.
>>
>>57035461
fucking killer dude, thank you. this works. this is a little more complicated, but do you know of a way i could do a helper function in php that then calls the other functions? so like
php terminalRunner.php 'script=create_entry.php&param1=...' ? how would i call the other php script within a php script and provide it the post is what i'm askin
>>
>>57035606
by function i meant script ***

a helper script
>>
How the hell does one map a bidirectional many to many relationship in the database without a bunch of cycling?

example - object A has a list of object Bs and vice versa. when object A is persisted, it's list of object Bs will be persisted, which will then try to persist object A, etc...


I'm rolling my own here btw. No ORMs, no frameworks or anything fancy. Just plain old JDBC, and implementing my own data mappers.
>>
File: smh_tbh_fam.gif (490KB, 500x671px) Image search: [Google]
smh_tbh_fam.gif
490KB, 500x671px
>It-ebooks
>Downloading is temporarily unavailable!
>>
>>57035740
i only buy/rent physical books now because of being burned more than once
>>
I'm doing a visual basic assignment for school, and the teacher wants us to have buttons to change the text color and font of one of the windows, but she's never mentioned anything about how to do that.
Any ideas?
>>
>>57035701
Use the proper tool, a grpah DB.
>>
>>57035740
kys
>>
>>57035774
I pirate them because >lol poorfag, but once I find a job I'm going to buy every single tech book that I have read.
>>57035777
Can you use WPF for visual basic? If not, Winforms.
>>57035792
I'm already ded inside senpai.
>>
>>57035792
based thomas cormen
>>
>>57035821

Like I already said, Cormen is a sanctimonious fag.
>>
File: Capture.png (12KB, 440x260px) Image search: [Google]
Capture.png
12KB, 440x260px
>>57035808
I dunno what WPF and Winforms are or how to use them, I'm on my 7th day of class and my teacher isn't explaining shit.
Here's what the program looks like, under edit there's Font and Color options which have to "Color & Font items should change the
color and the font of the information displayed in the amount earned display."
I saw some tutorials that say to dim a message box as a variable or something but I can't get that working
>>
>>57035808
>I pirate them because >lol poorfag, but once I find a job I'm going to buy every single tech book that I have read.
sure thing
>>
>>57035862
That looks like VB.Net forms.
>I dunno what WPF and Winforms
Google them, they're libraries to build GUI applications.
>>57035865
I also think that having a big library in the future will be a way to show off, in a very nerd way.
>>
>>57035808
>I pirate them because >lol poorfag, but once I find a job I'm going to buy every single tech book that I have read.
Somebody needs to make a Project Gutenberg for technical documents (public domain)
>>
>>57035569
Good news.
I just tested my kd-tree algorithm and it does work (at least, it for a fact gives me points that are all in the same ballpark, whether or not this is accurate I can't actually tell). I just have to fix a stupid bug where the points aren't actually being assigned their neighbors.
>>
is there any book teaching proper program structure (particularly in C)

Like how do I manage parent structs and their children?
>>
>>57035569
what do you use for this
all roads seem to lead to snek and i don't like it

>>57035900
god i have so many math books
i work in coffee shops and libraries mostly so i do 80% of my reading out of libgen copies of things i already own
maybe when i'm well-off enough to have a separate work room this'll change
>>
>>57036199
>in C
From what I've seen, it's "whatever works."

Although I've also heard "stupid people can compose stupid C programs" too.
>>
>>57036199
>Like how do I manage parent structs and their children?

Haphazardly. In that way, you will develop a typical leaky C program.
>>
Has anyone read Algorithms by Vazirani?
How's it compare to Cormen's book?
>>
File: 1389224279388.jpg (44KB, 500x316px) Image search: [Google]
1389224279388.jpg
44KB, 500x316px
What's the best place to be hired for freelance work? I want to do some small-scale professional applications for general "look what I can do" github purposes as my personal projects don't always display that- I want work that will likely only take me a week or two to complete. I don't care if I'm underpaid.
Suggestions?
>>
>>57036398
>Haphazardly
well yeah, because I have no knowledge of proper C program structure

I want a book that teaches proper C program structure
>>
>>57036407
much less comprehensive and formal
the first is fine, even desirable. the second i don't like so much
>>
>>57036199
When I do large scale projects, I give all of the structs IDs and put them in a std::vector (I know, C++, but the same logic applies). The type in the list has a pointer to the struct that created it. I call a function to look up the ID and return the pointer to the object. If the object has been destroyed, the ID is no longer valid and a null is returned safely. This isn't the best approach (lookup overhead, bit in-depth), but it did the job pretty well. I also added a list of void pointers and sizes for all of the data for easy storage and transfer over networks
>>
>>57036463
For garbage collection, I have a special list of IDs, and it periodically scans all of the IDs for a certain ID, and deletes it if there is no reference.
>>
>>57036457
one thing i will say for the dasgupta et al book is that from the outset they establish a perspective. even the length of the book gives you some organizing idea of what's important and what's not. i don't think you get that from clrs
>>
>>57036463
there has to be a better way
>>
>>57036487
Does C not have unique, shared, and weak pointers?
Seriously, you could handle all of that garbage collection through smart pointers.
>>
>>57036512
>>57036463
There are better ways (pointer to a pointer), but I made this with the intention of easily networking data over the internet (pointers don't work inter-machine), and the lookup system just came of it.
>>
>>57036501
I was recommended the book by a professor, it seems like a good choice to catch up on what I wasn't taught in some of my classes.
>>
Working on a small game engine in C.

I'm realizing just how much memory allocation higher-level languages and libraries must do.
>>
>>57036592
Well, in the first place the reason for the memory allocation is just a side effect of the language design.

Exceptions are memory and processor inefficient. Recursion is inefficient (without TCO). It shows up in the size of the binary at times, too (function inlining).
Basically all of the modern conveniences that modern programming languages provide you are all inefficient in some way or another.
>>
In bash how do make sure there are only unique outputs are picked. It has enough possible choices to make sure it is unique

I don't want to remove or delete the duplicate lines in the output I want to replace them which is what I keep seeing when searching online. So I can't use "uniq"

I'm inside a for loop btw. Should I make an if statement inside the for loop? Any ideas?
>>
>>57036638
RAII is not inefficient and is something I wish C had
>>
>>57036512
No, it doesn't.

You can code them yourself, but really, it is massively tedious because you have to do every increment/decrement yourself.
>>
>>57036664
You need to restate your problem because I literally have no idea what you're trying to do.
I'm going to obtusely interpret your problem as one where you have some data (with duplicates) and you want to process it into unique data.

Create a hashtable, insert the data into the hashtable, and then iterate over the elements of the hash table.
Congrats. Your data is unique. Whoop-die-doo.
>>
>>57036670
So why not use C++ then?
In terms of language features, C++ does not have a terribly large amount of overhead as compared to C.
Just don't do anything fancy and you'll be fine.
>>
>>57036638
>Exceptions are memory and processor inefficient
I get that they're slow if thrown, but aren't they much faster than checking all the return codes all the time in the common case (i.e. no exceptions actually being thrown)?
>>
>>57036739
I program microcontroller/dsp chips as a hobby and those things don't allow for large binaries

C always creates smaller binaries even if I am using a minimal amount of features in C++

RAII creates no overhead since it is a compiler construct and nothing else
There is no reason for C to not have it
>>
>>57036739
He's not me (I made the original post about using C), but to answer your question: I'm doing it for the experience of doing it in C.

Next time I will indeed use C++, and I will love and cherish it, for RAII is so much nicer than having to do resource cleanup by myself at the end of every function.

It could be worse. At least C has goto.
>>
>>57036742
Nope!
There's a chapter on Exception Handling in the book, "Programming Language Pragmatics"
An exception happens. It checks the stack frame for an exception handler. It verifies if the types match. If it doesn't, it destroys the stack frame and unrolls the stack until it finds an exception handler with correct type (the default one just terminates the program).

With C-style exception handling, a function returns a bool as to whether it passed or failed. And then you just handle it there and then. Magnitudes simpler.

What it boils down to, is that exception handling introduces a lot of bookkeeping data into the stack frame.
>>
>>57036785
But with return codes, you have a whole load of conditional jumps in your function, which aren't needed if you're using C++ exceptions, I would have thought.
>>
>>57036714
I have 20 possible outputs. If I tell it to output 15 of them it randomly outputs 15 of them but the problem being some are duplicates

I want it to randomly pick 15 unique outputs out of the possible 20

Make more sense now?
>>
>>57036841
After each one is picked, remove it from the collection.
>>
>>57036785
>a function returns a bool as to whether it passed or failed
to a point, yes. However, when macros are returned, things become more complicated as error correction can happen
>>
>>57036833
That's true. Let's think of this in terms of CPU pipelining.

So, when performing CPU pipelining, each sequential operation is actually happening (roughly) in parallel. When you have an if statement, there's a possibility for a jump. If it jumps, the CPU pipeline is cleared and it has to start all over again.

In the event that an exception occurs, the pipeline is cleared.
In the event that nothing happens, then the operation is equivalent to a nop. So yes, you could say that having tiny 'nop's littered throughout your program is less efficient. But I would say that a single 'nop' is more efficient than the assembly required to add and process the bookkeeping data in a stack frame.

>>57036860
He could also add the element to a hash table if they can't be removed.
>>
>>57036875
if (fuckADuck() != 0)
return -1;
if (rubADub() != 0)
return -1;
if (lubAFlub() != 0)
return -1;

vs.
fuckADuck();
rubADub();
lubAFlub();

You can also now use the return value for something useful. You're welcome.
>>
I'm new and teaching myself C and in a thenewboston video, he issued a challenge where you have to write a program that asks for a password then checks to see if it includes an uppercase, lowercase, $ symbol and digit.

Anyone want to look at my code and tell me how shit it is or how I can improve it?

#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>

int main(void)
{
int i = 0;
char pass[21];

bool upper = false;
bool lower = false;
bool digit = false;
bool symbol = false;

do{
printf("\nEnter password: ");
fgets(pass,21,stdin);

for(i = 0; i <= strlen(pass); i++){
if( isupper(pass[i]) )
upper = true;
if( islower(pass[i]) )
lower = true;
if( isdigit(pass[i]) )
digit = true;
if(pass[i] == '$')
symbol = true;
}

if(strlen(pass) < 6 || strlen(pass) > 20){
printf("\nPassword does not meet length requirements.\nPassword must be between 6 - 20 characters.\n");
continue;
}

else if(!upper || !lower || !digit || !symbol){
printf("\nPassword not strong enough.\nMust contain lowercase, uppercase, digit and $ symbol.\n");
continue;
}
else{
printf("Password accepted.\n");
return 0;
}
}while(strlen(pass) < 6 || strlen(pass) > 20 || !upper || !lower || !digit || !symbol);
}
>>
>>57036875
Hmm, yes, I suppose you're right. If you don't take the branch, then the cost of the effective nop is very small.

Onto a slightly different point: If I were to use C++ with exceptions disabled, presumably the compiler will generate some data for calling destructors at the end of a function, but am I right in thinking this would be the same as the code I would have to write myself if I were using C?
>>
>>57036905
>muh aesthetics
try{
fuckADuck();
rubADub();
lubAFlub();
} catch(Exception e) {
e.printStackTrace();
}

fuckADuck() throws IOException {
/* ... */
throw new Exception("whatafuck");
/* ... */
}
//etc
>>
>>57036860
What command does that?
>>57036875
newb here haven't learned this yet
>>
>>57036785
>An exception happens. It checks the stack frame for an exception handler. It verifies if the types match. If it doesn't, it destroys the stack frame and unrolls the stack until it finds an exception handler with correct type (the default one just terminates the program).
That is not how exceptions are implemented these days.
They use static tables containing the addresses where it should be caught and what destructors to call, so it's just a constant time lookup, call potential destructors, jump directly to catch-address.
>>
>>57036965
No idea, I don't know bash scripting because I'm not a masochist.
>>
>>57036972
Well, that's still more than a nop, and still less memory efficient than a simple if statement.
>>
>>57036785
All this wrong info. Classic /g/.

#1: C++ can implement exceptions with 0 real runtime cost. You'll get minimal overhead from exception tables, but it's 100x better than slapping conditionals in the code.

#2: > And then you just handle it there and then. Magnitudes simpler.
It's not simpler -- you end up having to put a conditional every damn time you call a function.

#3: What it boils down to, is that exception handling introduces a lot of bookkeeping data into the stack frame.
Just no.
>>
>>57036875
Oh, and thanks anon. This stuff is still a mystery to me.
>>
>>57036993
>with 0 real runtime cost
>You'll get minimal overhead from exception tables

that contradiction tho
>>
>>57037002
(as in, I haven't started learning about it until now)
>>
>>57036957
we're using C++, and it's not just aesthetics.

With return codes, a function has to acknowledge and handle all of the possible error conditions of every function it calls. At the very least, it has to save / pass the return code up to the calling function like so:
int result = 0;
if (result = fuckADuck())
return result;

That's 3 (arguably 2) lines of code and a conditional just to call a function. It's easy to forget, and it's a shitload of conditionals.

Exceptions let you write small, decomposed functions easily, without having to smother your real code with error value checks.

Also,
>exception specifications
horrible ideas plz go
>>
>>57036945
The only thing I can think of is that your do while loop is pretty pointless and has a lot of duplicate checking of all of the conditions.
You could get away with that just being an infinite loop.
Otherwise, your code seems decent.
>>
>>57037013
>runtime cost
>RUNTIME COST
it's a O(your code) SPACE cost in static memory, separate from code cache. That's not runtime cost, and it's a trivial amount of space cost. Meanwhile, all those conditionals have to be put in code cache and executed. Sucks to be slow.
>>
>>57037068
>he thinks it doesn't take time to traverse the exception tables

>laughingchinkcartoongirls.jpg
>>
>>57034830
so I developed a cipher in HS basically a modified keyed ROT, how do I go about making it into a script in python?
>>
>>57037054
>With return codes, a function has to acknowledge and handle all of the possible error conditions of every function it calls.
As you should do if you want robust and good software.
A program should not crash just because of various 'erroneous states', it should be able to deal with them and at the very least provide a diagnostic of what went wrong.
>>
>>57037054
>horrible ideas plz go
Exception specifications are a wonderful idea, and a critical component of type safety. It's only historical contingency that causes its implementation in C++ to be worthless.
>>
>>57036945
Couple of small errors:
>fgets with len 21 will overflow by 1 with a length 20 string: you need to account for the null terminator
>i <= strlen(pass) will access pass[strlen(pass)]. This will just end up pointlessly checking the null terminator.
>you're encoding the logic checks twice -- once in the while condition and once in the body of the loop. Can you figure out how to remove one instance?
>>
>>57036945
C does strings using null terminators. Because you set 'fgets' buffer length to 21, you can do for i, from 0 to 21.

You can check if any of the first 6 elements contain a null terminator. Because your fgets buffer is sized to be 21, it's impossible for strlen to be > 20.

You only need one Boolean.
>>
>>57037096
which is only required when the exception is thrown. you're much better off with a fast 99.9% case and a (slightly) slower 0.1% case. Especially when it means you no longer need 3 lines of code to call a fucking function.
>>
Just started learning C a couple of weeks ago. How is my code?

#include <stdint.h>

/**
* @param n n
* @return d on success, -1 on failure
*/
int64_t f(uint8_t n)
{
if (n <= 1) return n;
/* if n is greater than 92, fail */
if (n > 92) return -1;
n -= 2;

uint64_t a = 1, b = 1, c = 0, d = 1, e = 1, f = 0;

while (n) {
uint64_t g, h;
if (n & 1) {
g = a * d + b * e;
h = b * d + c * e;
f = b * e + c * f;
d = g;
e = h;
}
g = a * b + b * c;
a = a * a + b * b;
c = b * b + c * c;
b = g;
n >>= 1;
}

/* return d */
return d;
}
>>
>>57037129
that slightly slower 0.1% case is inconsistent in how long it takes which is problematic if you're working on something like audio

you still need to use traditional error handling in tight loops, so why throw another error handling method into the mix?
>>
>>57037117
>>fgets with len 21 will overflow by 1 with a length 20 string: you need to account for the null terminator
fgets will read at most n-1 bytes, and guarantees that the null terminator will always be there.
What he's doing is correct.
>>
>>57037139
It would be a lot better if it gave any indication at all of what it's doing. What is this function computing?
>>
>>57037129
>he doesn't know about macros and goto

#define maybe(x) do { if (x) goto cleanup; } while (0);


then

int blah(void)
{
int rv = 1;

char *y = NULL;

maybe( f(x) );

maybe( g(&y) );

maybe( h(z) );

rv = 0;

cleanup:
free(y);

return rv;
}
>>
>>57037152
>inconsistent in how long it takes which is problematic if you're working on something like audio
Is your *actual error handling* a no-op? If it's not then your runtime's going to be different no matter what.

>you still need to use traditional error handling in tight loops
I use inline arch-specific ASM in tight loops, that doesn't mean I'm dumb enough to write everything like that.
>>
>>57036346
>what do you use for this
>all roads seem to lead to snek and i don't like it
What?
>>
>>57037157
The nth Fibonacci number.
>>
>>57037152
Because one implementation optimizes for EXCEPTIONAL (i.e. should never normally happen) circumstances and the other is more liberal in that it adds tiny overhead to both success and failure so that either can happen without disrupting too much.

Ideally you use a nice language that lets you abstract over the two implementations but you're stuck with the bare bones in C++. You're using C++ so why the fuck are you complaining about there being two solutions to a problem even though they differ in the scenarios they are optimized for?
>>
>>57037129
You're comparing apples to oranges.
Your '99% case' would only occur when you basically never handle any errors, i.e ignores and let default terminate be called.
You can do the same with return values - just ignore them and let program crash on null pointers or w/e.
If you actually want to *handle* errors you're gonna need lots of try catch blocks and many errors do happen quite frequently like i/o (timeouts, file not found, etc).
>>
>>57037154
Good catch. I should recognize that from:
functionCall(charArr, sizeof(charArr))
>>
>>57037178
Mistyped. Scrap the final semicolon on the macro
>>
>>57037197
Often I want to handle an error 4, 5, or 6 levels up the stack. Exceptions let me cut out all the return code crap in the inner functions.
>>
>>57037197
>just ignore them and let program crash on null pointers or w/e
please tell me no one lets you work on production critical systems

> lots of try catch blocks and many errors do happen quite frequently like i/o (timeouts, file not found, etc).
Not in my experience, but YMMV based on domain / application.
>>
>>57037209
>>57037178
That calls f(x), g(&y), and h(z) twice
>>
>>57037197
>Your '99% case' would only occur when you basically never handle any errors, i.e ignores and let default terminate be called.
This is wrong. It's about how frequently the error should come up in practice, not about coverage of proper error handling in the code (because the latter should be 100%).

Pretending that all errors are created equal is wilful ignorance.
>>
>>57037230
Um, what? How does it call them twice?
>>
>>57037230
Never mind -- misread that. You just need to set rv inside the macro
>>
>>57036977
Fuuuck :(
>>
>>57037271
I'm using rv=0 for success, rv=1 for failure. The idea is that if any of the calls to f, g, and h fail, then any remaining calls will be skipped, rv will remain as 1, cleanup will happen, and then rv will be returned.
>>
>>57037289
That's fair if you don't want to propagate the underlying error code up to the caller. Suppose that makes sense.
>>
>>57037303
Oh, ISWYM. You're correct.
>>
>>57037139
>one letter variable names with minimal comments

D:
>>
>>57037345
It makes compilation faster.
>>
>>57037358
>It makes compilation faster.
not in a way that humans would notice
what are you doing
>>
>>57037415
Well, the function works, it's not like I'll ever need to rewrite it.

Single character names also makes the code smaller on disk.
>>
>>57037427
Not in a way that any human would ever notice
Stop doing retarded shit, if you ever get hired you WILL get fired for stuff like that and you'll kill yourself if you ever have to debug your code
>>
>>57034998

>why do programming language FFIs let me call "C functions"? What the fuck even is a C function? C doesnt exist at that level, it gets compiled away. there's only machine code.
Most operating systems have their respective API functions (i.e. Win32 API, Unix system calls, etc...) written in C. C compilers will generally have a standardized ABI centered around what the OS uses. Other languages may not necessarily follow the same rules. Consider the case of C++ on Windows. There are main compilers, MSVC++, and MinGW-w64. Both have a different name mangling scheme, and a different way of hangling exceptions, that makes linking code from both compilers pretty fucked. But since C is what was used for the Win32 API, they both follow the exact same rules for C. If a language wants to be extensible to other languages using a Foreign Function Interface, it helps that everyone plays by the same rules on how functions are called. Since C has a stable ABI for this, C is typically the gold standard for this. If I want to write a native library for Ruby in C++, I will have to export my functions as extern "C". If I want to use Rust, I similarly have to use #[no_mangle] for my functions, and if I want to pass structs around with different languages, I need to use #[repr(c)].

>why the fuck do we even need a {C runtime"? whatever the fuck that is. windows programs keep moaning over muh precious C runtime dll. why. the ABI is processor architecture + OS system calls. no need for all this faggot ass shit. am I wrong?
The "C runtime" is the implementation of the C standard library. If you use printf, or malloc, or any other C function, it has to be defined somewhere.
>>
>>57037441
I already debugged it, and when I wrote it I used longer variable names. I only optimized it once I had removed all the bugs.
>>
>>57037442
C standard library a shit

strings should be

typedef struct string {
size_t num_chars;
char *chars;
} string_t;
>>
>>57037473
But /why/
Even if you're deploying to a microcontroller, the compiled code is the same size.
>>
>>57037482
literally why
>>
>>57037483
To save space on disk. The source code takes up space too, y'know.
>>
>>57037491
so strlen would be O(1)
>>
>>57037518
while(foo[i]) {
//parse string
}
>>
>>57037529
The final char could still be a null byte.
>>
File: Mr_Robot_s2e4_hacking_the_FBI.jpg (123KB, 1012x570px) Image search: [Google]
Mr_Robot_s2e4_hacking_the_FBI.jpg
123KB, 1012x570px
Quick guys I need some help! How do I hack the FBI?
>>
Guys I made the code even smaller

#include <stdint.h>int64_t f(uint8_t n){if(n<= 1)return n;if (n>92)return -1; n -= 2;uint64_t a=1,b=1,c=0,d=1,e=1,f=0;while(n) {uint64_t g,h; if(n&1) {g=a*d+b*e;h=b*d+c*e;f=b*e+c*f;d=g;e=h;}g=a*b+b*c;a=a*a+b*b;c=b*b+c*c;b=g;n>>= 1;}


>>57037503
Not any space that's meaningful. How big is your hard drive, 1kb?
>>
>>57037529
this

>>57037518
why would you need to know the length if you can just parse it directly

unless you're sorting by length, strlen in pointless
>>
>>57037560
40gb
>>
>>57037582
I will buy you a 32 gigabyte flash drive if you promise to name variables useful names and to comment your code
>>
How would I go about using Scala to interface with my Arduino?
Is it worth it?
The only literature I can find is some dudes home automation and a forum post from like 2011.
>>
>>57037620
That's a promise I just can't make, anon.

I always use names like x or i for counter variables, and comments are worse than useless because there's nothing to stop them falling out of sync with code.
>>
>>57037635
Use C and JNI
>>
>>57037638
nobody gives a shit about counters
the only person stopping you from commenting is you

Even so, it's still useful to outline the purpose of a function, its results, and its other side effects
>>
>>57037638
Well obviously iterators will be named x or i- those are actually useful names (iterator, and ....x. coordinate.)
Iterators can be 1 char and that's fine because usually they're defined directly above and have no scope.

>and comments are worse than useless because there's nothing to stop them falling out of sync with code.
Update them when you update the code?
>>
>>57037554
Learning
https://cybrary.it/
https://n0where.net/
https://www.offensive-security.com/metasploit-unleashed
http://resources.infosecinstitute.com/
http://www.windowsecurity.com/articles-tutorials/
https://www.sans.org/reading-room/
https://www.corelan.be/index.php/articles/
http://opensecuritytraining.info/Training.html
https://www.blackhat.com/html/archives.html
http://www.securitytube.net/

News/CVE releases
https://threatpost.com/
https://www.deepdotweb.com/
https://packetstormsecurity.com/
https://www.cvedetails.com/
http://routerpwn.com/
http://www.exploit-db.com/
https://www.rapid7.com/db/
http://0day.today/

Wargames
https://overthewire.org/wargames/
https://www.pentesterlab.com/
http://www.itsecgames.com/
https://exploit-exercises.com/
https://www.enigmagroup.org/
http://smashthestack.org/
http://3564020356.org/
https://www.hackthissite.org/
http://www.hackertest.net/
http://0x0539.net/
https://vulnhub.com
https://ringzer0team.com/
https://root-me.org/
https://microcorruption.com/
https://starfighter.io/

http://catb.org/~esr/faqs/hacker-howto.html
>>
>>57037644
As in use C instead of Scala?
Also, JNI appears to be a whole can of worms
>>
>>57037676
Call C from Scala using JNI.
>>
>>57037660
>>57037659
I have to admit I'm a bit disappointed that nobody commented on the time complexity of my code.
>>
>>57037692
I tell you what, I could have told you that it's possible to get the nth fibonacci number in O(1) using the golden ratio but your shit var names were more important
>>
>>57037723
But for that to be true exponentiation would have to be O(1), and it isn't.
>>
>>57037743
>implying \forall n log_2(n) < 64 is not a very small number
>>
Lmao!! you all suck at programming
>>
>>57037796
>1 post by this ID
>>
>>57037800
but you do suck at programming
>>
>>57037831
>2 posts by this ID
>>
%% isBasic? tests whether a given sequent is basic
%% A sequent is basic if some formula occurs in both the left-hand
%% list and the right-hand list. For example, sequent P, Q |– P, Q is
%% basic, as is P, Q |– Q.

Define isBasic?(left |- right) = someSatisfy (x |-> x `in` right) left.

is there a more patrician language?
>>
I've uploaded my first set of predictions to numerai.

The score is terribad and my own logistic loss fundtion calculates bullshit, but I'm proud as fuck.
>>
>>57037796
I'm still probably better than you :)
>>
>>57037888
no you're not, you're just a faggot who cant event write fizzbuzz properly
>>
>>57037906
wrekt faggot https://github.com/yureru/Patchy/blob/master/source/RecursiveFizzBuzz.cs
>>
I love cubical type theory!
>>
>>57037906
#include <stdio.h>
#include <stdbool.h>

int main(int whatever, char **fuck_you) {
for (int i = 1; i <= 100; i++) {
bool printed = false;

if (i % 3 == 0) {
printf("Fuck");
printed = true;
}

if (i % 5 == 0) {
printf("Butt");
printed = true;
}

if (!printed) {
printf("%d", i);
}

printf("\n");
}

return 0;
}
>>
>>57037928
Does the CLR do tail call optimization?
>>
>>57037978
From what I've heard, yes. But don't quote me on that.
>>
File: IMG_20161012_055224019.jpg (3MB, 4160x2340px) Image search: [Google]
IMG_20161012_055224019.jpg
3MB, 4160x2340px
I work on this
>>
>>57038069
>falling for the Raspberry Pi meme

buy a PIC, they're more fun
>>
>>57038085
Did use a avr for this first, but I want muh database, Webserver n Internet. So raspi is better choice
>>
Does anyone here use emacs? I'm trying to do two simple things that I am finding to be very difficult:

> 1. Disable indentation altogether. I did this by setting 'electric-indent-mode' to -1.

This works. Now, when I insert a new line with return, it takes me to column 0 on the new line.

>2. I would like to have emacs insert spaces up until the first non-space column of the last non-empty line

So:

    Hello World // then press return on keyboard
< // cursor should end up here
>>
>>57038154
Why not vim?
>>
>>57038209
i have to use emacs for work
>>
>>57038232
What kind of fascist workplace forces you to use a particular editor?
>>
man, I'm glad my code is self-documenting or it'd be a lot more work
>>
>>57038237
I can't say but it truly is a horrible place
>>
>>57038271
Which country? Which sector?
>>
>>57038260
The problem with comments:

/**
* Checks whether the connection is still valid.
*
* @param conn the connection
* @return 0 on success, -1 on failure
*/
void reset_connection(void);
>>
>>57038276
CANT SAY CANT SAY IM SORRY
Its a huge company though. Not big 4, but used by the big 4 for very important services.
>>
>>57038334
Jesus anon I just want to know what to avoid.
>>
If I want the vertex normals of my triangle in OpenGL to be parallel with their vertex does that mean I basically use the same vertex coordinate as my normal and normalize that?

I'm awful at normals ;_;
>>
>>57038401
FUCKING NORMALS GET OUT
>>
Is it fine to focus on both web dev and software dev at the side time?
I am focusing on php and css/html/js and plan on doing Java for CS concepts and apps
>>
>>57038480
who is stopping you nigga?
>>
>>57036860
>>57036875
What i've got so far
array=( A B C D . .)  #all the way to Z
for (( i=0; i < $1; i++))
do
ran=$[RANDOM % 25]
echo "{array[$ran]} | uniq -u
done


does this
$./file 8
A
H
B
P
N
A
X
N

I've tried moving the uniq around I'm still getting the same problem
>>
File: mergeSort.gif (41KB, 540x369px) Image search: [Google]
mergeSort.gif
41KB, 540x369px
How would I sort a file that has grade percentage in java?
>>
>>57038401
You can't be parallel to a vertex.
>>
>>57038501
time ;_;
>>
>>57038526
What about parallel to the vertical edge of my triangle? would it be the vertex at the top of that vertical edge normalized?
>>
>>57038559
Vertical edge? And you can't normalize a vertex. Sort out your terminology, PLEASE.
>>
>>57038564
please no bully
>>
>>57038568
I'm not bullying. I cannot help because I have no idea what you want.
>>
>>57038579
I just want to my vertex normal vectors to be parallel to my vertical edge.
>>
Listening to some talk about tuples in C++11/C++14. Still have yet to see a benefit to using them over just making a fucking struct.
>>
>>57038652
Tuples are more generic, and so you can write reusable functions that work on tuples, instead of having to create specialized ones that only work on one particular struct.
>>
When learning programming, is it better to learn by looking at the book and applying it through the computer or physically writing notes.
>>
File: tegaki.png (4KB, 400x400px) Image search: [Google]
tegaki.png
4KB, 400x400px
Cubical type theory is REALLY neat, particularly the formulation of Valery Isaev. It actually makes the interval a type in the system, with introduction and elimination rules.

Instead of being able to do case analysis on the interval type, its eliminator allows the construction of Kan fillers that can be used to accomplish the same thing while remaining computationally nice. For example, to derive 1-x (1-0 = 1, 1-1 = 0), you construct this "open box", fill it, and project out the "lid".
>>
>>57037566
Because going one character at a time is slow (if you know the length you can process N / X chunks at a time using wider registers), and not everything is just parsing the whole string, operations like concatenating two strings need to know where the first one ends.
>>
>>57038652
I don't remember that well, but doesn't template meta programming magic let you iterate over tuple contents and shit, like create a type list
>>
>>57038669
>>57038690
So aside from template abuse, what real world uses are there for tuples?
>>
>>57038652
for a start, C++ doesn't have structured binding for structs
second, you don't always want named fields.
sometimes you literally just want multiple values.
third, you can write functions over tuples

fourth, it's much more concise than creating a million definitions and can be done without adding another top level definition

in Haskell it has a much more consise syntax:
(a, b) :: (A, B)
>>
>>57038670
Exercises + notes on files + anki.
I don't like writing those on paper since can't look/search in a fast way.
>>
>>57038712
sankyu
>>
>>57038652
>>57038706
Contrast:
// needs to be a unique name
struct Result {
// need to name fields
int x;
float y;
}

Result foo() { /* ... */ }

Result r = foo();
int x = r.x;
float y = r.y;

with:
std::tuple<int, float> foo() { /* ... */ }

int x;
float y;
std::tie(x, y) = foo();
>>
>>57038731
come on
it's C++ 2017


auto& [x,y] = foo();
>>
>>57038721
anime are not human you degenerate
>>
>>57038737
Oh, I didn't realize it had tie syntax already.
>>
File: 700px-Shoe0nheadisamudshark.png (694KB, 700x906px) Image search: [Google]
700px-Shoe0nheadisamudshark.png
694KB, 700x906px
>>57038739
fine
>>
>>57038706

Pissing you off.
>>
>>57038758
back to /pol/ faggot
>>
>>57038775
I don't actually like /pol/ but i like their autism
>>
>>57038765

That is a valid reason.

Also, join the Discord. We have NV now.
>>
>>57038865

I don't even use discord. Besides, not really installing anything at the moment. My new parts were supposed to be here yesterday, but they got delayed.

Once I get the new rig setup, maybe I'll join the fagfest.
>>
>>57038938

You don't even need to install anything. There's a web application.
>>
>>57038958

I prefer [spoiler]desktop applications[/spoiler]. Like I said, let me get shit setup first and then I'll get on there.

Then we can discuss averaging two (2) integers in C in real time!
>>
File: pyautoguipicture.png (132KB, 633x718px) Image search: [Google]
pyautoguipicture.png
132KB, 633x718px
Just installed pyautogui, made it write more useless code.
>>
Anyone use Go?

I need a database for Go that doesn't make me want to kill myself. Sqlite3 doesn't work so that's out of the window. I don't want a pure K/V store, I need hierarchical data and some way to query it. Doesn't have to be relational but I at least need mongoDB-like params where I can specify stuff, get users newer than 3 months for example. I don't want to install and connect to some monolith like MySQL/PostgreSQL. Pure Go preferably because muh single static binary.
>>
Just writing some really shitty MIPS assembly
# Set Variable
# sets variable to new value if it exists, if it doesn't exist
# allocate more space and append the new mapping to the list
#
# @param a0: address of variable string
# @param a1: new value associated with variable
#
# caveat: if variable string isn't nul-terminated, the behavior is undefined
#
# C(ish):
# {notfound, loc} = _findvar(string);
# if (notfound) {
# loc = malloc(alignup(strlen(string)+5));
# strcpy(loc+4, string);
# }
# *loc = value;
#
setvar: # save
addi $sp, $sp, -8
sw $ra, 4($sp)
sw $a1, 0($sp)
# attempt to find node of given variable name
jal _findvar
beq $v0, $zero, _setvar_L1
## alloc new space
push($a0)
# get string length
jal strlen
# add space for nul-terminator and word
addi $a0, $v0, 5
# align up to word boundary
jal alignup
# sbrk - allocate memory
move $a0, $v0
li $v0, 9
syscall
# change end pointer
add $a0, $a0, $v0
sw $a0, _varlist_end
move $v1, $v0 # save pointer for saving word
# strcpy variable name into list
addi $a0, $v0, 4
pop($a1)
jal strcpy
move $a0, $a1
_setvar_L1: # reload
lw $a1, 0($sp)
sw $a1, ($v1) # save new word in variable node
lw $ra, 4($sp)
addi $sp, $sp, 8
jr $ra
>>
>>57039029
I guess the documentation for the Cish pseudocode should read
*((int*)loc) = value;
>>
I scraped the top 10,000 domains from /g/ between 2010 and 2015 from the archive.moe dump: http://pastebin.com/miYNZBD5

I think it'd be significantly more interesting to see this plotted by percentage over time, but this was easy to do with regex without actually creating a database (simple sqlite import failed).
>>
I'm about to get promoted to an accounting position, I'm interested into getting deep into VBA for Excel. While there seems to be a lot of "guides" and "tutorials" out there, most of them doesn't seem to get deeper into the subject.

Or should I stick with VB books?
>>
bump
tea
>>
>>57039270
>2443 gnu.org
>2425 www.apple.com
Take that, applefags.
>>
Why doesn't this work?
The language is Scala
def moveBall(field:Array[Int], direction:Int, ballpos:(Int,Int)):Array[Int]= direction match {
case -2 => field((ballpos._1))(ballpos._2) = 0
}

the compiler reads
/error: value update is not a member of Int
>>
What C++ book to learn from?
>>
File: 2016-09-19-164543_547x226_scrot.png (28KB, 547x226px) Image search: [Google]
2016-09-19-164543_547x226_scrot.png
28KB, 547x226px
>>57039538
>>
>>57039527
What an ugly, verbose language
>>
>>57039581
you must've never used C++ before
>>
>>57039590
>it's ok because a more verbose language exists

Scala truly is the Java of FP
>>
My program works fine when there is only one network interface with an IP.
I don't want to make users select which one.. It breaks if I don't because it binds to the wrong one.. This is a windows program.

What should I do?
This is my fix so far..
import socket
local_ips = [i[4][0] for i in socket.getaddrinfo(socket.gethostname(), None)]
for n, ips in enumerate(local_ips):
print(n, ips)
HOST = local_ips[int(input("Which IP is your current interface using?"))]
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
s.bind((HOST, 0))

I use psutil to find out what port a program is using, I'm not sure exactly to see what interface that program is using. I'm guessing that would be the best way.
This is all I get from psutil:
pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=2, laddr=('0.0.0.0', 57122), raddr=(), status='NONE')

Any ideas?
>>
>>57039573
thanks baby girl
>>
>>57039604
i don't see much verbosity there, in fact what he just did would take more lines / letters to write in other languages.
>>
File: wat.jpg (111KB, 500x500px) Image search: [Google]
wat.jpg
111KB, 500x500px
>>57039025
>Sqlite3 doesn't work

Even Go can't be that bad. I refuse to believe it.
>>
>>57039655
>java style function syntax
>._1
>(( ))
>>
whomade god = "super " ++ god
>>
>>57039676
the underline thing seems more of his own doing, you can set numerical properties using "1", and java syntax is like C#'s, this is pretty different, tho the pharantesis made me laugh
>(((business programming language)))
>>
>>57039025
https://github.com/mattn/go-sqlite3

You gotta do what you gotta do.
>>
>>57039689
whomade = ("super " ++)
>>
>>57039722
unreadable in the sense that you lost context of the variable name
>>
>>57039733
>writing functions based on variable names
>>
>>57039740
>power a b
>power base exponent

which looks better
>>
>>57039751
top
or

a `power` b
>>
>>57039757
I really don't understand why haskellers want one letter parameters

it doesn't help documentation

variable names give extra context aside from the function signatures
>>
>>57039776
I hate you "everything needs a million lines of documentation" people

when you said power base exponent, didn't you mean

returnsAnIntPower intBase intExponent
>>
>>57039787
function signature already gives that info
I think that you're just making a shitty argument against proper variable names
>>
>>57039025
I remember sqlite being relatively easy to get going in Go.
>>
>>57039796
It's fucking obvious from the function, and if it weren't you could literally fucking call it once and figure it out

You literally want everything fucking dumbed down and all the lines of code doubled
>>
>>57039806
yeah sure, that will help in programs not fizzbuzz tier
>>
No classes today. I'm going to keep learning C in this cold and comfy morning. I love it.
>>
>>57039822
It will faggot, when you don't have to add an extra four fucking names explaining what the function does, despite the name telling you, what the variables do, despite the name and the code telling you, what the types are, despite the types telling you
>>
>>57039823
Show me your most powerful C snippet
>>
>>57039828
lines*
per function

or variable
>>
>>57039828
t. person who'd write
mainLoop a b c d fs gs
>>
>>57039830
no snippets just textbook excercises and two eurler project problems
>>
>>57039847
fs is a container of some kind and so is gs

I wouldn't write this anyway
>>
>>57034830
>working in the last months of life in this form

why do this
praise absurdo
>>
>>57039806
>you could literally fucking call it once and figure it out
Just, No.
This puts a significant overhead into your work flow.
I shouldn't have to do science on an artificially constructed phenomenon.
>>
>>57039806
that only works for functions with two args
try that with a function with 5 arguments
>>
>>57039830
->
.
>>
>>57037139
>n >>= 1;
wtf, c has monads?
>>
File: 1441238564946.png (151KB, 374x363px) Image search: [Google]
1441238564946.png
151KB, 374x363px
Been trying to round a float number to two decimals but it doesn't work. Anyone care to help me by saying what I need to write?

floatOne = 72.66
floatTwo = 59.89

answer = floatOne - floatTwo
round(answer,2)


I keep getting 12.769999999999996
>>
>>57039657
It's some sort of build problem with mingw and windows or something, I don't know... it just doesn't work. It compiles and it seems like it should work but it doesn't.

>>57039715
Yeah that's the one that doesn't work.

>>57039805
Maybe if it works.

It doesn't though.

Jesus christ you guys...
>>
>>57039912
round the variables
or
google the fuckin round() function lol
>>
>>57034884

are you good with gdb and their python api?
>>
>>57039912
answer =  round(answer,2)
>>
>>57039933
doesn't work.

i have.
>>
>>57039912
c++ parses undefined numbers as doubles by default, for floats you write

0.0f or 5.f
>>
>>57039955
holy fuck it works

thaaaanks!

i was confused because earlier i did this

floatOne = 72.66
floatTwo = 59.89
answer = floatOne + floatTwo

round(answer, 2)


and it worked perfectly
>>
>>57039976
You were probably working in the REPL, which automatically prints out the value of any expressions you type.
>>
>>57039976
>>google the fuckin round() function lol
>i have.
clearly not

>round(number[, ndigits])
>Return the floating point value number rounded to ndigits digits after the decimal point.
>Return the floating point value
>Return
>>
>>57039869
>Just, No.
>This puts a significant overhead into your work flow.
>I shouldn't have to do science on an artificially constructed phenomenon.

>open ghci
"power 1 0"
>is it 1? then it's base exponent
>is it 0? then it's exponent base
(<1 second)
you now know forever

who the fuck would even do exponent then base
you can fucking tell the order of same-typed args half the time

this is retardation

>>57039875
>function with five args
normally that's shitty programming
>>
>>57040012
Your face is retarded.

I'm inclined to agree with this sentiment >>57039822
>>
#pragma once or #ifndef #define
#endif ?
>>
File: grid.png (39KB, 1842x302px) Image search: [Google]
grid.png
39KB, 1842x302px
I have a set of integer points, the point set could be huge (couple of million points), i need to rotate them to a given position, then i need to make sure that the rotated points are integer coordinates. In order to do that i tried rounding, ceil, floor, casting to integer, but im "losing" points with every method. Whats happening is when im converting the points to integers, some points get the same coordinates and overlap, leaving a hole in the pattern.

How would you do this to keep the points from overlapping?
>>
>>57039573
wait do I skip effective c++ for the modern version?
>>
>>57040056
make it bigger before you round
>>
>>57039985
hmm maybe i'm still in my second week of my online python course so i'm not familiar with all the terminology.

using the cygwin prompt and it was a homework that I was doing which i was supposed to write the code in an already made file by my teacher that when i run it in the prompt it says whether I was correct or not. so yeah you're probably correct, thanks though! im finally done with this, i had done everything except this one(which was one of the first assignments)
>>
>>57040012
-- function that takes a first date, takes a number indicating how many other weeks the computed dates should be apart,  takes a list of weekdays that indicated the structure of the computed weekdays, and a last number indicating the first n computed dates

recurringDates firstDate skip weekDays n
>>
>>57040078
jesus christ that fucking comment

also
>n
>>
>>57040064
Then the same would happen, only the holes would appear somewhere else.
Scaling the points wont work either because when you scale back you end up with floats that needs to be converted to ints again.
>>
>>57040056
You could do a line sweep and round the x coordinate to the next largest integer after the last point?
That would probably skew the shape a lot though.
>>
>>57040126
what you want seems practically impossible
>>
>>57040128
Can you explain this? Are you thinking of the scanline algorithm?
>>
>>57040162
Something like that.
I mean, if the problem is that points get rounded to overlapping coordinats you can make sure this doesn't happen by rounding up instead of rounding down, if rounding down would make a point overlap with an already rounded point.
That's the basic idea. It will need more work to make it function satisfactorily, though.
>>
I'm trying to understand these TSP solvers.
Earlier today, I wrote an algorithm to find the K nearest-neighbors for all points.
How do I know that for any given TSP algorithm, that this set of neighbors is good enough that I can simply pick from the set of neighbors to produce an edge, and that at the end, there will be no points that haven't been included in the cycle?

In other words, how do people normally write algorithms like Ant Colony for large graphs, while making sure that every point is included in the cycle?
>>
I've realised that XML based programming languages are the future.
>>
>>57040232
Clarification: Rounding 'up' in this instance might mean having to shift a point by several integer units.
>>
>>57040253
Did you forget your medication?
>>
How simillar is C to Java? I'm still learning Java, but from what I've seen here, it seems like they both have a similar style. Could I easily jump from learning the basics of Java, to doing some basic coding in C?
>>
>>57040295
>How simillar is C to Java?
Not at all similar.
>Could I easily jump from learning the basics of Java, to doing some basic coding in C?
Sure.
>>
File: IBM_Cassette_BASIC.png (2KB, 640x350px) Image search: [Google]
IBM_Cassette_BASIC.png
2KB, 640x350px
I've learned BASIC when I was in highschool.
Since then I majored in something entirely not related to tech,
But I'd like to go back and learn a programing language again.
What should I learn?
>>
>>57040295
Java has C-like syntax, and a few of the types have the same names, but the similarities don't go much deeper than that.
>>
>>57040308
learn x86 assembly and work your way up
>>
>>57040314
Ah aight, thanks. Guess I still have a shallow understanding of C. mite b fun to try it out later though.
>>
>>57040295
Java is to C in the same way that Arduinos are to plain old circuits.

Although you could say that describes Python better.
>>
>>57040295
They are similar in the sense that Java syntax is derived from C/C++.
C lacks the syntax framework for classes and object orientation you might be used to from Java. If you can get over this fact, going from Java to C shouldn't be terribly hard.

I could be wrong though. I did it the other way around.
>>
>>57040308
C
>>
New thread:
>>57040421
>>57040421
>>57040421
>>
>>57040318
>>57040363
>x86 assembly
I'm not joking.
My highschool socialist curriculum, taught BASIC in computer class as an advance programing language
1000 REM Fibonacci Sequence Project
1010 REM Quite BASIC Math Project
1020 REM ------------------------
2010 CLS
2020 REM The array F holds the Fibonacci numbers
2030 ARRAY F
2040 LET F[0] = 0
2050 LET F[1] = 1
2060 LET N = 1
2070 REM Compute the next Fibbonacci number
2080 LET F[N+1] = F[N] + F[N-1]
2090 LET N = N + 1
2100 PRINT F[N];", ";
2110 REM Stop after printing 100 numbers
2120 IF N < 100 THEN GOTO 2080
.

This was my project, the teacher gave me B because it was "plain", while she gave another A+ because he used play command to play a siren with 4 your's old equivalent of a cop car.
>>
>>57040056
Not sure it suits your usecase but you could try this: http://datagenetics.com/blog/august32013/
>>
>>57040483
That's what happens when you go to an inner-city high school.
You have no one else but yourself to blame for being born :^)
>>
>>57040483
Yeah well, highschool is highschool. You can't expect too much from high school teachers.
>>
>>57040483
>>57040505
In high school i had a teacher in a computer literacy class, who claimed that the only way to be safe from computer virii is to not put a floppy disk in the drive.

Possibly he might have been confused about which class he was actually teaching.
>>
>>57040701
We didn't have health class.
Is python a good language to learn? or should I learn android programing instead.
>>
>>57040741
>Is python a good language to learn?
Try it and make up your own opinion.
>>
>>57040997
Apparently you can make VN with it using ren'py.
Going to try and learn it.
>>
>>57041018
Good luck and good fun.
>>
>int_fast8_t
>int_fast16_t
>int_fast32_t
>int_fast64_t
>fastest signed integer type with width of at least 8, 16, 32 and 64 bits respectively
What do they mean by 'fastest'?
>>
>>57040270
Proudly.
>>
>>57041128
the one that's the most fit for the cpu
>>
>>57041341
On what systems is this relevant?

On another note
 uint32_t tag = *(uint32_t*)&"RIFF";

Dijkstra is turning in his grave.
Thread posts: 327
Thread images: 20


[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.