[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: 315
Thread images: 28

File: prog.jpg (105KB, 473x496px) Image search: [Google]
prog.jpg
105KB, 473x496px
Previous thread: >>60804534

What are you working on /g/?
>>
Why is JS so cancerous? What the fuck is wrong with all those wrappers
>>
>>60808860
#include <cstddef>
#include <type_traits>
#include <iostream>

// Lists must have a value member and a next pointer
template <typename Object, bool is_class = std::is_class<Object>::value>
struct is_list
{
template <typename T, T Object::*>
struct helper;

template <typename T>
static std::false_type has_next(...);

template <typename T>
static std::false_type has_value(...);

template <typename T>
static std::true_type has_next(helper<T*, &T::next> *);

template <typename T>
static std::true_type has_value(helper<decltype(T::value), &T::value> *);

typedef decltype(has_next<Object>(nullptr)) next_tester;
typedef decltype(has_value<Object>(nullptr)) value_tester;

static const bool value = next_tester::value && value_tester::value;
};

template <typename Object>
struct is_list<Object, false> : std::false_type {};


size_t print_list(...)
{
std::cout << "No elements" << std::endl;
return 0;
}


template <typename List>
typename std::enable_if<is_list<List>::value, size_t>::type print_list(const List& list)
{
size_t n = 0;

auto* ptr = &list;
while (ptr != nullptr)
{
std::cout << ptr->value << std::endl;
++n;
ptr = ptr->next;
}

return n;
}


template <typename Type>
struct List
{
Type value;
List* next;
};


struct NotList
{
int value;
List<int>* next;
};


int main()
{
NotList nhead = { .value = 1, .next = nullptr };
print_list(nhead);

List<int> head = { .value = 1, .next = nullptr };
print_list(head);

return 0;
}
>>
I love C++!
>>
Working on our in house Netty based Back-end architecture.
>>
Write a program in your favorite language to create and print a cyclical list. So far we've had submissions in C, C++, Python, and Haskell

>>60808880
That is beautiful
>>
Working with this Indian guy.
He had done database with like 10 tables where all of them had like 20 columns, he said it was not normalized by design choice.
We are moving to new platform which has new db with over 100 tables which is normalized properly.
He told me it sucks because it's over normalized.
Is that guy actually retarded or is there really some benefit to having everything in one fucking table?
>>
can i import libraries or instantiate objects (from different classes) inside a class without a main in java?
>>
>>60808971

of course
>>
hey guys, working on some Python exercises, and I solved one but I don't understand quite how it works. here is the assignment:

>Write a function called cumsum that takes a list of numbers and returns the cumulative sum; that is, a new list where the ith element is the sum of the first i+1 elements from the original list. For example:
>>> t = [1, 2, 3]
>>> cumsum(t)
>[1, 3, 6]

and my solution:
t = [1, 2, 3, 4]
def cumsum(x):
b = []
for i in x:
a = x[0:i]
b.append(sum(a))
return b

print(cumsum(t))


I don't really understand the "a = x[0:i]" part. I thought slicing x[y:z] started the slice at y and went up to, but NOT INCLUDING, z. So in my code, when it's running through the second element, i=1, it should slice to [0:1] meaning just the first element... Where am I getting this wrong?
>>
>>60808978
thanks
>>
>>60808954
He sounds pretty retarded. The only reasons not to normalize your tables are laziness and stupidity. He sounds like he's right in the middle
>>
>>60809001
>cumsum
I'll give you some cumsum if you know what I mean
>>
>>60809038
cumSumOnMe();
>>
>>60809001

Your logic is fucked.
>>
>>60809045
>not
 you.CumSum(me) 
disgusting
>>
>>60809048
alright, so how exactly?
>>
>>60809166

Fails whenever the input list is not an enumeration from 1 to n.
fixd
def cumsum(x):
sum = 0
out = []
for i in x:
sum += i
out.append(sum)
return out
>>
>>60808954
You denormalize when you get a perfomance hit due to joins and shit. In 99.99% cases, you don't need it. In remaining 0.008% cases, denormalizing won't help anyway.
>>
Rate my FizzBuzz, /g/

#include <stddef.h>
#include <stdio.h>

#define spc(x, xs, c) \
((x) % (xs) == 0 ? (c) : ' ')

#define ch(m, i, c) \
(*((m) + (i)) != 0 ? (c) : ' ')

#define pc(c) putchar(c)


void character(size_t xw, size_t xl, size_t space, char c, const int* matrix)
{
size_t x;

for (x = 0; x < xw; ++x)
pc(spc(x, space, ch(matrix, 0, c)));

for (; x < xl; ++x)
pc(spc(x, space, ch(matrix, 1, c)));

for (; x < xl + xw; ++x)
pc(spc(x, space, ch(matrix, 2, c)));

for (; x < xl * 2; ++x)
pc(spc(x, space, ch(matrix, 3, c)));

for (; x < xl * 2 + xw; ++x)
pc(spc(x, space, ch(matrix, 4, c)));
}


void line(size_t xw, size_t xl, size_t space, const char* str, const int* matrix)
{
size_t x;

while (1) {
character(xw, xl, space, *str++, matrix);

if (*str == '\0')
break;

for (x = 0; x < space; ++x)
pc(' ');
}

pc('\n');
}


void fizzbuzz(size_t size, size_t thick, size_t space, const char* str)
{
int matrix[] = {
1, 0, 1, 1, 1,
1, 0, 1, 0, 0,
1, 1, 1, 1, 1,
0, 0, 1, 0, 1,
1, 1, 1, 0, 1
};

size_t xw = thick * space;
size_t xl = size * space;
size_t yw = thick;
size_t yl = size;
size_t y;

for (y = 0; y < yw; ++y)
line(xw, xl, space, str, matrix);

for (; y < yl; ++y)
line(xw, xl, space, str, matrix + 5);

for (; y < yl + yw; ++y)
line(xw, xl, space, str, matrix + 10);

for (; y < yl * 2; ++y)
line(xw, xl, space, str, matrix + 15);

for (; y < yl * 2 + yw; ++y)
line(xw, xl, space, str, matrix + 20);
}


int main()
{
fizzbuzz(3, 2, 2, "*");
return 0;
}
>>
/dpt/ is this a good implementation of random numbers?
#include <limits.h>

/** fuckUpBit
* Send an electrical signal to the int'th bit of the char. The
* specific strength of the signal should cause future read
* operations on the bit to yield uniformly inconsistent results. (I
* know this is physically possible, but I don't know how to do it
* in C.) */
void fuckUpBit(char*, int);

/** random
* Return a random number generated using electrical noise. */
int random(void) {
static int fuckedUp = 0;
static int source;
if (!fuckedUp) {
int i, j;
for (i = 0; i < sizeof(int); i++)
for (j = 0; j < CHAR_BIT; j++)
fuckUpBit(((char*)&source) + i, j);
fuckedUp = 1;
}
return source;
}
>>
>>60809001
In Haskell, this is just
cumsum = scanl1 (+)
>>
>>60809264
Oops I forgot source should be static volatile int, not just static int
>>
>>60809196
cool, I see now. Thanks!
>>
>>60808860
import sys
import os

#test.py

def q(question):
return input(question)

def wrong():
os.remove("test.py")
sys.exit()


if not q("Please enter a user name in alphabetic characters only \n>").isalpha:
wrong()


if q("Please enter you favourite RBG primary colour \n>").lower() not in ['red','green','blue']:
wrong()


>>
>>60809270
that's even gayer than
you.CumSum(me)
>>
>>60809298
>>>/reddit/
>>
>>60809264
Fixed for volatile-correctness:
#include <limits.h>

/** fuckUpBit
* Send an electrical signal to the int'th bit of the char. The
* specific strength of the signal should cause future read
* operations on the bit to yield uniformly inconsistent results. (I
* know this is physically possible, but I don't know how to do it
* in C.) */
void fuckUpBit(volatile char*, int);

/** random
* Return a random number generated using electrical noise. */
int random(void) {
static int fuckedUp = 0;
static volatile int source;
if (!fuckedUp) {
int i, j;
for (i = 0; i < sizeof(int); i++)
for (j = 0; j < CHAR_BIT; j++)
fuckUpBit(((volatile char*)&source) + i, j);
fuckedUp = 1;
}
return source;
}
>>
>>60808925
Cyclical, as in if I keep incrementing over it it just starts again, so for a 20 element list, list[21] is list[1]?

Please repost the Python version. I'm working on my own, want to compare.
>>
>>60809001
Put a print(i) in your for loop and you will know immediately
>>
>>60808925
Useless meme challenge.
>>
>>60809365
Name a better challenge
>>
>>60809433
Cold turkey isn't how you fix addictions, it's by overcoming yourself.
>>
>>60809401
Challenges are retarded unless they're for educational purposes.
Showing that you can use arbitrary constructs, functions, and state doesn't mean you're a good programmer.
>>
>>60809456
I am just trying to LIMIT IT, not outright stop it.
>>
i was brainwashed a a kid to want to be involved in the tech industry and I was only shown enduser packages and products with no understanding of how to actually make or reverse engineer any of what I interacted with, why do I still want a job in the tech industry.

I have no education in this only what I was brainwashed into wanting to do when I was a kid

so should I kill myself what hope is there in my life
>>
>>60809515
Lol, learn. Fascination with end user products is what drives people to any career. If you find out you don't like it after a valid try out, consider something else.
>>
>>60809515
what?
>>
>>60809515
>>60809556
Besides, the 'tech industry' is very diverse. I thought I wanted to make video games when I was younger, and I just ended up on a different path.
>>
>>60809556
i must gitgud then
>>60809590
I did make video games when I was younger, in highschool I made flash games
>>
File: mwZ5RTG.jpg (121KB, 480x1845px) Image search: [Google]
mwZ5RTG.jpg
121KB, 480x1845px
Hey guys I'm more on the operations side of things but I'm learning Python and Ansible to up my devops game.


For my first real project I want to write a script that uses my area's GeoIP list and scans each IP in the area for the most commonly used ports that are open (maybe even checks for exploits) and then lists the IPs in various text files named "Port 3389 Open" or something of that nature. How difficult do you think this would be for a beginner?
>>
>>60809810
Also obviously will utilize nmap and most likely nmap scripts to do the scanning so I won't have to write those.
>>
Cyclical array in Python (again):
https://pastebin.com/uZwT3g2e

>>60808925
>>
I'm toying with an edge detection program using genetic algorithm.

How retarded is this?
>>
>>60809590
>the 'tech industry' is very diverse

Yeah, a huge sea of diverse white men
>>
>>60809914
DETECT THESE EDGES
*unzips dick*
>>
>>60809914
>genetic algorithm

Also known by its other name: "stupid search"
>>
Is there a way to access datatypes that are not concurrency safe through channels in golang without making it look fucking retarded and more complex than simple mutexes
>>
>>60809914
http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html

Alternatively, if you're just looking for pixels along edges (rather than keeping track of which pixels belong to the same edge) why don't you just
>create a copy of the image
>blur it with a small radius
>subtract blurred copy from original
>threshold pixel values
>>
>>60809946
no, it's "stupid automatic search", which means you don't have to do much work, just sit back and let the algo take control.
>>
File: Screenshot_20170608_172945.png (101KB, 986x1052px) Image search: [Google]
Screenshot_20170608_172945.png
101KB, 986x1052px
Writing libc on FASM.
>>
>>60808925
(labels
((helper (orig remaining)
(if (not remaining) (helper orig orig)
(lambda ()
(cons (car remaining)
(helper orig (cdr remaining)))))))
(defun circular-list (&rest args) (helper args args)))
(defun print-circular-list (cl n)
(when (> n 0)
(let ((pair (funcall cl)))
(print (car pair))
(print-circular-list (cdr pair) (1- n)))))
>>
What is your opinion on recruiters?
I made a LinkedIn account last night and I already got mail from two recruiters. Should I bite or find a job by myself?
>>
>>60806495
All those examples can be assumed to be slow. Why do you trust C++ anymore?

If you've worked in any sort of high performance computing you'd know it's a very useless feature.
Amdahls law is in full effect here. And unlike most CS on speed things it's a rather constraining law.
You have to keep it in mind when you build a parallel system for speed. Important for clusters as well as single machines.

But again as I said. If you really don't care I'm sure it's a plus if you ignore cache stomps that might occur (which shouldn't be a big deal if what you're using this for is rather slow loop iterations).
>>
>>60810156
Lel it don't fucking work.
(print-circular-list (circular-list) 4) ; stalls out forever
>>
>>60810154
>Atom
>ASM
Oh god
>>
>>60810154
Look up the rep instruction for str_len (and other string-related functions), could be useful
>>
File: 20170602_104756.jpg (2MB, 2150x2148px) Image search: [Google]
20170602_104756.jpg
2MB, 2150x2148px
>>60809810
>>60809826
No one has any advice on this?
>>
>>60810203
An empty circular list doesn't make any sense you dumbass. What exactly did you expect it to do.
>>
>>60809365
>meme
Use >>>/v/
>>
>>60810183
>I guess you assumed..
No I know how these systems work. The problem with these systems is that either you're handling the absolutely most trivial case of not having any data sharing. In which case assigning work to an existing thread pool has always been there. Adding this just complicating the other circumstance that is when you have data sharing and this kind of system simply can't be sufficient unless there's some super advanced code analysis I haven't heard of. Basically if you can teach the compiler to do the job of the programmer well enough you would see gains. I don't deem that all that likely though. You might get there through profiling the program and feeding it back repeatedly. Which certainly would be interesting but it's usually not sufficient for software in general as you don't really stop developing/maintaining software anymore.
>>
>>60810232
That looks delicious. What is it? Is that raw salmon?
>>
>>60808860
i was gonna ask on the stupid questions thread, but this seems like a better thread to ask in.

i bought an RGB keyboard that is controlled only through the FN key there is no software ofr it. it has preset colors and animations on it. i want to try and code some different animations and colors onto it.

how would i go about this? what would i need?

is this too difficult for someone who has never done anything like this to do?

thanks
>>
>>60810232
It's difficult to measure difficulty. And beginner is very vague. So people can only really answer when they feel it'd be impossible.
To me it sounds entirely feasible. I haven't done geoip stuff but I assume it's either easy or there's a good library for it.
>>
>>60809365
>STOP DOING FUN THINGS THAT I DON'T LIKE

>>60809464
It's literally for educational purposes. A lot of programmers on here are young CS students or hobby programmers, and doing challenges is fun

>>60810156
>>60809892
Nice job anons

>>60810287
Depends on which keyboard it is. I'd start by googling the keyboard make and model, looking for some kind of software documentation. If it doesn't expose some way to change the colors through software, you might be able to hack some kind of microcontroller onto it, but that's probably a bit more involved than you're looking to do.
>>
>>60810287
It sounds rather intractable. You'd need to write a driver for the keyboard in the best case.
In the worst case the color stuff is implemented in HW and you'd have to reverse engineer that part of it. Which may be easier but it's not programming it's more about electronics.
And creating an interface for it might be a challenge unless you also write a new driver that handles transmitting color codes.
>>
>>60810289
Thanks. I believe there is a few companies that have IP databases that I will have to use.
>>
>>60810320
>implementing a data structure is fun
>>
>>60810344
>trying new things in programming when you're a student is not fun
>>
>>60810357
>implementing a data structure is ever fun
>implementing a data structure is not always struct instead
>being this addicted to closures
>>
In C when implementing hashtable. Should you make it hold size of the slot value and have fixed sized slots or just put void pointer there?
>>
>>60810215
>>60810320
>>60810344
>>60810357
>>60810389
Who are you quoting?
>>
>>60810357
Not that guy but unless it's your first or second datastructure it really isn't fun. It's a very concentrated programming problem where what I enjoy, engineering, is completely absent.
If you enjoy typing in code and running it that's fine. I'd consider you an odd case.
>>
>>60810389
When I read your post, I thought you were an idiot who was illiterate. Then I reread your post, and now I think I'm an idiot who is illiterate
>>
>>60810402
lern 2 greentext, newboy
>>
>>60810408
What do you enjoy doing then?
Typing boilerplate?

Writing your own shit is the only time programming could actually be considered "fun".
>>
>>60810418
>lern 2
>>>/b/
>>
File: 71zy1uJBMTL._SL1500_.jpg (207KB, 1500x1500px) Image search: [Google]
71zy1uJBMTL._SL1500_.jpg
207KB, 1500x1500px
>>60810287
>>60810320
its the RK Pro104. ive searched for software but i cant find anything. yeah i wouldnt even know where to begin with that.

>>60810322
yeah that definitely sounds really difficult.
>>
>>60810428
>your own shit
How is your typical datastructure your own shit?
I enjoy systems programming.
>>
>fun
>>
>>60810394
Uh, it all depends on what you need. If the value is not directly accessible via hash but is actually a pointer to the value, then obviously that's going to be slower, but sometimes it may be what you want anyway.
>>
>>60810402
>it are hte whomst art thou quoting meme

>>60810417
>When I read your post, I thought you were an idiot who was illiterate. Then I reread your post, and now I think I'm an idiot who is illiterate
I'm not the guy who originally said the thing, I just thought I'd make fun of it.
>defun
>defstruct
>using defun instead of defstruct to implement a data structure
>probably means you use a message passing paradigm where the object is a closure and the messages are parameters to the closure
>borf
>>
>>60810394
https://github.com/nothings/stb/blob/master/stb.h
This is a good library.
You can look at what they do if you want.
>>
>>60810484
>stb
>good
senpai...
>>
>>60810476
>implementing lists in List Processing Language
(print '#1=(1 2 3 . #1#))
>>
>>60810476
I'd like to see your defstruct version.
>>
>
>>
>>60810408
>It's a very concentrated programming problem where what I enjoy, engineering, is completely absent.
That depends on the kind of data structure you're implementing.
Non-exhaustive list of data structures which are generally heavily engineered by necessity:
>open-addressing hash table with double hashing
>database (technically a data structure, if you think about it, albeit a very big one)
>general purpose directed graph
>language evaluation tree
>simulated electrical circuit
>>
If I'm one of 3 in a class of 25 getting A's on all my programming projects then that must mean i could be above pajeet programming, right?
>>
>>60810599
>programming classes
>i could be above pajeet programming
No.
>>
>>60810588
>>database (technically a data structure, if you think about it, albeit a very big one)
kek
>>
>>60810599
Post your last assignment requirements.
>>
>>60810599
>on all my programming projects
name three
>>
>>60810599
No, it means that your study is Pajeet tier.
>>
String str = "test1";

Pattern pattern = Pattern.compile("1\b");
Matcher matcher = pattern.matcher(str):

return matcher.find();

why does this return false?
Every regex tester says this should find the "1" and work
>>
>>60810599
This guy has it right: >>60810617

Classes are for weak willed liberal pansies. You're probably a smelly millennial. If you've had any contact with higher education you're corrupted with poopy pajeet blood. Real men are strong and don't need school to program good.
>>
>>60810536
(loop with circ = '#0=(1 2 3 . #0#)
do (princ (pop circ)))
>>
>>60810623
nothing serious, its an IT degree but the class made me enjoy programming. I figured getting A's meant I might have a knack for it.

the last project was just a c# interface for a user to do queries on a database. The program needed to sort entries, return certain entries, without affecting the db and things like that.
>>
>>60810536
>>60810695
>this exists
>i bothered to spend 12 lines of code reinventing it
wow i am literally the best at doing nothing but waste time 24/7
>>
>>60810727
Don't be sad, there's barely any use for ciruclar lists.
>>
>>60810509
What's wrong with stb? It probably isn't perfect but goes pretty well along with the standard library and is damn easy to integrate.
>>
Should I listen to Doug Hoytes?
>>
>>60810668
iirc java need 2 backslashes in regex
>>
File: 1445705986467.jpg (31KB, 853x480px) Image search: [Google]
1445705986467.jpg
31KB, 853x480px
What is the single most fucked up fetish that can be programmed in fewer than 40 characters?
>>
>>60810844
ask >>>/trash/
>>
>>60809334
No cheating
>>
/dpt/ how do I write code to add an extra node to a fixed-length toad without alerting its chodes? The goal is to add a payload to the toad to make it cross the road when I change the mode.
>>
>>60810844
Dereferencing null pointer
int main(){return*(int*)0;}
>>
>>60810988
Applied genetics may technically be programming but it sure isn't computer programming.
>>>/sci/
>>
>>60811070
>daily programming thread
>daily computer programming thread
>>
>>60811171
You do have a point.
I guess that would make the sissy trapfags the most advanced and experienced programmers here. Not because they write good code (they don't) but because we're counting social programming as a kind of programming.
>>
>>60811234
>Who are you working on, /g/?
>>
What headers does your personal C library have?

#include <makilib/dstr.h> //dynamically sized string
#include <makilib/list.h> //dynamic array


What else is good?
>>
>>60810844

Sticking your dick in a bee hive

puts " |
|
| B
/-\\ B
| | C===3
\\-/"
>>
>>60808925
Guile Scheme has built-in functions for this.
(import (srfi srfi-1))
(display (circular-list 1 2 3 4))


For R5RS Scheme:
(define (circular-list . elems)
(define (last-pair lst)
(if (null? (cdr lst))
lst
(last-pair (cdr lst))))
(set-cdr! (last-pair elems) elems)
elems)

(define (print-circular-list lst)
(define (take-while-pair lst pred)
(if (pred lst)
(cons (car lst) (take-while-pair (cdr lst) pred))
'()))
(display (cons (car lst)
(take-while-pair (cdr lst) (lambda (x) (not (eq? x lst)))))))

(print-circular-list (circular-list 1 2 3 4))
>>
Is there any difference between a promise and just a thunk?
>>
>>60811431
Soldering CPU's I see? Got any clocks?
>>
>>60811525

the gravitational constant should be private to whatever object implements gravity
>>
File: 1493246822485.png (1MB, 992x1048px) Image search: [Google]
1493246822485.png
1MB, 992x1048px
>>60808860
Is anime decidable?
>>
>>60811812
>objects ""implement gravity""
Am I ""implementing gravity"" right now?
>>
>>60811814
decidably awesome
>>
>>60811273
I just have C wrappers for some system stuff in gcc and msvc, like thread functions, sockets and such.
>>
>>60808860
A server monitor in Python. I had half of the backend done and then tested it on Winblows. I'm torn between writing a bunch of platform-specific code for it and littering it with comments about how much I hate this pigfuck special snowflake excuse for an OS, and just ignoring Windows altogether.
>>
>>60812024
why do you need platform specific code for a server monitor?
>>
>>60812024
>in Python
Stopped reading right there.
>>
>>60809001

First it makes an empty list which will be the CUMSUM list.
It creates a list containing only the elements up to the index you're at, and adds all the elements of that sublist together and adds that to the CUMSUM list.

This works but this is a major waste of time and resources honestly. This uses more space and takes n^2 time since you keep summing up lists (linear time complexity) for every index (which there are n many of).

Every step of this can be done using the current index of the original list added to the previous index of the CUMSUM list, stepping through the original list.
>>
How do I test JS programs?
In Java I would mark everything @Autowired and provide mocks/stubs for test run.
In Purescript I would use Reader monad and provide a stub config value.
What shall I do in JS?
>>
>>60812024
Because a lot of the methods I use to gather information don't work on Windows, and I'm trying to avoid dependence on a third-party library.

>>60812070
How can you create something that just werksâ„¢ on everything with minimal fuckery in C?
>>
>>60812064
Meant to reply to >>60812064
>>
>>60811830
No, you're implementing "IAffectedByGravity"
>>
>>60810215
What's wrong with Atom or ASM?
>>
>>60812155
>just werksâ„¢
>>>/b/
>C
Where does my post mention C?
>>
>>60812154
Not programming related.
Try using >>>/g/wdg/
>>
any good reading material on audio programming? im just trying to play an audio file in go but i don't understand any of the termonology (frames, samples) etc etc or how it works in general
>>
>>60812174
You mean besides them being trash?
>>
>>60812155
What information are you trying to gather? Just curious.

>I'm trying to avoid dependence on a third-party library.
python itself is a third-party library
>>
>>60812233
>asm
>trash
wut
>>
>>60808860
I decided to start learning sockets in C++, finding it a little difficult though since it appears all of the sockets in C++ are handled using C's socket library, and I didn't learn C first
Anyone got any tips? My aim with this project is a straightforward file transfer client/server for GNU/Linux
>>
>>60812534
What exactly do you have a problem understanding? Its just simple function calls and its sort of object oriented, too (the file descriptor representing the socket object.)
>>
>>60812534
>GNU
>>>/b/
>>
>>60812586
>and its sort of object oriented
So in other words it's trash?
>>
>>60812586
I've never worked with sockets properly in any programming language so the whole thing is pretty new to me, maybe I just need to read further into it. I'm wondering what would be best to read if I'm starting it from scratch. I read the article on LinuxHowTos but it doesn't seem to go too far into everything.
>>
>>60812641

what interest does a functional autist like you have in I/O?
>>
>>60812660
I recommend Beej's guide, you'll find it by searching just that with a search engine. Sockets are an ancient API so the naming of stuff may be a little confusing sometimes (especially the data structures), but you'll quickly get a hang of it I'm sure if you just do the exercises.
>>
>>60812662
>POO and "FP" are somehow mutually exclusive
How is having low IQ treating you?
>>
sum types suck, right? if I, as a user of a sum type, want to extend it by adding a new value, I'm totally short of of luck. and if I, as a library writer, want to extend the sum type, all my clients will break because they're not pattern matching against it.

when SHOULD we use sum types?
>>
I don't like programming in javascript
why is dat
>>
>>60812709
Thanks a lot anon, found what you're talking about, I'll start working my way through that
>>
>>60812736

because it's a terribly designed shitlang
>>
>>60812723
by sum types I mean "algebraic data types"
>>
is there a quick way to configure passwordless SSH over 50 nodes
I really don't want to do each one individually
>>
File: 1487930506024.jpg (219KB, 1920x1080px) Image search: [Google]
1487930506024.jpg
219KB, 1920x1080px
>>60812764
This is possibly the most retarded thing I have read this week.
>>
>>60812781
Are you being paid by the hour or by salary?
>>
File: barking.jpg (34KB, 524x468px) Image search: [Google]
barking.jpg
34KB, 524x468px
>>60812798
neither, it's a personal project using school resources
>>
>>60812795
algebraic data types are bad dude sorry
>>
>>60812827
Can't you just write a script to automatedly log into every single machine and setup the same login scheme?
>>
>>60812854
I meant you conflating "sum types" with "algebraic data types". Which is a redundant word anyway.
>>
How do I enforce static typing in javascript?
I don't want to have to keep casting what I know to be a number that's been reinterpreted as a string.
>>
>>60812916

you don't

use typescript or something
>>
>>60812916
>>60812971
Not programming related.
Use >>>/g/wdg/
>>
>>60811247
lewd
>>
>>60812916
Easy, take off the "script?".
>How do I enforce static typing in java
>>
>>60813027

java and javascript are nothing alike
>>
>>60813027
Why would he switch from one shitlang to another shitlang?
>>
>>60813044
That's the point tho
>>60813046
Java is a good language tho
Anyone who says otherwise's waifu a shit
>>
>>60812662
>>60812760
>>60812971
>>60813044
>that spacing
I didn't even bother to read your posts, because I already know they're fucking stupid. Piss off.
>>
>>60812855
I got really lazy and found one
>>
>>60813060
>Java is a good language tho
Only if something can be both good and shit and the same time.
>>
>>60813085
>Only if something can be both good and shit and the same time.
You imply Java is shit
Anyone who says Java isn't a good langauge's waifu a shit
You're waifu a shit
QED
>>
>>60813100
>You're waifu a shit
My waifu is both good and shit and the same time. Just like Java.
>>
>>60813121
Wrong Java is exclusively good and you're waifu exclusively a shit
>>
The hood for my master's degree robe is choking my neck.

>>60811273

I don't tend to conglomerate library headers into one uber header. That's kind of bad practice.
>>
>>60813136
Java can't be exclusively good since it's shit and my waifu can't be exclusively a shit since she's good.
>>
File: smug_ran5.png (325KB, 529x735px) Image search: [Google]
smug_ran5.png
325KB, 529x735px
>>60810844
Clear[\[Infinity]];
\[Infinity] = -1/12;
>>
Wait, so in Scheme, defining functions is the same as defining variables?
>>
>>60813167

It can be, but there's also a syntactic sugar (which you should be using) that cannot be used for ordinary variables.
>>
>>60813167
>in Scheme
Stopped reading right there.
>>
Imna start saying "syntactic nougat" out loud irl, this will be my thing
>>
What's the big deal about functions that return a list of of symbols + lists of symbols.
>>
>>60813202
Haskellfag pls go.
>implying you can do this in your lang
(loop repeat 5 thereis (parse-integer (read-line) :junk-allowed t))
>>
>>60813293
>Haskell
Stopped reading right there.
>>
>>60813320
Cfag pls go
>implying you can do this in your lang
(mapc #'print '(1 2 3))
>>
>>60813061

I bet you don't even put your curly braces on a new line.
>>
>>60813258
What
>>
File: 1485127305074.png (281KB, 676x669px) Image search: [Google]
1485127305074.png
281KB, 676x669px
>>60813375
>C
Stopped reading right there.
>>
>>60813401
Lisps pride themselves because some of their functions returns lists of symbols.
What's the big deal
>>
>>60813426
Javafag pls go
>omplier you can goo this in lang
char (*(*x[3])())[5]
>>
>>60813472
What's wrong with expressing that?
>>
File: 1484429074416.png (99KB, 288x390px) Image search: [Google]
1484429074416.png
99KB, 288x390px
>>60813472
>Java
Stopped reading right there.
>>
>>60813498
Stoppedfag pls go
>implubo you can hoob this in yuor lenguaje
Hello world!
>>
What's a better way to inline this function
def is_composite(x, a, r, n):
if x == 1:
return False
for _ in range(r):
if x == n - 1:
return False
x = x*x % n
return True

than this
if x != 1:
composite = True
for _ in range(r):
if x == n - 1:
composite = False
break
x = x*x % n
if composite:
return False

It seems ugly to set a variable and have to check it.
>>
File: java on top.png (127KB, 1250x838px) Image search: [Google]
java on top.png
127KB, 1250x838px
>>60813498
Lispfag pls go
>pliers you do this leng
>>
File: 1484851788150.jpg (39KB, 289x308px) Image search: [Google]
1484851788150.jpg
39KB, 289x308px
>>60813520
>Stopped
reading right there.

>>60813554
Lisp
Stopped reading right there.
>>
>>60813523
Why are you inlining it?
If you want to restrict its scope as to not create problematic code dependencies make it local in some way. I don't know what python has but I'm sure there's something appropriate.
>>
>>60813568
Could you get progressively more smug instead? This is boring.
>>
>>60813568
mefag pls go
>plywood can doyelife
*get a job*
>>
File: 1496955665695.jpg (898KB, 1570x1876px) Image search: [Google]
1496955665695.jpg
898KB, 1570x1876px
>>
File: 1484589609504.png (439KB, 720x720px) Image search: [Google]
1484589609504.png
439KB, 720x720px
>>60813594
>me
Stopped reading right there.
>>
>>60813606
hahahahah ebic XDXDXDDDDD---:DD rofl lmao :DD :P xP
>>
>>60813606
>Assembler
Are you 12?
>>
>>60813571
>Why are you inlining it?
Because the function call overhead is significant. I hate how you have to make your code uglier and repeat itself if you require performance. And this isn't an issue with Python's speed, it applies to C,C++, etc as well.
>If you want to restrict its scope as to not create problematic code dependencies
That's not a problem, the problem is inlining it make it uglier by introducing a variable, a check, a reassignment, and a break statement, and its purpose becomes less clear.
>>
>>60813606
C and C++ are botnet (all modern cars phone home with telemetry + data outside the scope of telemetry). Python looks safe, though.
>>
>>60813730
>C++
Worst language in the history
>>
>>60813654
I concede, you win.
>inb4 stopped reading right there
>>
>>60810991
This will page fault
>>
>>60813699
Yes I know inlining is an optimization but you're using python. You've thrown any idea of writing fast software out the window. It'd be wiser to just call out to C if you actually needed some speed.
And FYI people usually don't manually inline things because it's something the compiler is supposed to handle. Usually you modify the code so the compiler gets it can inline it productively.
>that's not a problem
It may not be your problem.

If your problem is that the code is too slow there just write a trivial implementation in C and be done with it. I don't see how the function can overhead can be that significant given you have a loop that does a mul and a mod on a type which I doubt python can know ahead of time. Calling a function shouldn't be that terrible.
>>
Stopped reading right there.
>>
Which visual studio code theme do you guys use?
>>
>>60813769
Not necessarily.
>>
>>60813814
Well, on any modern OS using paging anyways.
>>
File: 1493190621920.jpg (27KB, 640x360px) Image search: [Google]
1493190621920.jpg
27KB, 640x360px
>>60813743
>I
Stopped reading right there.
>>
File: whatalad.jpg (60KB, 640x640px) Image search: [Google]
whatalad.jpg
60KB, 640x640px
Java scrub rite 'ere. Listen, so much fucking aids went down when my friend asked me to help refactor his RSPS source that he ripped, so I was like yeah cool whatever AND WOULDYA LOOK AT THIS

else if (getId() == 20767) {
itemRequiriments.put(Skills.ATTACK, 99);
itemRequiriments.put(Skills.DEFENCE, 99);
itemRequiriments.put(Skills.STRENGTH, 99);
itemRequiriments.put(Skills.HITPOINTS, 99);
itemRequiriments.put(Skills.RANGE, 99);
itemRequiriments.put(Skills.PRAYER, 99);
itemRequiriments.put(Skills.MAGIC, 99);
itemRequiriments.put(Skills.RUNECRAFTING, 99);
itemRequiriments.put(Skills.AGILITY, 99);
itemRequiriments.put(Skills.HERBLORE, 99);
itemRequiriments.put(Skills.THIEVING, 99);
itemRequiriments.put(Skills.CRAFTING, 99);
itemRequiriments.put(Skills.FLETCHING, 99);
itemRequiriments.put(Skills.SLAYER, 99);
itemRequiriments.put(Skills.HUNTER, 99);
itemRequiriments.put(Skills.MINING, 99);
itemRequiriments.put(Skills.SMITHING, 99);
itemRequiriments.put(Skills.FISHING, 99);
itemRequiriments.put(Skills.COOKING, 99);
itemRequiriments.put(Skills.FIREMAKING, 99); itemRequiriments.put(Skills.WOODCUTTING, 99);
itemRequiriments.put(Skills.SUMMONING, 99);

}


This is the most fucking aids I've actually seen for a game. REALLY?! Just make a fucking array and iterate through.

REEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
>>
>>60813833
>their
Stopped reading right.
>>
>>60813860
Yeah he's doing data definition in code.
It's not as bad as you think but it's not good.
>>
>>60813887
I understand it's okay to do don't get me wrong but with the way this source communicates it has to be done through an array, there was already one made so why they did it like that I don't know.
>>
What actual complaints do you have on gtk and do you like Qt any better?
>>
>>60813860

>that he ripped
So this is decompiled code?
>>
>>60813926

Loop unrolling performed by compiler.
>>
>>60813793
>You've thrown any idea of writing fast software out the window
Yes, but native Python code can be optimized in relation it itself.
>And FYI people usually don't manually inline things
As far as I know, CPython doesn't support this, so you have to hardcode manually.
>Calling a function shouldn't be that terrible.
When called:
$ python3 -m cProfile -s time test5.py 
2157639 function calls (2157606 primitive calls) in 2.768 seconds
ncalls tottime percall cumtime percall filename:lineno(function)
578245 0.462 0.000 0.462 0.000 primes.py:56(is_composite)

And when inlined:
$ python3 -m cProfile -s time test5.py 
1579394 function calls (1579361 primitive calls) in 2.514 seconds

So 578245 function calls add an overhead of ~250 ms. But you're right, even the most unoptimized C code will outperform optimized CPython.
>>
>>60808860
Writing an interpreter in Haskell for an assignment. Changing functions to first class values currently. The task was divided into parts and earlier they were supposed to be second class and I don't really like how we have to modify the code now, I'd prefer we had had to make them first class from the beginning.
>>
I got two strings a and b in Rust, how can I check if a[3..8] == b[5..10]?
>>
>>60810320
>>60810322
>>60810432

i found this website that does a tear down of the keyboard, do any of the pictures give you a better idea of what might be necessary?

https://translate.google.com/translate?hl=en&sl=zh-CN&u=http://www.pinwaishe.com/wspc/9712.html&prev=search
>>
>using the dpttxt twitter picture

Didn't know /prog/ers were still around
>>
>>60813793
>And FYI people usually don't manually inline things because it's something the compiler is supposed to handle.
Fuck yeah they do, there's always a function or two there that take fucking shittons of time but not even always_inline fucking inlines for some reason. In real time applications its not uncommon at all people write macros instead of inline functions, or just straight up copy paste.
>>
File: tAnqryCup2E.jpg (32KB, 705x1020px) Image search: [Google]
tAnqryCup2E.jpg
32KB, 705x1020px
struct String {

int length;
char *p;
String(char *pt) {
length = strlen(pt);
p = (char*)malloc(length+1);
}

};


What's C++ analog for
p = (char*)malloc(length+1); ?
>>
>>60814252
p = new char[length + 1];


and
delete [] p
to free p.
>>
>>60814088

Well, I don't have a lot of experience with Rust, but check this out:

pub fn main() {
let a = "hello world";
let b = "xxhello world";
let a_iter = a.chars().skip(3).take(5);
let b_iter = b.chars().skip(5).take(5);
let mut zip = a_iter.zip(b_iter);
let eql = zip.all(|tup| tup.0 == tup.1);

println!("{}", eql);
}
>>
>>60809936
Diverse in career options you sperg
>>
>>60814278

what happens if I use regular delete on a new[]? Or vice versa.
>>
File: download_2.jpg (8KB, 206x156px) Image search: [Google]
download_2.jpg
8KB, 206x156px
>>60814283
>>
>>60814385
>ribbit the reddit frog
>>>/r/abbit/
>>
File: 1479596863096.png (20KB, 640x480px) Image search: [Google]
1479596863096.png
20KB, 640x480px
>>60814392
>>
>>60813293
what does this even do
>>
>>60814385

Meh. I hacked it together rather quickly. It solves the problem for arbitrary UTF-8 strings without needing O(n) access time on each character. Not sure how efficiently the Rust compiler is able to process all of the iterators at this time though.
>>
>>60814512
That's something that shouldn't have to be "hacked together"
>>
>>60814548
Where did you get this idea?
>>
>>60814556
It's called an opinion, autismo.
>>
>>60814576
>opinion
discarded
>>
>>60814586
Not an argument
>>
>>60814634
>argument
invalid
>>
So I just started learning C++ from scratch. I also recently started playing GTA V again. Is it possible to code my own meme menu with C++?

Better yet, what kind of shit can I use this for. Like what kind of programs can I use it to make?
>>
>>60814725
>meme
>games
>code
Your kind isn't welcome here. Piss off.
>>>/v/
>>
>>60814725
Jesus christ being new is so cringy
>>
>>60814548

I'm sure there's a cleaner solution. I'm not that well used to Rust's iterators.
>>
>>60814725
>C++
Stopped reading right there.
>>
Do you shower everyday /dpt/?
>>
>>60814725
>meme
>>>/v/
>>
>>60814774
Nope.
>>
>>60814749
>>60814752
>>60814763
>>60814798

Alright memelords, I get it, I'm gay. Now what the fuck can I do with this.
>>
>>60814813
>memelords
>ribbit spacing
Fuck off. Your kind isn't welcome here.
>>>/v/
>>
>>60814823
>>>>/trash/
>>
>>60814725
>Is it possible to code my own meme menu with C++?
what did he mean by this
elaborate
>>
>>60814837
>improper formatting
>>>/r/abbit/
>>
>>60814725
Seriously, stop falling for the C++ meme. Let it die.
>>
>>60814813
>>60814893
>meme
>>>/v/
>>
File: niggerloli.jpg (175KB, 1280x1329px) Image search: [Google]
niggerloli.jpg
175KB, 1280x1329px
Meet Rust chan! She is the true successor to C++.
>>
>>60814847
Slang for mod menu.
>>
>>60814941
> she
>>
>>60814941
Is she black?
>>
>>60814941
I know people dislike Rust but Jesus that looks like trash.
>>
What a particularly awful thread, everyone.
>>
>>60814953
Rust chan loves you
>>60814951
Yes
>>60814948
Yes
>>
File: what are birds.gif (1MB, 249x250px) Image search: [Google]
what are birds.gif
1MB, 249x250px
>>60814725
>meme menu
>>
>>60814973
>Yes
Oh... I'm not going to use her then.
>>
>>60814974
>>60814947
>>
File: yukari_disgust.png (29KB, 287x201px) Image search: [Google]
yukari_disgust.png
29KB, 287x201px
>>60814725
Sorry I don't speak RETARDESE
>>
>>60813860
why not create an array for those skill types and then call them after the "." proceeding "Skills"?
I feel like that would shorten it by a lot.
>>
>>60812662
>functional
What is ``Functional" though?
>>
>>60815140
A fashion statement
>>
File: wQRMfVTA3S4.jpg (329KB, 1038x1024px) Image search: [Google]
wQRMfVTA3S4.jpg
329KB, 1038x1024px
>>60814252
Next question.

How do I overload an operator+ for this struct? I want to be able to concatenate my own string.

typedef struct String {

int length;
char *str;
void print();
unsigned getLength();

String(char *ptr) {
length = strlen(ptr);
str = new char[length + 1];
}
~String() {
delete[] str;
}

String& operator+(const String& strs) {
// return String s();
}

};


strcat might be used, however, I don't understand how.
>>
>>60815191
You didn't explain what ``Functional" is, you just said what category of things it belongs to.
>>
>>60815195

Return type is a new string, not a reference to something.

You want to return with a call to the constructor of a new string
>>
>>60815195
Reallocate str to fit the size of the concatenated string and use strcat to concatenate this.str with strs.str.

Other remarks: you're not overloading the + operator, you're defining it. Also, in C++, no need to typedef your struct type, you can refer it as String elsewhere without the struct keyword.
>>
>>60815294

>Other remarks: you're not overloading the + operator, you're defining it.
If you're defining a function with different argument types to the function with the same name which is already defined, that's overloading.
>>
File: 1488321566939.jpg (8KB, 247x248px) Image search: [Google]
1488321566939.jpg
8KB, 247x248px
>mfw this thread
Do you guys even kode?
>>
>>60815317
You're right.

>>60815271
Depends. I think what >>60815195 is trying to implement is the "+=" operator, which actually appends strs to *this. What you describe really is the "+" operation for strings.
>>
>>60815356
no
>>
"dereferencing a null pointer is undefined behavior, it can do anything"
>writes a compiler that launches a nuke every time a null pointer is dereferenced
muahaha
>>
Is there a specific term for a compiler that targets the same system it runs on? In other words, is there something that means "a compiler that isn't a cross-compiler?"
>>
>>60815602
.. A native target compiler ?
>>
>>60815356
>mfw this thread
Everything in your post reeks of reddit.
Seriously: piss off. Your kind is not welcome here.
>>
>>60815626
why do you even exist?
>>
>>60815626
You've literally never posted anything programming related.
>>
>>60815642
It seems like you're new on this website.
Go be retarded somewhere else, like at reddit.
>>
>>60813860
literally what is wrong with this and how can it be improved?
>>
>>60815661
>If it's stupid and it works then it's not stupid
That being said the ideal way would be to load the data at start from a file.
>>
>>60815584
Nothing prevents from launching nukes at each semicolon. The only difference would be that your compiler would not be a strict C compiler anymore.
>>
>>60815684
answer the question and provide a code snippet that you think would be better
>>
>>60815693
I answered. How about you think about the implementation yourself you lazy fuck.
>>
>>60815703
>literally autistically screeching about code style
>cant think of anything better
"ok"
>>
>>60815692
my nuke launching compiler would be a strict c compiler
>>
>>60815716
>do my homework for me
>>
http://blog.ielliott.io/why-LINQ-is-broken/
>>
>>60815716
>"here's the design commonly used to solve this problem in the most flexible way"
>Dear Sir this is too hard Sir please provide Java code I can copy/paste Sir.
>t. Pajeet
>>
>>60815722
That's exactly what I meant, but my wording was sloppy. In other words, it doesn't take a strict C compiler to launch nukes.
>>
>>60815784
>>60815726
Just pointing out that /dpt/ has no coding ability and can only complain and never contribute.
>>
>>60808860
How does Linux decide what core to bind a thread/process to? I've read a few articles on CFS, but none of them mention that. Is that handled somewhere else? I know you can manually set the CPU affinity, but what if you don't?
>>
>>60815798
You asked what's wrong and he answered you. If you can't implement a simple ini reader you should stay on codecademy a bit longer.
>>
>>60815798
>coding
>>>/g/wdg/
Your kind isn't welcome here.
>>
>>60815814
Not programming related.
Ask on >>>/g/fglt/
>>
>>60815856
why do you exist?
>>
>>60808880
What am I looking at?
>>
>>60815879
C++ traits
>>
>>60815824
>codecademy
see >>60815856
>>
File: 02Catwoman01FinaleArtwork.jpg (351KB, 1600x2500px) Image search: [Google]
02Catwoman01FinaleArtwork.jpg
351KB, 1600x2500px
Absolute pleb question.
If I were to get into programming for the sole purpose of creating an open source alternative to Daz Studio, what programming language should I start on? Python?
I know this is the typical hurdur, gotta walk before you run a marathon. I'm just curious.
>>
>>60809991
yes it's called switching to Rust
>>
>>60810668
Why do you have the \b? Pretty sure it matches white space and your string doesn't have any white space in it.
>>
>>60813143
You're finally graduating? Congrats fellow programmer (male) (female)
>>
>>60814973
Tell her, i don't like her
>>
>>60815940

>Google Daz Studio
>3D rendering/animation suite
Don't use a slow language like Python. I would recommend a high performance language such as C++ or Rust. My general recommendation for starter languages is C, which is also fast, but lacks many of the useful abstractions that will make developing large applications easier.

>>60816076

Male. Exclusively male.
>>
>>60816162
Congrats fellow programmer (male)!
>>
New thread:
>>60816224
>>60816224
>>60816224
>>
>>60814083
That's very surprising. That's an absolutely massive cost for function calls.
They should work on fixing that.
>>
>>60813293
literally what does this code do when run?
>>
>>60817032
Gives you a tuggie.

Why don't you fucking run it?
Thread posts: 315
Thread images: 28


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