[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: 317
Thread images: 35

File: thedonald.png (1MB, 920x599px) Image search: [Google]
thedonald.png
1MB, 920x599px
What are you working on, /g/?

Old thread: >>60032063
>>
First for Lisp is the weakest programming language.
>>
>>60037166
seconded
>>
>>60037123
Thank for the /dpt/ related picture.

DONALD RULEZ
>>
>>60037171
t. /r/the_donald
>>
Do you shower everyday /dpt/?

I don't and feels like it't throttling my programming capabilities
>>
File: ada-strong-1120-transparent.png (111KB, 1120x1120px) Image search: [Google]
ada-strong-1120-transparent.png
111KB, 1120x1120px
>continuing from last thread

I have a question about data logging in the context of high-performance simulations. We gather data at 100Hz in sim time which gets written to file and analyzed by our GNC team.

Is it faster/more efficient to write the data to disk continuously as the sim runs (i.e. 100 writes per sim-second) or store the data in memory and dump it to disk once the sim finishes?

I'm leaning toward the latter being faster as I understand disk writes are an expensive operation, but I don't know enough about the details of I/O to reason about it intelligently. I'd like to hear pros and cons to each approach, tools for profiling this kind of things, keywords for researching myself, etc..
>>
>>60037196
sometimes twice a day
>>
>>60037239
Have two buffers, when you're writing one to disk when it's full you can fill the other up.
>>
File: not my wm theme.png (3KB, 640x400px) Image search: [Google]
not my wm theme.png
3KB, 640x400px
Help, I need to come up with a 256 color default palette for RGA.
>>
>>60037354
the color I bleed for you Crimson
>>
In c++ is there some way to make locally defined functions with zero runtime overhead?

Why can i make local function declarations but not definitions?
>>
Thinking of making a way to program an arduino over wifi using an esp8266.
I'd make a utility program to connect to the esp8266 over the network, then write a driver or whatever that makes a virtual com port show up in windows and routes the rs232 signals to the esp8266 which sends them straight to the arduino's uart pins. That way I can use it with any IDE I want (visual micro in my case).
Good idea?
>>
>>60037239
Whom quotes?
>>
>>60037624
Go be mentally retarded elsewhere.
>>
Anons why won't this work, it compiles and executes and I get the right number of nodes in tree, but it's still wrong according to professor. :S



void BSTree::insert_recursion(BSTNode *parent, const int num)
{

BSTNode *temp_root;

if(parent==NULL)
{
BSTNode *new_Node = new BSTNode(num);
parent = new_Node; //Root pointer points at the New Node
n_elem++;
}

else if(num < parent->value)
{
insert_recursion(parent->left, num);
}

else if (num > parent -> value)
{
insert_recursion(parent->right, num);
}

else if (num == parent -> value)
{
root -> count = root -> count + 1;

}
}

>>
>>60037488
>locally defined functions
Why would you want to?
>>
>>60037239
Look into multithreading.

You keep one thread to gather data at 100hz and store into a shared buffer, and one thread to read chunks of data from the shared buffer, and write to disk.
>>
>>60037728
Tighter scope

>>60037488
No
>>
>>60037488
Either your local function could as well be global and there's no point in allowing nested definition, ---local declarations is a stupid feature anyway---, or there is additional functionality to it, like closure or using a different definition based on a runtime condition, and you must pay the price for it in terms of overhead. What's your use-case?
>>
>>60037787
>Tighter scope
Use multiple compilation units and static functions, or just shrug it off; who cares if it doesn't affect anything?
>>
>>60037728
>>60037788
I have a oneliner that i'm calling in several places in a switch. I ended up making it a macro, but i don't like that. Since the line only really makes sense in this one particular scope i don't want to litter the global namespace with a function.
>>
>>60037825
For the same reasons you use namespaces
>>
>>60037940
Which is? Symbol collision? I suggested the static modifier against that.
>>
>>60037714
I can't read this horrible code "style". Pull it out of the loo.
>>
>>60037714

Not a c++ guy, but the only thing I can think of is that you are going one level of recursion too deep. If you instead make your method return a node* object, you can avoid that. See the BST page on wikipedia, has a c++ implementation that works that way.

Why bother with the *temp_root btw? It never gets used.
>>
>>60037976
It's better to store the function in a scope where it's used. Having it be beyond that is bad design.
>>
>>60038092
Functions aren't stored because they aren't objects in C++.
>>
>>60038184
I know. You store them in your source code with words you typed.
>>
>>60038211
Ok, so? You agree that nested function definitions would have no runtime impact right? Now for the coding style part I agree with you because I'm a schemer, but let C++ be C++, even though it's a clusterfuck.
>>
>>60038259
I was only ever taking about style and good practice
>>
>slowing down your compiler with useless comments, whitespace and linebreaks
>>
>>60038298
*parser
>>
>>60038291
Excellent !
>>
>he is not porting his whole codebase to Rust
>>
File: blackgirlscode.jpg (105KB, 900x599px) Image search: [Google]
blackgirlscode.jpg
105KB, 900x599px
WE WUZ CODERS N SHIEEET
>>
>>60038399
rust is so bad that the so called "rust programmers" don't program in it but just shitpost to others that they should convert their whole project to rust.
>>
>>60037926
hows about a lambda?
>>
I've spent the last few months building a search engine (wibr.me) where only older html style, hobbiest made sites are kept. Which are minimal in bloat. If you know any decent sites, please submit some! (top right of page) I only got a few sites indexed and need some assistance with that.
>>
>>60038644
>I only got a few sites indexed and need some assistance with that
why not write a crawler like all the other search engines?
instead of calculating pagerank and shit just look for enormous amounts of bloat and exclude most of the internet
>>
How is Go as a programming language? I've got to learn it for an internship over the summer. Any Gophers here?
>>
>>60038741
Shit if you hate code repetition
>>
>>60038741
"The perfect language for Googlers"
>>
>>60038472
That was my first thought, but i'd have to assign it to an std::function.
>>
>>60038791
>but i'd have to assign it to an std::function
no you wouldn't
if you really want to, you can do it oldschool C style and store it in a void* and then do the appropriate casting when you want to perform the call
>>
>>60038741
Haven't found a real use for it yet but I like it.
>>
>>60037488
lambdas
>>
>>60038741
Interesting ideas, bu also lots of annoying quirks like why the fuck do we need all blocks to be scopes? If you use the "shortcut" variables declaration syntax inside an if, variables are declared at the if scope and you can't have them on the outside, so you have to explicitely declare them. What is the point? That shortcut doesn't cut.
>>
Why do I suck so much at C? I'm trying to make a really really simple thing but somehow this won't work. The first printf is fine and prints the correct length. If I add the second printf I get a runtime error, even if I force something like n=3 in the body of init
struct point {
int t;
float v;
};

struct pointArray {
struct point *arr;
int length;
int end;
};

struct pointArray init(int n)
{
struct pointArray pa;
pa.length = n;
printf("%d", pa.length); // This works and prints the correct length
pa.arr = (struct point *)malloc(pa.length*sizeof(struct point));
printf("%d", pa.length); // This causes an address boundary error
pa.end = 0;
}


Any ideas /g/?
>>
Just wrote a small program in C to filter out commented lines from a test input file, for fun. Is it good code?
#include <stdio.h>
#include <stdbool.h>

int main()
{
char c;
bool is_comment = false;
bool end_comment = false;

for (c = getchar(); c != EOF; c = getchar())
{
end_comment = false;

if (!is_comment)
is_comment = (c == '#');
else if (c == '\n')
{
is_comment = false;
end_comment = true;
}

// only print non-comments, don't print newline at end of comment
if ( !is_comment && !end_comment)
putchar(c);
}

return 0;
}
>>
>>60038906
No. Except maybe if length <= 0
>>
>>60038815
I can? What, like this?
void* pFun = [](){};
(reinterpret_cast<void(*)()>(pFun))();
>>
>>60038952
You don't need to set end_comment every iteration. In fact I think you can do with only one bool that gets set true at '#' and false at '\n'
>>
>>60038906
Weird. You're really, really sure it's the printf and not the malloc that fucks up? And the program you ran and got the error from does what, just
init(5); 
and then exit? I don't see any bug in what you posted, except init lacks a
return pa; 
>>
>>60038952
Also I think the standard form is
while ((c = getchar() != EOF)
>>
>>60039008
>>60039053
Thanks
>>
>>60037714
maybe he knows ur a weeb
>>
>>60037123
On my free time I try implementing a generic AI, aka human like in C++. I know it probably won't work, but at least doing the headers is fun.
>>
>>60039276
>doing the headers is fun.
Gr8 b8 m8 I r8 it 8/8
>>
This program should find differences between two files, writing to stdout every offset in hex.

while ( !ram1.eof() || !ram2.eof()) {
ram1.read( (char*)&val1, sizeof(uint8_t));
ram2.read( (char*)&val2, sizeof(uint8_t));
if (val1 != val2) {
res << hex << ram1.tellg() << endl;
}

}


But, those offset aren't right.
Just.. why?
>>
>>60039308
Was not a bait.
When you do the headers you are basically defining the API. It forces you to think of how everything should work and gives you a better idea of the final result (without actually implementing anything). So it's great. Not so great of course if you do it the other way arround (write first the implementation and then put together an API)
>>
>>60039424
There's some commercial AI library for AAA games.

It has a Brain type, AFAIK.
>>
>>60039367
Assuming the coding works (looks fine to me), it may be:
1. You are not having into account non printable characters (\n, \t, etc...)
2. You are not using an encode of fixed 8-bit size. Maybe you're using utf8 or some variant? Are you printing non latin characters?
>>
>>60038906
works for me if I just call init(3) in main
even works for init(0)
>>
File: Hask IO.png (294KB, 960x800px) Image search: [Google]
Hask IO.png
294KB, 960x800px
>2018
>now writing you're code by proving it correct

Definition swap (vars : byte * byte) :=
let '(x, y) := vars in
let x := xor x y in
let y := xor y x in
let x := xor x y in
(x, y).

Theorem swap_correct : forall x y, swap (x, y) = (y, x).
Proof.
intros; unfold swap.
rewrite (xor_commut y (xor x y)), xor_assoc.
rewrite xor_nilpotent, xor_false_l.
rewrite <- xor_assoc, xor_nilpotent, xor_false_r.
reflexivity.
Qed.
>>
It's a binary file open in binary mode.
>>
>>60039543
now prove OpenBSD's ifconfig
>>
>>60038996
yes, something like that
I can't be assed to recall the precise syntax
also remember you can do it manually by hand with inline asm
>>
>>60039566
Forgot to quote
>>60039520
>>
File: analBeedSort.png (14KB, 661x250px) Image search: [Google]
analBeedSort.png
14KB, 661x250px
Hey looking for a Java friend again.
I'm currently sorting my ArrayList<Object> by Zone ( char ) alphabetically
and I'm wondering if I can sort by Location ( String ) like a second preference.

Current compareTo() Method :

    @Override
public int compareTo(CarSpace other)
{

if (this.spaceZone < other.getZone())
{
return -1;
} else if (this.spaceZone > other.getZone())
{
return 1;
} else
{
return 0;
}

}



Pic related is the output and the in red is the Location field.
>>
>>60039572
>implying you can
OpenBSD is fundamentally broken. You can't prove incorrect code.
>>
File: what eee.jpg (112KB, 931x694px) Image search: [Google]
what eee.jpg
112KB, 931x694px
>>60039543
>comments out 90% of his code
>>
>>60039424
Doing the api first makes a lot of sense, especially in tdd, but are you saying you have any idea what the api of a human-like ai should look like? Sounds like masturbation to me. Besides, C++'s requirement of header files are a pain in the ass of every programmers, and you can write unimplemented apis without them, so how can you enjoy it?
>>
Years ago, I came here to tell everyone that I was training neural networks on forex data.
Everyone was absolutely right, I was overtraining on the data and overconfident.
I also didn't have any entry or exit strategy, I didn't normalize for volume, and I didn't have a timeframe switching strategy yet.
I've had a lot more experience in my software career since then. I'm working on it again, but I will not prematurely post results without a reality check until I have a solid automated system.
>>
>>60039534
unrelated, but what do the 3 and 0 mean?
>>
>>60039588
elaborate
>>
>>60039585
you mean if the spaceZone is equal sort by location?
just do the same if else if else with the location whenever this.zone==other.zone
>>
what is the best anime to watch to improve my programming abilities

besides serial experiments lain
>>
"Do I cast the result of malloc?" has got to be one of the most linked questions on stack overflow
>>
>>60039622
Look up seL4, Cogent, BiblyFS
>>
>>60039637
Lain is the only good anime.
>>
File: 1492893423406.jpg (208KB, 1036x1536px) Image search: [Google]
1492893423406.jpg
208KB, 1036x1536px
>>60039629
Of course; thanks so much, I'm over thinking it again. Please disregard my question. :^)
>>
>>60039620
?
they're the argument to the other anons init function which I think allocates an array of points
He said that something was wrong when he set n to 3 but it seems to work so the bug is somewhere else
>>
>>60039637
>obligatory homosexual anime recommendation
>>
>>60039589
>not commenting your code
Perl """"programmer""" dtected
>>
>>60037123
I keep disassembling things lately. not sure why. it's a fun learning exercise I guess.
pic related, a gigabit ethernet card driver for 16-bit MS-DOS.
>>
>>60039597
>but are you saying you have any idea what the api of a human-like ai should look like?
I have an idea of a human-like api that I think could work, nothing more than that. And it's not complete either, but I keep working on that.

>Besides, C++'s requirement of header files are a pain in the ass of every programmers
I somehow got used to them to the point that now I like them. I see them as the API definition & documentation of a project. But of course they take time to code, if I where time constricted I would not enjoy making them so much.
>>
>>60039711
wow it's beautiful
>>
>>60039687
Neat. I've seen man pages like error(3) and never knew what the number meant.
>>
File: e1000.png (139KB, 1920x1387px) Image search: [Google]
e1000.png
139KB, 1920x1387px
>>60039711
forgot related pic
>>60039722
thank you
>>
File: funni_horsee.png (323KB, 315x665px) Image search: [Google]
funni_horsee.png
323KB, 315x665px
>>60039704
>commenting your code for "readability"
Reddit pajeet confirmed
>>
>>60039695
how can an anime be homosexual?
>>
why doesn't it work? substring can't contain any repeating characters. it just returns the length of the string
class Solution(object):
def lengthOfLongestSubstring(self, s):
maxlen = 0
slen = len(s)
if slen < 2: return slen
seen = {}
for i in range(slen):
j = i
seen.clear()
while j < slen and not s[j] in seen:
seen[s[j]] = 1
j += 1
if j > maxlen: maxlen = j - i
return maxlen
>>
>>60039735
>reddit
>pajeet
wow my filter got your post twice!
nice!
>>
>>60039566
Hmm care to post what output you're getting?
>>
>>60039729
ah for man pages it means the section number of the man page
see man(1)
the 1 means it's an executable or a shell command
it there was a System call named man it's manpage would be man(2)
>>
File: aika_grin.png (17KB, 500x500px) Image search: [Google]
aika_grin.png
17KB, 500x500px
>>60039637
Aria.
>>
>>60039758
So how are you reading his comment?
>>
>>60039729
That's not the same thing.

The number is the section that the command comes from so that:
1) You can find it easier
2) You can have the same command name repeated in different sections, probably doing similar but slightly different things

MANUAL SECTIONS
The standard sections of the manual include:

1 User Commands
2 System Calls
3 C Library Functions
4 Devices and Special Files
5 File Formats and Conventions
6 Games et. al.
7 Miscellanea
8 System Administration tools and Daemons
>>
>>60039637
Battle Programmer Shirase
>>
>>60039772
I get some offsets, I put them in HxD for comparison and they're wrong, there are a lot of bytes which differ before that.
>>
I'm learning C but I don't know what I'd do with that information. What would I even program? what do you people even program?
>>
File: nse003_001.jpg (195KB, 728x1161px) Image search: [Google]
nse003_001.jpg
195KB, 728x1161px
>>60039637
SE. (Systems Engineer)
Perfect balance between Story, Art, Huge tits, Programming and Drama.
All rather realistic.

Unfortunately way too short.
>>
>>60039789
I obviously unfiltered his post to read it :^)
>>
>>60039867
he likes a middle school girl?
>>
>>60039830
Well to debug it, I would do the following:
1. Test that comparing the same file produces no output.
2. Test that comparing the same file with 1 byte off produces 1 hex number as output, and check that the hex -> decimal corresponds to the position of the diference.

If you're trying to make a binary diff, that's not the way to go though, just to warn you.
>>
>>60039543
You could have proved a more general thing. You need abelian (op (a, b) = op (b, a)),
nilpotence and assoc.
Rewrite it please.
>>
>>60039896
>If you're trying to make a binary diff, that's not the way to go though, just to warn you.

How should I do it, then? Loading the entire file in an array?
>>
>>60039891
who doesn't
>>
>>60039641
Very interesting. My point in citing OpenBSD's ifconfig was that software proofs weren't applicable to "regular" software, and in that regard I believe I'm still right. But the Cogent workflow for software correctness is quite interesting, even if it has only been proven in a microkernel and incomplete filesystem. Additionally there are performance drawbacks. No matter how much of a "mess" you say OpenBSD is, it's in actual use today
>>
>>60039750
can someone please eyeball this? it's not fancy
>>
>>60039750
seen is just filled with ones
you need to put s[j] in there
>>
>>60039891
a middle school girl who is president of a company which develops sex sleeves
>>
hello im autistic can someone please help

 test4time://logincallback#access_token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI1MlFYN0IiLCJhdWQiOiIyMjg0TEwiLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4iLCJzY29wZXMiOiJ3aHIgd251dCB3cHJvIHdzbGUgd3dlaSB3c2V0IHdhY3Qgd2xvYyIsImV4cCI6MTQ5MzAwMDM0MSwiaWF0IjoxNDkyOTgyMDI2fQ.QfHZm87xGcgtGkSPvr8vrG4NJpNdK8v96IHQObKuQ7s&user_id=52QX7B&scope=sleep+settings+nutrition+activity+heartrate+profile+weight+location&token_type=Bearer&expires_in=18315 


i need the token between access_token= and &user_id, the token varies in size so im not sure how to parse it out of that string

doing it in java/android if anyone knows an easy way. i know i can make a new function to do it but im sure theres a way to do it with indexOf() i just cant think of it cuz im autistic and dumb
>>
>>60039918
If the file is not huge (say > 30MB), yes.
It depends on exactly what you want to do, for example:

If you have ABCD[200xD]E and ACD[200xD]EB, your output will be 1,2,3,4,5...202, instead of what you probably want: 1(-1).
>>
>>60040067
1. get position of the last character in "access_token="
2. get position of the first character in "&user_id"
3. subtract to get the length
4. you have the starting position from (1)
problem solved?
>>
>>60040057
i want the key to be the letter, and the value to not matter. checking s[j] in seen should be checking if s[j] is a key that exists in the dictionary unless i'm understanding this wrong https://docs.python.org/2/tutorial/datastructures.html

i'm basically trying to use it as a hashmap whose values are just booleans (not even full booleans, since it's uninitialized)
>>
>>60040069
Rewritten everything in C.
int main() {
FILE *ram1;
FILE *ram2;
FILE *result;
ram1 = fopen ("ruby1", "rb");
ram2 = fopen ("ruby2", "rb");
result = fopen("diffs1_2.txt", "w");
unsigned char buf1, buf2;
while (!feof(ram1)) {
buf1 = fread(&buf1, 1, 1, ram1);
buf2 = fread(&buf2, 1, 1, ram2);
if (buf1 != buf2) {
fprintf(result,"%X\n", ftell(ram1));
}
}

fclose(ram1);
fclose(ram2);
fclose(result);
}


Now doesn't anything, what am I doing wrong?
>>
>>60039750
this approach isn't going to work without a second loop or a cleverer algorithm
>>
File: 1490691259603.jpg (151KB, 1189x780px) Image search: [Google]
1490691259603.jpg
151KB, 1189x780px
>Variable arg count functions (...) can access their args with built-in variables similar to 'this' in C++. They are 'I64 argc' and 'I64 argv[]'.
MUH
>>
>>60039711
>>60039734
goddamnit I am so stupid.
said driver is open-source already so I'm completely wasting my time here.
>>
>>60040157
Jesus Christ, found the error.
>>
why hasnt anyone invented a programming language yet thats basically JAVA but does all the annoying stuff automatically for you?
>>
>>60040159
it has 2 loops though. it's O(n^2). like i said i'm not trying to be fancy
>>
>>60037166
Any tallking points to support your thesis?
>>
>>60040120
oh right forgot how dicts worked there
it's actually the last if, you need to check if j-i > maxlen, otherwise I always got 1
>>
>>60040313
fuck i knew it was something stupid like that. i fixed it on the right half of that line you can see but i forgot the other one. thanks!
>>
Anybody here wanna experiment with older men?
I'm 19, I think finding oneself is the key to be a better programmer.
Although I'm chubby, I got to lose weight to maximize pool of older men and to maximize sexual attraction.
>>
>>60040313
>calling hashes dicts
>>
>>60040431
>calling association lists hashes
>>
>>60040431
python also calls arrays lists
>>60039750
can someone explain to me the "sliding window" approach to do this in O(n)? reading about it and i don't really understand. this solution (after fixing it) was good enough to not time out with O(n^2) but i want to understand the most optimal way too
>>
>>60040392
do you have a plump girly butt?
>>
>>60040484
I have a big butt, thanks to my african heritage.
>>
>>60040450
>calling property lists association lists
>>
>>60040503
are you nigger?
>>
>>60040512
define nigger
>>
Whoever thought multiple inheritance was a good idea.
Take it from Java and have single inheritance with interfaces.
It turns out, this model is much better since it protects the programmer.
>>
>>60040157
>buf1 = fread(&buf1
fread returns the amount of bytes read.
>>
>>60040512
/g/ the place where asking for skin color is more important than asking for gender.
>>
>>60040586
Yeach, corrected that. Now I get some runtime obscure error.
>>
>>60040392
before you do that, get beads from the sexual liberation company, they're giving away free beads, all you have to pay for is shipping
better experiment whether you like that stuff
>>
>>60040472
nvm i get it now. you have a low index and high index on the window, starts out L = H = 1. then, you slide H to the right until you hit something that's already in the set. then you slide L to the right until the set is valid again (doesn't contain the character at index H) and once it's valid, you start sliding H to the right again
>>
>>60040605
True. Gotta make sure he's a cute boy before we worry about whether he's a nigger or not.
>>
>>60040541
are you a black man?
>>60040605
kek
>>
>>60040392
Just kill yourself, watching BBT or some "nerdy" tv series doesn't make you a programmer.
>>
>>60039574
>also remember you can do it manually by hand with inline asm
That's way beyond me.
>>
>>60040635
You could say that at first sight.
>>60040640
I never mentioned tv series.
>>
>>60040669
You watch them anyway, women love tv series because they're both degenerate scum.
I hope Islam will stone you to death.
>>
>>60037926
Using macros is fine, just make sure to undefine them when you're done. I even used them like this:
    #define Idea2 std::pair<Idea*, Idea*>
lnk_op<Idea*> gen = lnk_op<Idea*>(this); //A is generalization of B
lnk_op<Idea*> elm = lnk_op<Idea*>(this); //A is element of B
lnk_op<Idea*> syn = lnk_op<Idea*>(this); //A is a synonim for B
lnk_op<Idea*> rel = lnk_op<Idea*>(this); //A has a relation to B
lnk_op<Idea2> cmp = lnk_op<Idea2>(this); //A is B compared to C
lnk_op<Idea2> act = lnk_op<Idea2>(this); //A is doing C in time B
#undef Idea2
>>
>>60040230
What's the annoying stuff?
>>
So linux advocates for open source software so programmers can use source code from any program and update it in any fashion they want. Sounds nice and all but a lot of innovation is driven out of the wanting to capitalize, right? Wouldn't this system impede on innovation because a lot of people don't want to create if they can't make money off of it? I know open source doesn't mean free as in free beer or whatever the saying states, but never the less this system impedes on innovation period. Or am I wrong? Why can't programmers protect their intellectual property?
>>
>>60040669
>You could say that at first sight.
well sorry for leading you on, you can hit me up when you become white tho
>>
>>60040702
Why even use a macro if you can just:
using Idea2 = std::pair<Idea *, Idea *>;
>>
>>60040691
But Silicon Valley is fun to watch.
Islam won't touch me in me lifetime anyways.
>>
>>60040723
I'm white in my heart.
My father is white.
>>
>>60040738
light skin or dark skin?
>>
>>60040730
Well you got me there.
But also, I don't want to have Idea2 on the global scope, in fact I don't want to have Idea2 declared at all, I just wanted to use that on those 6 lines of code, to make all them look nicely spaced.
>>
>>60040749
Doesn't matter as both stamp me as a nigger.
>>
>>60040608
What error?
>>
>>60040770
Well it would be bound to the scope of the function that initializes those variables, unless you do that in the global scope in which case I guess you're right.
>>
>>60040774
true
>>
>>60040714
>another dumbshit ancap trying to discuss big boy politics
>"hurr durr money is literally humans' only motivating factor"
>not knowing companies explicitly inhibit progress because it makes them money

This discussion has happened to death on other places more suited to it. Fuck outta here.
>>
>>60040714
every innovation comes from academia world where people do it because autism

big business tricked the whole world into thinking they """research""" andor """innovate"""
>>
Ok my negroes, tell me about the worst annoying shit problem you've ever faced at work
>>
Are switches ever used too often? I feel like I use them a lot in c# when I'm doing input validation or assigning multiple handlers to the same control. I feel like that's bad practice though
>>
File: 1490591570507.png (170KB, 480x480px) Image search: [Google]
1490591570507.png
170KB, 480x480px
>>60040878
>at work
>>
Writing a web mapping app in Java for hw. Why is this language so dog shit? Are there any actual benefits to using it other than interoperability with the existing code base of dog shit that was written in it in the last 20 or so years?
>>
>>60040882
Yes, zealots will say its better to have a map of event ID -> handler. Been there, done that. I didn't feel satisfied with the change.
The switch is not bad for event handling and actually is faster and consumes less memory than the map approach.
If you had a lot of cases then you should start to worry.
>>
>>60040990
If you don't have a lot of cases, why not elseif?
>>
File: import PIC functions.png (3KB, 151x60px) Image search: [Google]
import PIC functions.png
3KB, 151x60px
Any more important PIC functions?
>>
>>60040702
#ifdef FOO
#error Macro pollution!
#endif
#define FOO <some expression>
<do stuff>
#undef FOO


I hate macros.
>>
>>60041064
Switch is shorter because the name of the variable has to be written just once instead of once per if clause. But otherwise its pretty much the same thing.
>>
Going to make an automated watering/lighting system for some hanging plants and turn them into a "living curtain" for my rooms windows when this semester is over.

If I put the finished code on GitHub will employers be impressed and hire me for once?
>>
>>60041206
If the macro already exists the compiler would print the error anyway. As long as people that makes macros take care of undefining them it's fine. They usually don't though.
>>
>>60040807
>>"hurr durr money is literally humans' only motivating factor"

it is.
>>
have an intro in arm64 assembly
.text
.globl _start
_start:
ldr w1, uart #serial putput address to w1
ldr w2, =message #address of string to w2
//load byte into w3, increment message, print, repeat
b loop

loop:
ldrb w3,[x2] #load byte from the address in w2 to w3 reg
strb w3,[x1] #store byte from w3 reg to serial out addr
cbz w3, finish #if the byte in w3 is zero ('\0') go to finish
add w2,w2,1 #add 1 to the string address to get to the next char
b loop #repeat

finish:
mov w3, '\n' #put newline in w3 reg
strb w3,[x1] #put newline from w3 reg to address in x1 (serial output)
b .

uart: .int 0x09000000
message: .asciz "niggers tongue my anus"
test: .asciz "lol is it kill" #test to see if printing goes beyond \0
>>
>>60041376

Money
Influence
Love
Lust
Revenge

We have plenty of motivating factors.
>>
I need your help, /dpt/.

I began studying Java, and I stumbled upon a dumb exercise I can't get done.

>Ask the user to input 4 numbers
Okay.
>Then calculate the "average" of them
Okay.
>Using a For statement
Fuck.

I can't figure out how to accomplish that calculation using For statement, I can get it done through other means but I'm required to do it that way.

Any help would be greatly appreciated.
>>
File: jewdas.png (198KB, 520x388px) Image search: [Google]
jewdas.png
198KB, 520x388px
>>60041376
Stupid materialist
>>
>>60041419
You forgot "mastery" my dude, people really like gitting gud

Not surprising for a Ruby /dpt/ tripfag, but still
>>
>>60041426
This isn't really a programming problem; it's a math one.
>>>/sci/
>>
>>60041419

Basically all money equivalents. You get money so that you can do the others, and if you have more money, you are more capable of doing the others.

>>60041428

See my response to the above.
>>
>>60041459
See my response above >>60041428
>>
>>60041439

That is indeed a motivating factor, but most people are a bit more vain.
>>
>>60041375
>If the macro already exists the compiler would print the error anyway.
Not so.
>>
>>60041451
The calc itself isn't hard, achieving it through a For statement is what I'm clueless about
>>
>>60041426
for (i = 0; i < n; i++)
sum += a[i];

sum /= n;
?
>>
>>60041476
So you can save each entry from the user into an array then use the for loop to go through the array and add them to an int. Or you can use the loop to prompt the user for an entry 4 times that gets added to the same int each time
>>
>>60041459
>Basically all money equivalents.
Shut the fuck up Austin.
>>
>>60040822
Do you unironically believe this? If so can you provide a more in depth argument for your claim?
>>
Got directed here from /sqt/, but I'm wondering how to search for a certain char or letter in an array. This is for a project which is based off pointers and if anyone has an answer which implements pointers then thanks.
And I already tried Google btw.
>>
>>60041531
Your problem is hilariously trivial and easy.
>>>/sqt/
>>
>>60041465

nod an argubend

>>60041507

No u!
>>
>>60041531
Iterate over the array.
>>
>>60041560
Why do you want to irritate the irate?
>>
When writing C programs what's wrong with malloc-ing a huge area of memory and using that for everything?
>>
>>60041591
What made you think it's wrong? It's a baby step towards efficient memory usage
>>
>>60041591

That's an existing technique.
>>
>>60041591
Can fail if there is not enough contiguous memory available. Might make the code a little more complex, depending on your design.
Otherwise it's a good idea. It's called a memory pool.
>>
Whats a good framework for developing guis?
I was thinking of using
https://github.com/PistonDevelopers/conrod/

so that I could make a small disk visualizer.
>>
File: sad-frog.png (186KB, 936x590px) Image search: [Google]
sad-frog.png
186KB, 936x590px
guys becoming a programmer is actually super hard why do people try to make it look like a trivial task
>>
>>60041823
>frogposter
>too dumb to program

no surprises there
>>
>>60041823
Don't say that, I'm just now trying to become a developer. I'm fine with making dumb shit though as log as I get paid over 50k a year
>>
>>60041823
>Frogposter
You will never amount to anything.
>>
>>60041823
most people here are still on the same level as you.
>>
How do I do FPS-lookaround in WebGL and Javascript?
The problem is that first-person games allow indefinite turning, without screen borders being a concern, but in-browser the cursor can only move so far left or right.
>>
What programming languages have the strongest type systems?
>>
>>60041722
anybody?
>>
>>60041943
Do some searching.
https://gamedev.stackexchange.com/questions/9105/how-to-implement-mouselook-in-the-browser
>>
>>60041966
any FPL with dependent types.
>>
>>60041966
Agda, Coq
>>
>>60041898
by that logic you must be spamming all boards with apu 24/7 anon
>>
>>60041877
>I'm fine with making dumb shit though as log as I get paid over 50k a year
Don't go to /dpt/ then.
>>
>>60042031
because you are all losers or way above that? kek do I need to ask?

I need to stop coming to 4chan at all
>>
File: Doesn't seem complete.png (34KB, 513x576px) Image search: [Google]
Doesn't seem complete.png
34KB, 513x576px
>>60041974
If they can't even make their github presentable how do you think your application will look.
>>
>>60041722
>https://github.com/PistonDevelopers/conrod/
use Qt
>>
File: 1483394314324.png (358KB, 498x680px) Image search: [Google]
1483394314324.png
358KB, 498x680px
>>60041823
>>
>>60042054
Anon you sound really poor. Most people who do programming on their spare time (which /dpt/ clearly is about) have a passion for it. That's why you don't belong.
Earning that meager sum is not difficult, I'm absolutely confident you will achieve it. But don't clutter this place.
>>
>>60041823
dumb pajeets that can't even figure out how to use a toilet can do it, so can you.
>>
>>60042093
>>>facebook
>>
>>60037488
lambda?
>>
>>60042101
I love how exclusionary some people on /g/ can be. 50k is a good starting salary in my area. Every hobby has to start somewhere anyways
>>
>>60042089
why use qt?
>>
>>60042141
you should suck some dicks for a living instead anon, i bet you'd be better at it too
>>
>>60042174
>tells me I dont belong and not to "clutter" the general

>clutters the general
>>
>>60042189
thats a diff dude anon
my advice still stands btw
>>
>>60039888
Filters once again proven stupid and pointless.
Grow up faggot, and face the real world.
>>
>>60042200
ill work to develop the first 2d anime dick sucking app available exclusively on windows phones then Ill be good enough for you
>>
https://hackage.haskell.org/package/iteratee
https://hackage.haskell.org/package/conduit
https://hackage.haskell.org/package/pipes
https://hackage.haskell.org/package/machines

Has pure FP IO gone too far?
>>
>>60042236
>ill work to develop the first 2d anime dick sucking app available exclusively on windows phones then Ill be good enough for you
nah, you're gonna put on panties and suck my dick to become good enough 4 me anon
>>
>>60041991
Right. I'm just trying to build up a list to take a closer look at.
Haskell
OCaml
Coq implements a dependently typed functional programming language,[3] while seen as a logical system, it implements a higher-order type theory.
Mercury is a functional logic programming language. It features a strong, static, polymorphic type system, and a strong mode and determinism system. It can be viewed as a pure subset of Prolog with strong types
Caledon is a dependently typed, polymorphic, higher order logic programming language
Clean is a general-purpose purely functional computer programming language. It shares many properties with Haskell

https://en.wikipedia.org/wiki/Comparison_of_type_systems
https://en.wikipedia.org/wiki/Comparison_of_programming_languages_by_type_system

>>60042023
Havent heard of that one yet thanks.
Agda is a dependently typed functional programming
>>
>>60041168
Your prefix is too rapey and it's triggering me.
>>
>>60042317
holy shit go back to tumblr
>>
So what are you currently working on /dpt/?
>>
>>60042484
finals coming up so not much right in the moment. doing the projects for chapter 1 of art of assembly programming. the version i have is the free pdf you can get online, thinking about buying the book though. the book says it's structured where you get right into assembly programming in chapter 1
>>
>>60042505
x86 im guessing?
>>
>>60042523
ye
>>
Greetings, /dpt/. I've looked everywhere but I'm stuck on how to fill this char array. It's malloc'd as an array of character pointers, so as to be able to hold a string (without including string.h).
intptr[0] = "This is a string"; throws an invalid pointer error and
**intptr = "This is a string."; crashes it.
doesn't seem to work.
#include <stdio.h>
#include <stdlib.h>

int main (void) {
char **intptr;
intptr = malloc(sizeof(char*) * 0);
//fill the array in here
intptr = realloc(*intptr, sizeof(char*) * 1);
printf("Your input: %s \n", intptr);
return 0;
}
>>
>>60042566
>intptr = malloc(sizeof(char*) * 0);
what's 0 * the size of a char pointer
>>
>>60042566

what are you even trying to do dude
>>
>>60042592
I multiplied it by 0 to make it empty. I only allot it space for 1 char ptr once it's been filled.

>>60042601
Eventually going to accept some input, and after I've determined it's not an int, double, or single char (which works just fine already), it defaults to treating it as a string and allocating memory for multiple chars aka a string.
>>
>>60042647
Meanwhile in a sane language with string literals.
>>
Okay /dpt/, I wrote a genetic algorithm to generate programs for a slightly modified version of brainfuck. The problem is I have no idea what types of programs I should select for.

I've already generated a program which produces the Fibonacci sequence, approximates e^x, and other simple functions.
>>
File: 1477255349332.png (208KB, 395x375px) Image search: [Google]
1477255349332.png
208KB, 395x375px
>>60042647
>I multiplied it by 0 to make it empty.
you're allocating 0 bytes of memory
>>
>>60042451
>Being baited this easily
>>
File: interrupts your path.png (250KB, 1919x1046px) Image search: [Google]
interrupts your path.png
250KB, 1919x1046px
>>60042484
>>60042317
I'm glad to know that RAPIC's interupts work.
On a sidenote, since I didn't load the interrupt table, it used program code as an address, which then jumped in device registers, which just happened to contain a jump to an out of memory address. We did it, /g/. We stopped polling.
>>
>>60042657
That's pretty cool anon. Post some examples.
>>
File: multiplied by 0.png (20KB, 668x348px) Image search: [Google]
multiplied by 0.png
20KB, 668x348px
>>60042681
/g/ hall of fame
>>
File: 1492996129458.png (38KB, 668x348px) Image search: [Google]
1492996129458.png
38KB, 668x348px
>>60042740
>>
File: 1469663567025.jpg (28KB, 455x348px) Image search: [Google]
1469663567025.jpg
28KB, 455x348px
>I multiplied it by 0 to make it empty.
I lost IQ points reading this
>>
This is your brain on the C menace, /dpt/.
>>
>>60042647
>I multiplied it by 0 to make it empty.
>>
>>60042727
Here's the Fibonacci sequence:
-m,n]>>,[>-+[-+>>]],<+n]<<+-][

You can see it's modified as I don't really enforce the rule that there must be a closing bracket for each start one (it just jumps to any corresponding bracket). The main instructions (+ - < >) do the same as in normal brainfuck.

The added ones:
n stores value of the current cell to a variable
m sets that variable to zero
, sets the value of current cell to the variable
>>
>>60042813
No, this is just a beginner being retarded.
He would've been retarded in any language.
>>
File: 1492032765232.jpg (46KB, 429x429px) Image search: [Google]
1492032765232.jpg
46KB, 429x429px
Newfag here. Someone please explain to me how to learn how to program. I've got zero experience and like to start learning now.
>>
>>60042830
>Not standard brainfuck
Well shit, I can't put it through my brainfuck compiler.
Well it should be trivial to modify it anyway.
>>
>>60042867
read K&R so you don't end up like the sadcase above
>>
>>60042867
my_string = "hello world"
print my_string
>>
>>60042867
eat a book
>>
>>60042891
You forgot to multiply by 0.
>>
>>60042867
A V O I D 
the c meme.
https://www.tutorialspoint.com/pascal/
>>
>>60040067
>60040067
Make a string array which splits the line based on the & symbol, disregard what you don't need.
>>
>>60042867
dumb frogposter
>>
>>60042867
No matter what you do, AVOID PASCAL
Learn Rust.
>>
>people picking on a beginner to feel better about their incompetence
damn, so low /g/
>>
>>60042874
Yeah, those added commands make it so I don't have to leave my computer on all night to get an even slightly complex program
>>
>>60042867
actually if you're >>60042566 ignore >>60042889
and go to http://www.learnpython.org/en/Hello%2C_World%21
>>
>>60042566
I don't think you're a good match for C.
>>
>>60042944
nerds need to do that to live

it's not /g/ exclusive phenomenon by any means
>>
>>60042944
If you are a beginner, you are getting picked on. It is that simple. Be it on /v/, /fit/, /tg/ or even /a/
>>
>>60042944
my programming teacher calls us "fucking retards" when we do dumb stuff
>>
>>60042944
>>60043012
I don't normally do this. I don't even derrive pleasure from it.
It's just he's exceptionally poor at this. Definitively the worst I've seen.

I can't even understand how you arrive at that code as a rookie. Why is that realloc there?
>>60042867
Start some structured learning. Read a book, follow a tutorial. Anything. Make sure you understand what's being said. If you don't ask questions (here in /dpt/ is fine).
>>
>>60043046
does he browse /g/?
>>
>>60042947
If you don't mind, can you briefly summarize how you handle fitness testing, selection, cross over, and mutation? and how is each brainfuck program encoded in genes?
Population size? mutation rate?

I'm also interested in writing genetic algorithms, but I'm pretty new to it.
>>
I see you've gone almost an entire thread without talking about Jai. I just wanted to let you all know, God is really disappointed in you.
>>
>>60043156
Fitness testing is fairly straightforward. I give the fitness function the array created by the brainfuck program and say something like:
if (array[i] == i*i) fitness++;
The fitness of this one program is then fitness/array.length. You can use the same technique for stuff like fibonacci and other functions you want approximated.

Selection can be done in various ways, but I use a Cellular Evolutionary Algorithm to keep some diversity in the population (and also to visualize competing solutions, it looks cool). I select the highest fitness individual from the neighborhood of a single solution and simply mix the genomes 50/50.
The genes are strings making up the program. An array of strings, basically.

All the other things you mentioned are just parameters so I can mess around and see what works best. There is no one good population size or mutation rate. You just have to tune it for what you want.
>>
Programming is extremely easy. Just map the decision procedure of a problem into the class of types and endow it with a homotopy theory such that logical inferences correspond to continuous maps on types and project the decision procedure into the quotient space of types under the identification of decision procedures that take and return the same type and then you construct a representation of the transitive action of the affine semisimple Lie group of symmetries on the lattice of the space of types and you endow the Lie algebra with a left-invariant Haar measure such that you can integrate the action of the symmetry group over the path defined by the projection of the original decision procedure which will give you the energy functional of your algorithm and then you use variational calculus to minimize this functional.
>>
>>60043304
Is this how we originally discovered fizzbuzz?
>>
>>60043304
This. Is there a more efficient way?
>>
File: acton.png (90KB, 780x402px) Image search: [Google]
acton.png
90KB, 780x402px
>>60043304
>>
trying to compact a date into 16 bits but it's not working
>>> from ch1progs import *
>>> ToDate(11, 29, 1995)
0
>>> bin((11 << 12) | (29 << 7) | (1995 % 100))
'0b1011111011011111'
>>>


here's my code
def ToDate(m, d, y): return (m << 12) | (d << 7) | (y % 100)
>>
>>60043344
#define DAY(x)    (((x) >> 11) & 0x1F)
#define HOUR(x) (((x) >> 6) & 0x1F)
#define MINUTE(x) ((x) & 0x3F)
#define TIMESTAMP(d, h, m) ((((d) & 0x1F) << 11) | (((h) & 0x1F) << 6) | ((m) & 0x3F)
>>
>>60043419
can you tell me why my way is returning 0 though? i do the same thing without the function in the repl and it returns the correct value
>>

>>> from ch1progs import *
>>> ToDate(11, 19, 1995)
0
>>> def td(m, d, y): return (m << 12) | (d << 7) | (y % 100)
...
>>> td(11,19,1995)
47583

##### ToDate's definition in the source file
def ToDate(m, d, y): return (m << 12) | (d << 7) | (y % 100)


this doesn't make any sense
>>
>>60043339
that was a good talk
>>
File: 1466132106005.png (34KB, 532x108px) Image search: [Google]
1466132106005.png
34KB, 532x108px
*blocks your path*
>>
>>60043344
type Month is range 1..12;
type Day is range 1..31;
type year is 0 .. 99;
type Date is record
M : Month;
D : Day;
Y : Year;
end record with Pack;
--;^)
>>
>>60043767
*unlocks path"
>>
>>60043344
>>> def ToDate(m, d, y):
... return (m << 12) | (d << 7) | (y % 100)
...
>>> bin(ToDate(11, 29, 1995))
'0b1011111011011111'
>>>


Works fine. You must be fucking up the import
>>
>>60043778
;^)
>>
>>60043790
how? look at >>60043732
>>
>>60043808
Like I said, you're fucking up the import somehow
>>
>>60043767
*gets put on a waiting list and is never woken up*
>>
>>60043790
restarting the python shell made it work but i still don't know why. i repeated the import command after i had the latest version in the file
>>
>>60043827
I wish that would happen to me
>>
>>60043835
Trying to import the same file more than once in a session will result in the interpreter not doing anything and continuing to use the one already loaded
>>
>ywn hang out with cool harvard/mit autists and discuss advanced algorithm problems with them
feels bad
>>
>>60043860
ahh i gotcha. any better way than restarting the shell?
>>
File: 1461719056620.jpg (32KB, 500x500px) Image search: [Google]
1461719056620.jpg
32KB, 500x500px
>>60043933
Yeah, but you get to hang out with a bunch of losers and tripfags who'd rather shitpost about languages instead of actually programming! Isn't that better, anon?
>>
>>60044097
Don't program in the shell and just make your own .py files?
>>
First for Python
>>
first for java
>>
>>60044405
>>60044417
Python and Java being slow as usual.
>>
>>60044423
upvoted
>>
>>60044433
Thanks
>>
>>60044440
You're welcome
>>
>>60044423
1.0000000000000002th for JavaScript
>>
What license should I use for homework assignments?
>>
File: captcha.png (295KB, 400x580px) Image search: [Google]
captcha.png
295KB, 400x580px
>>60044444
My captcha
>>
File: 1476980587254.jpg (398KB, 1280x720px) Image search: [Google]
1476980587254.jpg
398KB, 1280x720px
>>60044450
ehehe~
>>
>>60044392
kys?
>>
>>60044469
GPL3
>>
how can i remove all occurrences of '0x' from a string using python? e.g. if it was 0abx i'd want 0abx, but if it was 0xab i'd want ab
>>
>>60044485
Is that the one where if you even read it, all future work you ever do must be public domain?
>>
>>60044504
Yes.
>>
New thread:

>>60044514
>>60044514
>>60044514
>>
 
//wordL drop the last word, wordR drop the first word
val wordL = lines.flatMap(line => line.split(" ").dropRight(1))
val wordR = lines.flatMap(line => line.split(" ").drop(1))

//pair the two adjacent words with 'zip' method
val pairWord = wordL zip wordR

//val printList = pairList.zipWithIndex.map{case(k,v) => (k,1)}
val pairMapper = pairWord.map(word => (word,1))
val pairReducer = pairMapper.reduceByKey( (x,y) => x+y )




Scala code that produces a RDD of [(String,String),int]

The touple has a word and the word following it and the int is the count of the preceding word.

I'm wondering how I split the touple.
Thread posts: 317
Thread images: 35


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