/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

First for Lisp is the weakest programming language.

seconded

Thank for the /dpt/ related picture.

DONALD RULEZ

t. /r/the_donald

Do you shower everyday /dpt/?

I don't and feels like it't throttling my programming capabilities

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

sometimes twice a day

Have two buffers, when you're writing one to disk when it's full you can fill the other up.

Help, I need to come up with a 256 color default palette for RGA.

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?

Whom quotes?

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;

}
}

>locally defined functions
Why would you want to?

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.

Tighter scope

No

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?

>Tighter scope
Use multiple compilation units and static functions, or just shrug it off; who cares if it doesn't affect anything?

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.

For the same reasons you use namespaces

Which is? Symbol collision? I suggested the static modifier against that.

I can't read this horrible code "style". Pull it out of the loo.

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.

It's better to store the function in a scope where it's used. Having it be beyond that is bad design.

Functions aren't stored because they aren't objects in C++.

I know. You store them in your source code with words you typed.

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.

I was only ever taking about style and good practice

>slowing down your compiler with useless comments, whitespace and linebreaks

*parser

Excellent !

>he is not porting his whole codebase to Rust

WE WUZ CODERS N SHIEEET

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.

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.

>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?

Shit if you hate code repetition

"The perfect language for Googlers"

That was my first thought, but i'd have to assign it to an std::function.

>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

Haven't found a real use for it yet but I like it.

lambdas

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 Sup Forums?

Just wrote a small program in C to filter out commented lines from a test input file, for fun. Is it good code?
#include
#include

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;
}

No. Except maybe if length

I can? What, like this?
void* pFun = [](){};
(reinterpret_cast(pFun))();

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'

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;

Also I think the standard form is while ((c = getchar() != EOF)

Thanks

maybe he knows ur a weeb

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.

>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

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)

There's some commercial AI library for AAA games.

It has a Brain type, AFAIK.

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?

works for me if I just call init(3) in main
even works for init(0)

>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

It's a binary file open in binary mode.

now prove OpenBSD's ifconfig

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

Forgot to quote

Hey looking for a Java friend again.
I'm currently sorting my ArrayList 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.

>implying you can
OpenBSD is fundamentally broken. You can't prove incorrect code.

>comments out 90% of his code

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.

unrelated, but what do the 3 and 0 mean?

elaborate

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

Look up seL4, Cogent, BiblyFS

Lain is the only good anime.

Of course; thanks so much, I'm over thinking it again. Please disregard my question. :^)

?
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

>obligatory homosexual anime recommendation

>not commenting your code
Perl """"programmer""" dtected

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.

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

wow it's beautiful

Neat. I've seen man pages like error(3) and never knew what the number meant.

forgot related pic
thank you

>commenting your code for "readability"
Reddit pajeet confirmed

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

>reddit
>pajeet
wow my filter got your post twice!
nice!

Hmm care to post what output you're getting?

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)

Aria.

So how are you reading his comment?

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

Battle Programmer Shirase