/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: Yegor.jpg (1200x574, 119K)

Other urls found in this thread:

en.wikipedia.org/wiki/Find_first_set
en.cppreference.com/w/cpp/algorithm/lower_bound
twitter.com/SFWRedditVideos

Not anime, fuck off

faggot, fuck off

Well user, which one are you?

Attached: DgbHNurU8AIhqYu.jpg (1200x469, 66K)

>async await
yikes.

c/c++ - second picture
javascript, scriptoshit - first picture.

>user is retarded: episode 3

I have the logic for Conway's Game of Life but it just outputs to a terminal right now. I've never done anything with a GUI before so I don't really know how to go about it. What's the most straightforward way to open a window and write a grid to it?

Attached: 1545591752455.jpg (1920x1080, 269K)

Tk

Concurrency? Why don't you just use Rust?

Because I'm heterosexual durr!

1st for FUCK HASKELL and FUCK FUNCTIONAL PROGRAMMING in general.

is it okay to be a programmer if u are not a cute anime girl???

If I can't make my functions mutable then how will I silence them?

Go drink some bleach, shit for brains.

define func fibonacci[n];
a = 0.0
b = 1.0
for int inside of range[0.0 | n];
c == a
a == b
b = c + b
return value of a
for int inside of range[0.0 | 8];
console.print[fibonacci[int]]
or else;
console.print[,Error,]

Working with some General Obilisk. Compiles nicely ggo.

you're retarded, but there is a lot of people here who aren't familiar with proper procedural design, and thus assume that procedurally-oriented languages are bad.
The people who usually complain about procedural programming are the same people who will write a 150-line function in Java that has half a dozen arbitrarily-placed exit points, god knows how many side effects, and can leave the object in numerous different states upon exiting.

there's nothing wrong with async, it's extremely useful in IO-bound applications (see: almost any program that connects to the internet). C# is an abomination, but that's not an async problem.

>.Find(p => true)
why

There are so many things fucky here.

>not using implicit typing
>getting a List when you know it will never have more than 1 entry because of the .Find
>checking products for null when it can never possibly be null
>not checking the result of the .Find when calling it on an empty data set will cause it to return null, and the .ToListAsync extension method will throw an exception when called on a null

>. C# is an abomination

Attached: 1490434324788.jpg (1080x1920, 532K)

there's literally zero net gain over Java. It fixes a handful of minor Java problems, while introducing its own minor set of issues. Both are shit.

no

>. It fixes a handful of minor Java problems, while introducing its own minor set of issues

Care to give some examples?
Then what would be a proper programming language?

Attached: 1544075490567.jpg (700x394, 35K)

>yegor
>Every begin object plus inmutable, slow slow programs
Only works in bussiness rules programming, few operations, errors massive bad and complex expression.

delegates are a decent addition, and async is valuable. ref and out are good.
In a language where almost everything is namespaced by classes anyway, the namespace keyword just adds even more boilerplate crap to an already boilerplate-laden language. Java's 'package' is cleaner.
pascal case for both functions and types is asinine and it detracts from readability.
the 'params' keyword is fucking ugly, ... makes infinitely more sense.
destructors are harmful and the fact that Java makes them unnatural to use is good.
struct in C# is redundant and completely unnecessary.
interface implementation and object inheritance are two wildly different things, and C# gives absolutely no syntactic indication of that.

I am looking to create a C# WPF application that will run on multiple machines in a network, and they all need to access/edit the same set of data in some SQL database.

I don't know what happens when there are multiple users attempting access to the same db. If it's currently being queried what happens when a new query is attempted?

How do I make sure that all requests have been handled from all sources and everyone is viewing the most up to date data?

My current thought is that there would need to be some second application that handles the queuing of requests and dishes out the updates to all applications when new requests come in. This seems like it could be excessive, but as these are the tools I'm aware of, this is what I plan to do. What is the best practice for this kind of thing?

Attached: Weekend Project.jpg (480x640, 42K)

SQL Server locking is a huge subject in and of it self. As far as concurrency handling, if you're using EF directly from the clients, you can just make sure each table has a ROWVERSION column and EF will automagically handle it.

From what you're describing, it sounds like you should have some sort of middleware between the clients and the SQL Server. Let it maintain a single reference universe and handle the requests, while persisting the data to the SQL Server as appropriate.

is there a better way of doing something like pic related instead of having to wrap all my code in promises?

Attached: awaitawaitawaitawait.png (646x702, 55K)

Build Server in C# query database in server, yes seriabilization is painful but other approach are worse.

Which context menu do you prefer?

Attached: context.png (378x245, 1K)

none of these loops will run in parallel. it will await a single thing in each iteration and only move on to the next one after it has resolved.

use Promise.all():
function processThings() {
return Promise.all(things.map(processArrayOfThings));
}

etc.

also dont use new Promise() unless you absolutely must. all your "new Promise()" wrappers are unnecessary

a slider?

>it will await a single thing in each iteration and only move on to the next one after it has resolved
this is what I need though, is what im doing in the original the only way? I have to wait to download each file in the last array before moving onto the next.

if I had 4 bits that are all 0 expect for one which is 1, how would why I find out the position of that 1
ie. 0010 would be 2, 1000 would be 4

divide number by 2, then multiply to see if you get the same result. if you do, try dividing it twice, then thrice...and so on
if you dont, your bit position is the number of times you divided it by 2
this assumes youre only working with integers though

>30 argument constructors

i dont know what you are doing, but sounds like you can at least download all files in a single array simultaneously before moving on to the next array.

-----------

if you really want to wait for each single item you can at least get rid of all the new Promise stuff. just write each function like you wrote the processThings function

I'd rather use bitshifts if it comes to that. I was hoping there was formula I could plug it into.

Slider (or anything analog-ish) is the only reasonable choice

Attached: mmm.jpg (347x102, 6K)

there are x86 instructions for this
en.wikipedia.org/wiki/Find_first_set

your number would be in a 32-bit word or something so you would "count leading zeroes" and then subtract it from 32 or whatever

i put together the entire programmer outfit (pleated skirt plus hairband for extra productivity)
its going great so far!
is there anything else i can do to boost efficiency?

Kill yourself.

>if you really want to wait for each single item you can at least get rid of all the new Promise stuff. just write each function like you wrote the processThings function
Thank you, I'm a brainlet lmao.
I made a script that downloads every image from a board using the Jow Forums api, if I dont wait for each file to download it tries to download too many at once and sends an error.

no you didnt

I think I figured out why my laptop's monitor randomly gets stuck in rainbow loops. At first I thought that a trace near the GPU was delaminating, or it was overheating from old ass thermal paste

Now I'm pretty sure that this is just what happens from the constant lightning strikes I get on my bed when I move around in this dry winter weather

Are you seriously writing that in C++?

You can do that in like 5 lines of Haskell. Here, let me show you

Attached: pion7sr3p8421.jpg (1280x720, 80K)

programmer pills!

Attached: aid10095617-v4-728px-Take-Hormone-Replacement-Therapy-Step-2.jpg (728x546, 50K)

Dude just use one tag

el monstruo...

Attached: 1510608158526.jpg (1400x1400, 241K)

there's literally nothing wrong with having multiple exit points in a function.
That's an artifact and now a myth which originated from older procedural programs where people would create multiple exit points using jumps, which are obviously bad.

Functions with return statements can only return to the next function on the call stack, unless you are misfortunate enough to have a buffer overflow.

>being too fucking retarded to know what a context menu is

Please kill yourselves immediately.

>he uses a GUI toolkit that doesn't allow context menus to have sliders

Whoever recommended that python book wtf? So third chapter im calling a turtle called bob? What is this shit? I wanna make actual guis, not this surface level shit

>python
>gui
Python doesn't have any sort of built in GUI toolkit. You'll want to look for docs on the specific toolkit you want to use, they're unlikely to be covered in a general Python book.

>any language
>GUI
You're going to be thrashing in pain no matter what you do, may as well just end it all and use vulkan forever

The first time I did it, I directly blitted the pixels to a Swing window. Don't do that though. Buffer the image and draw it all at once, otherwise you end up with a progressive scan line above a certain resolution.

I started of doing a lot of back-end programming with C++ and at the moment I'm working on some game engine stuff for this mixed reality thing. As of late though my project manager wants me to create a website and I haven't done any webdev stuff since highschool.

do
{
n = n >> 1;
bitposition++;
} while (n > 0)

i'm sure you already have the striped knee-high socks, but make sure to get a matching pair of arm warmers too!

>there's literally nothing wrong with having multiple exit points in a function
it's fine in GC languages
it's OK in C++ because RAII
but multiple exit points can be pretty bad in C if not properly handled
actually jumping to the memory-freeing file-closing etc block at the end of a function when you want to return early is one of the two remaining good uses for goto (the other being multi-level loop breaks)

4 cases wow

use a switch

Learning Forth.

Attached: forth.jpg (1044x574, 251K)

Hey anons, should I use a char array in C++ or should I just stick with std::string?

depends on the circumstances

Its a gui thing called turtle

string_view

debugging a sega genesis game.
trying too figure out what compression is used on the graphics.

There's tkinter and turtle. Someone made a flappybird clone using turtle in python. Pretty cool.

>>>cont/a/inment
Stay there weebscum

tkinter is featured in the python help file dude

have anyone tried using cmake in windows and havent killed themselves yet?

use it with jetbeans

I use cmake with conan for both Linux and Windows, it just werks.

I'm confused, isn't the whole purpose of objects to encapsulate the state and mutate the state based on received messages?

I want to write a function that can take as input an integer and an array of sorted integers, and then return the count of how many integers in the array are greater than and how many are less than the value provided. What would be the most time efficient way to do this?

making front-end for a carpooling app in angular

binary search to find the index at which the needle is

remember to account for the possibility that the needle appears multiple times, assuming that can be the case

How do you do a single binary search when the value being provided to the function might not exist in the array though?

You could implement easily what you want on top of lower/upper bound:
en.cppreference.com/w/cpp/algorithm/lower_bound

You'll find the two numbers either side of your needle if you conduct the whole search and don't find it.

>go to the middle index
>assume that everything to your left is smaller, everythig to your right is larger
>you now have size(array)/2 for both of the partition.
>if number is smaller than current element, go left, else go right
>increment the previous numbers accordingly, say, going left means that the smaller_partition is now 1 smaller and the large_partition is 1 larger
>do this until BAM! you found your number

this pretty much

this algorithm is at worst O(n/2) assuming that an answer exist

finish a thread you autists, so that there aren't 2 /dpt/s on Jow Forums

RAII _IS_ GC!!!

What's your favourite MySQL/MariaDB storage engine, Jow Forums?

Attached: storage.png (678x591, 1.15M)

wrong.

why do we have two /dpt/s
are you guys retarded

var myConcat = function(arr1, arr2) {
"use strict";
return arr1.concat(arr2);
};

console.log(myConcat([1, 2], [3, 4, 5]));

rewritten looks like THIS:
const myConcat = (arr1, arr2) => {
"use strict";
return arr1.concat(arr2);
};

console.log(myConcat([1, 2], [3, 4, 5]));


is that REALLY all there is to this arrow notation?
change function to => and move it to the other side of the argument(s)?

is THIS "regex"?

Attached: 49766477_2382610811777609_7406788363149115392_n.jpg (564x564, 32K)

.Find() doesn't return an enumerable, this code won't even compile.

Arrow notations allow you to skip braces and the return keyword if the entire body is a single statement.
var f = function (a, b) { return a + b; };
is equivalent to
var f = (a, b) => { return a + b; };
is equivalent to
var f = (a, b) => a + b;

It also binds the value of "this" to the object it is defined for.

>is THIS "regex"?
this has nothing to do with regex

Both are C++

I'm currently learning golang so I though I'd share my impl
package main

import "fmt"

func fibonacci() func() int {
a, b := 0, 1

return func() int {
a, b = b, b + a
return a
}
}

func main() {
f := fibonacci()
for i := 0; i < 10; i++ {
fmt.Println(f())
}
}


I'm having a lot of fun learning golang, I'm honestly remembering why I like coding. Golang does a lot of things right from my first pass at its language features.

thanks m8

Attached: 50494691_938053383060082_9148854298434600960_o.jpg (1076x1076, 108K)

I'm using a beautiful soup 4 to webscrap.
After I get the thing I wanted using find(), how do I get another thing I know shows up after the first thing without re-reading the entire document?

Attached: Dabi.png (1044x1440, 705K)

it is.

What is the rule of thumb for adding / subtracting a double in C?

I know an operation with a massive value difference (for example 2^(120) + 2^(-120)) will be rounded and ends up imprecise
What is the rule of thumb to be confident that an operation will be precise?

template
auto row(size_t i) {
if constexpr (std::is_same_v) {
....
}
}

error: ā€˜Eā€™ was not declared in this scope
if constexpr (std::is_same_v) {

What the fuck is GCC smoking?

Attached: 1548159279568.png (1938x3445, 323K)

>var
Retards.