/dpt/ - Daily Programming Thread

Previous Thread: What are you working on, Sup Forums?

Other urls found in this thread:

en.wikipedia.org/wiki/Xlib
www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/
en.cppreference.com/w/cpp/container/set/insert
hackage.haskell.org/package/primes-0.2.1.0/docs/Data-Numbers-Primes.html
github.com/huonw/primal/blob/master/primal-sieve/src/streaming/presieve.rs
en.wikipedia.org/wiki/Fortune's_algorithm#Pseudocode
twitter.com/SFWRedditGifs

First for sublime text is best editor

cara in jam-jams

Why is the professional enterprise using C# and Visual Studio when Sup Forums says both are shit?

>enterprise

>I feel like literally everything has been done already

I get why one might feel that way in consumer or enterprise software - even though it's still not true there either.

But this is why I enjoy being in academia despite the pay being much lower than in industry. When you're on what amounts to the bleeding edge of a field many obvious things have NOT been done, and what has been done has very often been done really inefficiently. Actually improving it to make it a usable tool will give you lots of citations and make you a regular speaker at any methodology-focused sections of a your field's conferences.

And if the low pay is really bothering you, know that you are in the best position to monetise your know-how when whatever you've been working on starts being applied in non-academic/clinical use. You can start spin-off companies to capture a big chunk of a nascent market yourself or (if you lack the entrepreneurial mindset) just do consulting for companies which do that. They will approach you themselves - after all, they attend all the same conferences where you speak about methodology. I've made significant money doing the latter and I'm planning to do the former at some point.

tl;dr: Everything still sucks (even more?) in academia but that's great.

t. man who replies to seven hour old posts from a previous thread

char answer[5];
fgets(answer, 5, stdin);


Do I need to free answer? Thank you in advance.

C# and Java are preferred by enterprises because they are harder to fuck up for their thousands of sub-par programmers. If they let their employees use C, they would break everything.

Can a Pajeet learn C?

Only hardcore /dpt/ experts can learn C properly :^)

They can sort of do C++, but they are the type of people who do this:

Foo* foo = new Foo();

They may or may not remember to use delete, but they certainly won't be using smart pointers or allocating on the stack. They might also use malloc in C++ code.

Yes it's simple

in two sentences: how does a gui framework like qt work in combination with say X

obviously at the bottom of the "stack" we have the OS, in this case linux, which has acces to the hardware, but who tells the graphics card/unit what to reunder, how does this work (in two sentences) ?

Foo* foo = (Foo*) malloc(sizeof(Foo));
foo = new Foo();

An Ulam spiral generator. It's extremely fast, but I'm having problems with my prime sieve library. It only accepts a u32 as a top limit, and I need a higher limit to get a 50,000x50,000 spiral.

// Stack allocation
Foo foo;

// Heap allocation
auto bar = std::make_unique();

Both are preferable to naked new/delete or malloc/free.

en.wikipedia.org/wiki/Xlib

1980s style C library
You can make pure Xlib GUIs but it's maddening.

Poo* poo = new Poo();

Loo.push_back(poo);

// Street allocation
Poo* poo = new Poo();

// TODO: Loo allocation

Loo *loo = new Loo();
loo->in(poo);

// Street allocation
Poo* poo = new Poo();

poo.bring_to(new Loo());

Use u64 instead?

not really
memory leaks can still happen pretty easily

those languages are preferred because of their large arrangement of libraries/frameworks that support modern technologies and because development speed is very important

Just make your own resource manager so you can use it with < c++14. No need to bother with latest standard

>my prime sieve library
literally a few minutes to look it up on wikipedia and implement the pseudocode

Why are you guys even using C++ like this? It has no upsides.

what speaks against using it ?

Has anyone done terrain generation that does not use Perlin noise? I've been trying to get a large-scale planet made but the continents end up with no lakes or inner seas ever.

I feel like I could just make a bunch of patches of "land" inside of the continent regions, but just deleting the land to make water will fuck-up the natural features (suddenly water, out of fucking nowhere).

I can't think of a way to program it in less than a megabyte of source code. Can someone push me in the right direction?

> ?
Please stop committing crimes against typography.
No spaces before punctuation.

Why are you trying not to use perlin noise? There is reason everybody uses it

The fact that buffer overruns are the norm and undetectable namespace poisoning ruins lives.

whos the qt

What do you suggest?

Ideally, Perlin Noise works great for making shapes. It sucks at accurately placing lakes and small internal features where they would belong.

The only problem with this is the placement of the star.

star goes with type signature! Off with your head, heretic!

Foo * foo = new Foo()
//compromise

Isn't that a function of terrain elevation? Lakes match a basin, they're not sudden disruptions of land.

This guy is doing fine:
www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/

You might want to do some sort of "erosion" processing on your land though.

>no ;

int x, y, *p, *q

biribiri

Why would I re-invent the STL when my compiler supports the latest standard? Moreover, why would I bother with old and decrepit standards when the current one exists?

To the left or to the right, both are bad. Aside from it being likely unnecessary heap allocation, there remains the fact that it does not automatically clean itself up, meaning there is more work on the hands of the programmer to make sure all of the pointers get cleaned up.

Exactly the reason why gods of programming made it possible to have declarations on multiple lines.

Argument to moderation fallacy

I have committed no fallacy, and if you knew any rudimentary minimum about methods of debate you would know this

I have made no proposition or claim to truth

Damn, didnt expect you to know that. Nvm you win.

That generation demo works really well for making islands, but since I'm trying to build a whole continent, a lot of what he's doing for elevation and biome selection doesn't work for me.
My existing code generates cliffs and mesas and other elevation features. I'm currently using similar methods to decide the shape of the continents, but they're also really nasty looking. If there's a better method, I'd like it.

went for an interview last week and bombed it, so going back and looking over the basics again.

Fucked up on a question about implementing chain-of-responsibility in Java.

I'm using HackerRank, is there any other things that help me practice interview style programming?

How do you generate terrain for a sphere?
Are you just using regular 2d methods and mapping them onto a sphere?

i have this function
void post(const LogEntryInfo& log)
{
for(BaseLoggerSink* sink: sinks_)
sink->post(log);
}
is it safe call it from multiple threads? sinks_ is just a std::set, im worried that iterating over it from multiple threads could fuck up some iterators or something, content of sinks_ never changes, content of post() is irrelevant

If your function is pure then its safe to call from multiple threads. If not than maybe? Probably not

Foo* bar, baz;

Why is this acceptable??!??!

The syntax of a declaration is not
type identifier;
It is
base-type declarator;
And the declarator has all the information showing how the type being declared is related to the base-type. That's how we can have useful stuff like
int (*f())[5];

This is a function returning a pointer to an array of five integers. Declaration mimics use: if you call this function, dereference the result and take an array subscript of the result, you get an int.

No it's allocated on the stack.

en.cppreference.com/w/cpp/container/set/insert

>No iterators or references are invalidated.

: ^ )

Real life formation and evolution of continents/coastlines/lakes/rivers occurs by vastly different mechanisms over very different time scales so I'd say it makes sense to do it iteratively with different methods focusing in each of those in isolation rather than attempting to do it all in one go.

As to the specific algorithms I can't help much, sorry.

my function is pure, but im wondering for example, one thread is iterating, its at 5th element from 100, and then second thread start iterating too, wont this affect the first threads iteration?

It's always going to be safe for reading, the point is that inserting items won't make the iterators invalid

It's a library made for very fast prime computation that is extremely optimized (to the point of being cache friendly). I'm afraid that I'll fuck something up when I edit the source.

Use a different library

I'm just lopping off the poles and generating them separately, so I end up with an orientable 3d surface. This allows me to describe each location uniquely as a 2d manifold. I have a vector field (really just a scalar height) defined at each point on that manifold (everything starts zeroed out).

The field function is actually a distribution over the whole manifold, so I'm allowed to do cheap tricks. I add normal distributions centered at points where I want mountains and other flat-topped distributions where I want mesas. For sheer cliffs, I use truncated log-normals. All these distributions add together to form a smooth terrain map (too smooth, so I do some jaggedization after everything).

Having a Manifold lets me do cheap tricks later on, like being able to paint trees onto the landscape nicely without clipping the terrain and some drainage calculations for erosion.

That's why those languages have garbage collection. If you want to make memory leaks impossible and have no garbage collection, you have to use an ownership model like Rust. The disadvantage to ownership is that it's somewhat harder to learn, and beginners often experience something called "fighting the borrow checker". You have to realize that the borrow checker screams at you because it loves you, not because it hates you.

bivariate normals*

Good luck trying to create a prime sieve that's as optimized as Rust's primal crate.

why to pleb languages when there is holy js

>is the shape of your code

led strip works
temperature works
now just have to light the rgb leds according to temperature

>This uses a state-of-the-art cache-friendly Sieve of Eratosthenes to enumerate the primes up to some fixed bound (in a memory efficient manner), and then allows this cached information to be used for things like enumerating and counting primes.
>state-of-the-art cache-friendly
>(in a memory efficient manner)

teach me electriconics

How would you recommend I get into stuff like this as a C# dev?

I've always wanted to tinker around with electronics and make neat little physical things with what programming ability I have I just have no idea where to even start with it.

>state of the art
>>CTRL+F "wheel"
results
hackage.haskell.org/package/primes-0.2.1.0/docs/Data-Numbers-Primes.html

garbage collection isn't always gonna save you from memory leaks dude

get an arduino
????
start

would be the easiest way. you can go the hard way and directly start with pure C on avr boards

no i am dumb.

>state of the art
>use wheel;

>garbage collection isn't always gonna save you from memory leaks dude
wtf i hate gc now

arduino

post the latest code comment you've made

Apparently it does use a wheel in the sieve but they don't mention it

>Fuck this shit. Fix later

>// Main method to implement

Does it have to be in the past week?

this rust code has use wheel; i just thought it was funny because of how simple the statement is, it's not even namespace-prefixed though so how does that work, where can i find wheel? i'm not familiar with rust obviously

github.com/huonw/primal/blob/master/primal-sieve/src/streaming/presieve.rs

nvm i guess you can just refer to local "folders" in your project like that without a namespace

Thank you friend

Type "C tutorial" or "linux tutorial" into youtube. Most of them are from pajeets.

I always laugh at Sup Forums spergs who think they are superior to anyone because they write their fizz-buzz tier programs in C. Even stinky indians can do that.

was meant for

this, C is like the easiest language, it has the basic syntax of any C-like language and it just has a few extra very basic things like functions, structs, pointers, arrays, preprocessor macros

en.wikipedia.org/wiki/Fortune's_algorithm#Pseudocode
>pseudocode

Where can I learn to write a decent makefile? All the tutorials and stuff I found only do simple ones with no includes or anything

# Using callable wrapper class to avoid Pool pickling overhead

A comment of the "explain why it's done in the more complicated way" variety.

...

// used by asm_gen

Is that a Teensy?

No.
Arduino nano. Same as arduino uno, just smaller

is it alright to do shit like this

Class

God is dictating me the specs for a new OS guys.

>star
>part of type signature
That's not how it works. The type in the beginning of the declaration does not necessarily represent the type of the variable declared.
p is a pointer to int *p is of type int int *p;
similarly
p is an array of ints p[] is an int int p[];
p is a function taking two ints and returning an int p(int , int ) is an int int p(int, int);
You read the declared type from the variable and outwards, so that it corresponds to the usage of the variable in code.

-- Send only to the sender to prevent channel-wide spam with generic word triggers

Say what you want, but it is fast.
It does use a wheel

Is there any small, fast and safe c compiler similar to the Tiny C Compiler? TCC is unfortunately discontinued since a few years.