[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: 341
Thread images: 30

File: non anime picture.png (29KB, 267x448px) Image search: [Google]
non anime picture.png
29KB, 267x448px
Previous: >>57613373

What are you working on, /g/?
>>
>XKCD
I fucking hate you
>>
literally nothing

I haven't accomplished anything in the last 3 months

other than smoke like so fucking much weed wow
>>
File: gold-medal.png (20KB, 246x242px) Image search: [Google]
gold-medal.png
20KB, 246x242px
>>57619390
That pic is so true. Here a medal for you.
>>
I fucking dare you guys to average two ints in C

Pro tip: you can't
>>
>>57619434
That one is old.
>>
What do you call a function that takes some arguments and return a instance struct that has fields set according to the function arguments?
>>
>>57619434
If you can't do it in C, what language can you do it in..?
>>
>>57619456
A "constructor".
>>
File: shot0033.jpg (310KB, 1920x1080px) Image search: [Google]
shot0033.jpg
310KB, 1920x1080px
>>57619434
int average (const int x, const int y) 
{
if ((x < 0) ^ (y < 0))
return (x + y) / 2;
const int xh = x / 2;
const int yh = y / 2;
const int xhr = x % 2;
const int yhr = y % 2;
return xh + yh + (xhr & yhr);
}
>>
File: k&r.jpg (475KB, 852x973px) Image search: [Google]
k&r.jpg
475KB, 852x973px
I've decided that I want to become a developer at a quant hedge fund.

I have good python and SQL, but no real dev experience or a CS degree, so I've got a fucking mountain to climb.

I understand I'll need incredible C++ for it. What else do I need to focus on? I have some Java and C, so I don't see learning C++ as too much of a thing, but what else should I be focusing on?

I'll probably need a proper developer job between now and getting there, but this is more of a stretch goal.
>>
>>57619434
I'll bite

(a + b)/2
>>
can we please have a dedicated mod in /dpt/ that bans people for not posting anime in OP? especially XKCD
>>
>>57619483
>anime image
>akarin
>const everywhere
o/
>>
>>57619434
 unsigned int average = (a / 2) + (b / 2) + (a & b & 1); 
>>
>>57619473
MyStruct s = MyStructConstructor("foo", 43);

Like this?
>>
>>57619497
Connections. You wanna work at a hedge fund? You'll need connections more than a degree.

After that, data structures and algorithms.
>>
File: anal beads.png (410KB, 1137x465px) Image search: [Google]
anal beads.png
410KB, 1137x465px
>>57619390
>5 years to detect birds
Use a cognitive API.
>>
>>57619502
HURR DURR SIGNED OVERFLOW IS UNDEFINED
>>
>>57619536
What
>>
Working on my terminal emulator, addingg macOS support because that seems the easy to do before Windows.

Working with cocoa in Rust is a huge pain in the ass, especially since I never worked with it before.
>>
>>57619434
I would've told you but it's patented
https://www.google.com/patents/US6007232?dq=6007232
>>
>>57619569
if (a+b) is greater than maxint then something terrible happens
>>
>>57619531
Any good resources for learning algorithms? They're something that's missing from my skillset atm. Think we have a copy of Hacker's Delight at work, seem to remember that talking about it.

Got a few banker m8s who might be able to point me in the right direction, so I'll get something that way, in addition to randomly reaching out to people in the industry.

Any particular books etc. you'd recommend for those?
>>
>>57619464
Languages that abstract data better?

Python can do it just fine

>>57619502
Nope, Check 4294967295 and 5000

>>57619513
Nope. Check -3 and 3.
>>
>>57619434
lo = min(a,b);
hi = max(a,b);
return lo + (hi-lo)/2;
>>
>>57619464
Ada
>>
>>57619631
SICP
>>
>>57619434
int _ret = a/2 + b/2;
if (a%2 == 1 && b%2 == 1) _ret += 1;
>>
anyone has the updated programming challenge list?
otherwise give me some begineer projects in Java
>>
>>57619620
Then don't do that
>>
>>57619434
__float128 average(short int a, short int b)
{
__float128 c = (a/2)+(b/2);
return c;
}
>>
>>57619569
In the C standard, overflow during signed integer operations is undefined.
If you two positive ints and get something larger than INT_MAX, or two negative ints and get something smaller than INT_MIN, that's undefined behaviour. Which means, as the old joke has it, the compiler can generate pretty much any machine code it sees fit, including one that makes demons fly out of your nose.
>>
>>57619676
Cheers m8
>>
>>57619688
https://better-dpt-roll.github.io/

>anon is forcing https but doesn't have a redirect
Gay.
>>
>>57619390

Use clarfai or something similar.

>reinventing the wheel
>>
>>57619611
>https://www.google.com/patents/US6007232?dq=6007232
wew
>>
>>57619746

what was that about https?
>>
>>57619434
int lo = min(a, b);
int hi = max(a, b);
int answer;
for (int i = lo; i <= hi; i++) {
if ((i-lo) == (hi-i)) break;
if ((i-lo) == ((hi-i)-1)) break;
}
answer = i;
>>
>>57619775
If you navigate to the site without https, you get a 404.

That site should have a http binding that redirects to the https version, rather than 404'ing.
>>
Any python-experts here?

I'm creating a django web-application. It is going to scrape the ever-living shit out of pixiv, danbooru, deviantart etc...

The question is, how do I proceed? I already came up with some efforts that were in my view, failures. I attempted to use celery to fetch each pixiv image/page, but that proved to be a mess because I'd have to put everything into redis, and everything has to be pickled or dilled, serialized.

I just don't know how to proceed.
>>
>>57619649
Abstract primitives are fucking cancer, dude
>>
>>57619790
https 404s for me. http is the only one that works
>>
>>57619790
i can open the site but when i press roll nothing happens :(
>>
I'm designing a YouTube archival system and I'm running into some trouble on storing information and files.

Let's say I have a video archive, which will have infomation about the video url, video file location, HTML page file location and archive parameters infomation. (I also plan to tracking channels and playlists with some other data structures.)

One approach I was thinking about is having a SQL database where each video archive could be an entry in a table. The information about the archive parameters, video url, video file path and HTML page file path could be stored in the columns. But I'm unsure if storing file paths is a good idea with this approach.

Another approach could be using XML files to store the archive parameter data and file path data.

What is a good approach to storing and managing information like this?
>>
I've heard lambda calculus is good and helpful, but I don't immediately see how. Does it give any practical knowledge for anything but functional programming? What is it practically used for?
>>
File: 1473056468658.png (65KB, 977x785px) Image search: [Google]
1473056468658.png
65KB, 977x785px
Is there a computer science equivalent?
>>
File: cardboard computer.jpg (106KB, 600x800px) Image search: [Google]
cardboard computer.jpg
106KB, 600x800px
>2017 - 0.08333
>not programming in cardboard and marbles
https://lapinozz.github.io/learning/2016/11/19/calculator-with-caordboard-and-marbles.html
>>
>>57619660
hi = INT_MAX
lo = INT_MIN
>>
>>57619864
>total price: $240
absolutely disgusting.
>>
>>57619434
a/2 + b/2 + (a%2 + b%2)/2
>>
>>57619832
SQL
>>
>>57619832
>file location
>html file location
Unless static pages are a must, you can use any server-side language and just use URLs like "/video/ID-NUMBER/download".
If you're concerned about using sequential row IDs, generate a unique alphanumeric ID and use that instead.
>>
>>57619390
>xkcd
gtfo nigger
>>
>>57619434
template<int A, int B>
struct average
{
template<int X, bool Half>
struct result_type
{
static constexpr int value = X;
static constexpr bool half = Half;
};
using result = result_type<((A + B) >> 1), !!((A + B) & 1)>;
};
>>
>>57619922
why does C++ with every next release look even more like a kludge on a kludge on a kludge?
>>
File: c++ in a nutshell.png (72KB, 1016x98px) Image search: [Google]
c++ in a nutshell.png
72KB, 1016x98px
>>57619943
>>
>>57619864
1. Read SICP
2. don't not read SICP
>>
How does <Compiler Explorer> https://godbolt.org/ knows which line produce each instructions set?
>>
xkcd is fun
>>
>>57619922
>stupidsepplesuseofstatickeyword somethingeverycompilerwilldetermine int value = X;
sepples is turning into java with a couple of very ill-considered features mimicked from functional languages
>>
>>57619943
Because it is.

C++17 is designed to let compilers be backwards compatible with C++98. C++98 code needs to be able to be compiled on C++17 compilers, or else people get upset that they can't use stupid shitty code.

I mean, just imagine what it'd be like if you realize your code can't compile in the latest version of C++, so you need to be stuck on earlier versions until you port 50,000 lines of code that was originally designed to be ran on 90s era hardware.
>>
>>57619782
That is so disgusting, but correct.
>>
>>57619434
return 0.5f * (x&0xFF + y&0xFF);

ez ez
>>
>>57619922
>overflows at compile time
>>
>>57619943
>>57620049
i mean your choices are between wrapping calls to older languages (like Python wraps C/C++, just as they wrapped Fortran numerical calls) or supporting backwards compatibility in the language itself, in which case you either get no modern features, or your modern features have kludge syntax

there's this romantic notion that one day we'll rewrite shit in modern languages that unfortunately isn't realistic because it doesn't respect how much work has really gone into intrastructure. when you reimplement infrastructure you get garbage like Hadoop and Spark
>>
File: 1478627983236.png (350KB, 1000x1000px) Image search: [Google]
1478627983236.png
350KB, 1000x1000px
in PyQT5, is there a convenient way to keep the UI bullshit away from the main program?
>>
What is a good way to learn python ?
Codecadamt is not that good as far as I heard you guys.
>>
>>57619434
((long long int)a + b)/2
>>
>>57620168
Find a good course by a good university. CMU seems to have a good intro to programming course in Python.
>>
(* camlavg.ml *)
open Num;;

let avg s1 s2 =
let n1 = num_of_string s1 in
let n2 = num_of_string s2 in
let avg = (n1 +/ n2) // Int 2 in
string_of_num (integer_num avg)
;;

let () = Callback.register "avg" avg;;

/* main.c */
#include <stdio.h>

#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/callback.h>

static value *closure_avg = NULL;

static char *argv[] = { "", NULL, };

extern void caml_main (char **);

int avg (int a, int b) {
char *ret;
char buff[200];
int reti;
CAMLparam0 ();
CAMLlocal3 (res, sa, sb);
if (closure_avg == NULL) {
caml_main (argv);
closure_avg = caml_named_value ("avg");
}
sprintf (buff, "%d", a);
sprintf (buff + 100, "%d", b);
sa = caml_copy_string (buff);
sb = caml_copy_string (buff + 100);
res = caml_callback2 (*closure_avg, sa, sb);
ret = String_val (res);
sscanf (ret, "%d", &reti);
CAMLreturnT (int, reti);
}

int main (int argc, char **argv) {
int a;
int b;
int c;
sscanf (argv[1], "%d", &a);
sscanf (argv[2], "%d", &b);
c = avg (a, b);
printf ("avg (%d, %d) == %d\n", a, b, c);
return 0;
}

# make.sh
#!/bin/sh -ex

ocamlopt -c camlavg.ml
ocamlopt -output-obj -o camlcode.o nums.cmxa camlavg.cmx
gcc -I$(ocamlopt -where) -c main.c
gcc -L$(ocamlopt -where) -o avg main.o camlcode.o -ldl -lnums -lm -lasmrun
>>
>>57620210
Did someone hurt you when you were a kid?
>>
>>57619434
>>57619670
declare
type Decimal is delta 0.1 range Float(Integer'First).. Float(Integer'Last);
A,B,C : Integer;
begin
C := Integer(Decimal(A)/2.0 + Decimal(B)/2.0);
end;
>>
>>57620168
I'm using 'Think Python - How to Think Like a Computer Scientist' and it's good so far. If you don't like the sound of learning from a book you could always try YouTube, there must be more tutorials for Python than anything else at this point.
>>
>>57620121
And when you let infrastructure sit around you get Heardbleed and Shellshock
Software is shit :=/
>>
>>57620295
Are you implying that that won't happen with software that gets rewritten every 2 years?

There's even a greater chance of that happening 2bh
>>
>>57619864
>DEVOTE EVERY ASPECT OF YOUR LIFE TO LEARNING MATH 24/7 FOR LIKE A YEAR
>ITS EASY TO GIT GUD IT JUST COSTS A FEW HUNDRED DOLLARS AND REQUIRES BEING COMPLETELY AUTISTIC
nobody actually takes this advice
>>
Need a good word for a table name. The table describes files that have been posted, submitted.

The table describes files that are incoming, are received, and have yet to be processed to be entered into the system.
>>
>>57620337
input_table
>>
>>57620337
inbox
>>
>>57620332
Well, a lot of modern tools and "software methodologies" would theoretically be less bug prone if you did it all over again.
I just think we need to move away from C.
>>
>>57620337
t
>>
>>57620168

Are you learning for the sake of learning, learning with the intention of seeking work, or learning to complete a project?

I got started due to option (3). It makes it a lot easier and enjoyable to self-teach if you have some endgame goal in mind.
If you're a fan of math, the daily Project Euler projects are a nice way to get it all going.
>>
>>57620239
Why the fuck not just use libgmp instead of all this cs-undergrad-meme-tier bs
>>
>>57620397
Now you have two problems
>>
>>57620347
>>57620350
Both sensible suggestions, although it doesn't tell me what is in the table. file_inbox, file_input could work, but I'd like for the table name to also describe a single entry.

e.g there's a table named gallery_file, which tells you what you'll find in the table and also describes a single entry.

>>57620387
Why would you do that
>>
>>57619408
What's wrong with xkcd?
>>
>>57620158
The techniques are the same regardless of language or UI toolkit.

How much it costs (in terms of added complexity) depends upon the nature of the program.
>>
>>57620428
Guess
>>
#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[])
{
int len = strlen(argv[1]);
int halflen = (len-1)/2+1;
for(int a = 0; a < halflen; a++)
{
if(!(argv[1][a] == ' ' | argv[1][len-1-a] == ' '))
{
if(!(argv[1][a] == argv[1][len-1-a]))
{
printf("No");
return 0;
}
}
}
printf("Yes");
return 0;
}

I got palindrome detector on the DPT roller. rate
>>
>>57620460
Fucking tell already
>>
>>57619529
Just move to C++, you'll like classes.
>>
>>57620466
I think you're trying to skip spaces, but you will only skip spaces that are at the same distance relative to the start and end. The outer 'if' is redundant. If you want to skip spaces you'll need to track the offset from start and end of phrase separately, I think.
>>
>>57620158
>[..] QT [..] convenient [..]
No.
>>
>>57620612
What should i use then?
>>
>>57619536
(int)(((int64_t)a+(int64_t)b)/(int64_t)2);
>>
>>57620622
gtkmm
>>
>>57620428
>>57620468
not him but the guy behind these comics is a massive faggot, he was "with her" and suck dicks all day long
just to name a few things
>>
>>57620624
And if int is 64 or longer?

>Code monkeys will always code monkey.
>>
>>57620466
>no functional programming
2/10
def palin(string):
if len(string)==1 or len(string)==0: return True
return palin(string[1:-1]) and string[0] == string[-1]
>>
>>57620644
>falling for such a simple b8
>>
>>57620659
Ho shit. Now I'm ashamed.
>>
>>57620655
ok, you failed the simplest test I could come up with: "b ob"
>>
Is there any reasons to use impure functions with side effects in C?
>>
>>57620644
Then you would use >>57619483
>>
>>57620466
(>>57620563) Here's my non-alphabetical skipping solution:
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int check_palindrome(char *check)
{
char *start = check;
char *end = check + strlen(check) - 1;

while (start < end)
{
if (!isalpha(*start))
{
start++;
continue;
}

if (!isalpha(*end))
{
end--;
continue;
}

if (*start != *end)
return 0;

start++;
end--;
}
return 1;
}

int main(int a, char **v)
{
for (v++; *v; v++)
{
printf("%s: %s a palindrome\n", *v,
check_palindrome(*v) ? "is" : "is not");
}
}

% ./a.out "a" "abc" "madam i'm adam"
a: is a palindrome
abc: is not a palindrome
madam i'm adam: is a palindrome
>>
File: wf3.png (79KB, 1327x1056px) Image search: [Google]
wf3.png
79KB, 1327x1056px
RIP-relative addressing now works in my Forth compiler, so all code and data references are relocatable.
The assembly core is now mostly complete, just need to do some cleanup of the printing routine (trim those leading zeros and make it work in bases other than hex) and the input/output stuff should print the classic " ok" on the same line ,etc.
Rest will now be written in Forth itself (including the code optimizer).
>>
>>57619434
can someone explain to me why this would be hard?
>>
>>57620743
May I ask why you are doing this?
>>
>>57620755
corner case
>>
>>57620755
try to average two INT_MAX
>>
>>57620679
"b ob" is not a palindrome though.

If they want to include spaces, then remove the spaces before calling.
>>
>>57620755
Overflowing two numbers when you add them, and rounding
You could do
const int x_half = x/2;
const int y_half = y/2;
return x_half+y_half;


But you couldn't safely do
return (x+y)/2;

Because if x+y is greater than 2^32, you get a negative number.
>>
>>57620767
if it's a 32bit int, just use a 64bit int
>>
Database-question:

A table is named file.
A file has a source.
A file already has a tag relation.

Good arguments for/against implementing the source as a tag?
>>
>>57620787
>"b ob" is not a palindrome
it's okay, not everyone is built for success, you'll always stay NEET

>>57620799
same thing for you
>>
>>57620799
int isn't guaranteed to be 32-bits, but 99% of the time it is
>>
anybody know a good anime about programming?
>>
>>57620828
>programming a palindrome checker is a method to check if someone is successful
get rekt son i'll fuck u up bitch
>>
>>57620845
not being able to programming a palindrome checker is a good sign that someone isn't succesfull
>>
>>57620828
he's right, though. "b ob" backwards is "bo b". they are clearly different.
>>
>>57620787
>"b ob" is not a palindrome though.
https://en.wikipedia.org/wiki/Palindrome#Sentences_and_phrases
>>
>>57620760
I really like Forth and there doesn't really exist any good free native code compilers (especially not for x64).
Plan is to built up a complete IDE (compiler, debugger and editor specially built for Forth code) and use it for writing programs in, and eventually my own OS based on Forth (I'm thinking a 64 bit, identity mapped one ala TempleOS - no paging is very suited to Forth so you can easily share dictionaries and code/data space between programs - but I'm at least gonna strive for truecolor graphics and HD resolution, not gonna care about gpu accel though, just vbe).
>>
So I'm learning python (yes I get it you prefer x but I've made the choice that python is best for me) anyway next year I want ot do atleast one project a month here's what I have so far
encrypted client/server chat service
encrypted facebook chat client
countdown timer using config files
implied probability calculator
print if a word is even or odd
bingewatch calculator

what else could I add?
>>
File: g programming challenges.png (302KB, 1920x1080px) Image search: [Google]
g programming challenges.png
302KB, 1920x1080px
>>57620932
>>
>>57620918
https://en.wikipedia.org/wiki/Palindrome
faggot
>>
>>57620926
Why would you want to make your own OS? Take that time developing and put it towards a big FOSS project, and put that on your resume.
>>
Are C++ programmers likelier to be racists?
>>
>>57620993
>likelier
typical nigger
>>
yes lads, quick question
ive been using System.out.printf("%s[%s] %8s %23s%n" to format bla bla bla
but now ive had to change sysout... to array.add("bla bla bla+ bla" how do I use format with .add instead?
Yes I know im stupid
Thanks
>>
what C++ exception do i throw for "programmer errors", for example accessing some resource before it has been opened
runtime_error seems the most approriate but it doesnt quite fit imo
>>
>>57620979
If that's your definition of a palindrome, your original solution was incorrect.
>>
>>57621033
>my original solution
I never posted one
>>
>>57621027
there's also logic_error, but why won't it fit? You can also throw integers and write a function that parses it with a switch
>>
>>57620987
>Why would you want to make your own OS?
Because most OSes are disgustingly complex and bloated with layers upon layers of abstraction between everything, it's just very tedious and boring to program for.
>>
>>57621055
Then stay out of the discussion.
>>
>>57621075
kek, stay mad
>>
>>57621071
Wouldn't it make sense to learn the APIs for existing systems that people use before you decide to make your own OS entirely? Especially given how a lot of libraries abstract that out like SDL
>>
>>57620926
>truecolor graphics and HD resolution
>on x86(_64)
Won't happen
>>
>>57621027
class YouAreAStupidFuckGetBackToDebugging: public std::exception {
public:
YouAreAStupidFuckGetBackToDebugging(const std::string& message)
: std::exception(message) { };
};
>>
File: ProgrammingChallenges, 4.0 (HD).png (2MB, 3840x2160px) Image search: [Google]
ProgrammingChallenges, 4.0 (HD).png
2MB, 3840x2160px
>>57620932
>>
>>57620863
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BOOL int
#define TRUE (0 == 0)
#define FALSE (0 != 0)

static BOOL ispal (const char *s) {
size_t i;
size_t l;
l = strlen (s);
for (i = 0; i < l / 2; i++) {
if (s[i] != s[l - i -1]) {
return FALSE;
}
}
return TRUE;
}

static const char *is = "\"%s\" is a palydrome.\n";

static const char *isnot = "\"%s\" ain't a palydrome.\n";

void checkpal (const char *s) {
const char *format;
format = ispal (s) ? is : isnot;
printf (format, s);
}


const char *strings[] = {
"",
"a",
"aa",
"ab",
"aaa",
"aab",
"aba",
"abc",
"baa",
NULL,
};

int main (void) {
const char **ptr;
for (ptr = strings; *ptr != NULL; ptr++) {
checkpal (*ptr);
}
return 0;
}


Is it correct master?
>>
>>57621121
Try it on "Madam, I'm Adam"
>>
File: 2016-11-21_22:50:01.png (49KB, 482x251px) Image search: [Google]
2016-11-21_22:50:01.png
49KB, 482x251px
>>57621121
you failed
>>
File: fb.pdf.png (109KB, 1700x2200px) Image search: [Google]
fb.pdf.png
109KB, 1700x2200px
>writing paper due in a few hours
>accidentally find out about loops and counters in latex
and now I've got this

>Error: Our system thinks your post is spam. Please reformat and try again.
fuck
http://pastebin.com/CYanP5F8
>>
>>57621157
It say no because of the case and the spaces and...
>>
>>57621121
in haskell, this is just
palindrome str = reverse str == str
>>
>>57621194
Can it handle big string without out of memory?
>>
>>57621194
This would work on "Was it a car or a cat I saw?"
>>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int check_palindrome(char *check)
{
char *start = check;
char *end = check + strlen(check) - 1;

while (start < end)
{
if (!isalnum(*start))
{
start++;
continue;
}

if (!isalnum(*end))
{
end--;
continue;
}

if (tolower(*start) != tolower(*end))
return 0;

start++;
end--;
}
return 1;
}

int main(int a, char **v)
{
for (v++; *v; v++)
{
printf("%s: %s a palindrome\n", *v,
check_palindrome(*v) ? "is" : "is not");
}
}


version 2, handles case.

% ./a.out "Madam, I'm Adam" "Was it a car or a cat I saw?"
Madam, I'm Adam: is a palindrome
Was it a car or a cat I saw?: is a palindrome
>>
>>57621212
>>57621194
would not*
>>
>>57620787
> "b ob" is not a palindrome though.
Wow, ok, well... Didn't expect that to be honest... Thank you for coming, we will contact you if you get to the second round!
>>
>>57621228
nice but
>not naming int params argc and argv
>not checking for argc and argv
>>
>>57621228
int check_palindrome(const char *s)
{
const char *p = s + strlen(s) - 1;
while (s < p)
if (*p-- != *s++)
return 0;
return 1;
}
>>
>>57621099
I just enjoy low level code, I want to easily be able to do things like inline asm and just access things.
>>
>>57621194
>>57621232
you'd need something like

is_palindrome s = s' == reverse s' where
s' = map toLower . filter isAlphaNum $ s
>>
>>57621270
That doesn't handle mixed case, spaces, or punctuation.

Please try to keep up.
>>
>>57621232
>>57621212
{-# LANGUAGE ViewPatterns #-}
import Data.Char

palindrome (prep -> str) = reverse str == str
prep = map toLower . filter (not . flip elem [',',';',' ','?','\'','"'])
>>
>>57621301
>That doesn't handle mixed case, spaces, or punctuation.

it wasn't supposed to.
>>
>>57621261
>not naming int params argc and argv
No law requiring it.
>not checking for argc and argv
argc is redundant; argv is guaranteed to be zero-terminated.
>>
>>57619434
are people joking in the answers?
Just cast them into a float and get over it.
Is there a real catch?
>>
>>57621379
t. pajeet
>>
quick, write a program that proves you're not a pajeet
>>
>>57621379
>casting into a float
>>
>>57619434
cannot you just
(a+b)/2.0

?
>>
>>57621427
No. There is no floating point type in C accurate enough to make it practical.
>>
>>57621448
2 ints, average... that's like x.5 at worst... git gud
>>
>>57621427
Yes. There is a floating point type in C accurate enough to make it practical.
>>
>>57621480
>not knowing how floating point is stored in memory
>>
double has 53 bit precision, which is plenty for an int

division by two is accurate in floating point, it's division by things not powers of two where error creeps in
>>
>>57621496
>knowing how floating point is stored in memory
>>
>>57621496
just use java and stop wasting time on anime board
>>
>>57621486
"double" typically only has a 53-bit significand. "int" can be 64-bit, and such systems exist.

"long double" isn't required to be any larger than "double" (it isn't on MSVC).
>>
Why is >>57621324 better than >>57621281 ?
>>
>>57621427
try that with two INT_MAX
>>
>>57619390
> it can be hard to explain

but this is completely trivial to explain. god I hate xkcd
>>
>>57620264
Based Ada
>>
>>57621584
can you explain?
>>
>>57620264
>tfw unironically love ada
>>
still cant figure out how to get data bindings working with FsXAML without using MVVM or MVC
>>57619431
sounds like my last couple weeks
>>57620239
nv-approved
>>
>>57621622
>nv
nv?
>>
>>57621631
y-yes?
>>
>>57621552
>>57621545
Just for curiosity, is C standard library still as bad as it used to be?
>>
>>57621655
>C standard library
>bad

pick one faggot
>>
>>57621584
Do you think he meant "GPS lookup"?
>>
>>57621631
What does "nv-approved" means?
>>
File: bananaiwata.jpg (48KB, 497x585px) Image search: [Google]
bananaiwata.jpg
48KB, 497x585px
Who here has a software job AND works on side projects?

How do you do it? The last thing I want to do when I get home is code
>>
>>57621679
It means attention whoring tripfag refers to self using own tripcode
>>
>>57621673
Like there is no reason why they had to rewrite every common function existing for linux kernel. Just come on.
>>
>>57621719
Look up "freestanding environment". An OS kernel does not have a standard library available.

       -fhosted
Assert that compilation targets a hosted environment. This implies -fbuiltin. A hosted environment is one in which the entire standard library
is available, and in which "main" has a return type of "int". Examples are nearly everything except a kernel. This is equivalent to
-fno-freestanding.

-ffreestanding
Assert that compilation targets a freestanding environment. This implies -fno-builtin. A freestanding environment is one in which the standard
library may not exist, and program startup may not necessarily be at "main". The most obvious example is an OS kernel. This is equivalent to
-fno-hosted.

>>
>>57620428
Nothing, it triggers /pol/tards.
>>
>>57621766
t. redditor
>>
>>57621191
Nice.jpg.
>>
>>57620428
The ones about girls and sex are insipid, cringeworthy, and often outright creepy (especially if the name "Megan" comes up)
>>
>>57621551
they're the same
>>
>>57620817
i can't say shit without knowing the requirements of the database
>>
>>57621748
Well, c standard library was quite unpredictable.. at least few years ago. Maybe it's God-given tool now.
>>
>>57621934
If you say so. As long as you understand that is irrelevant to the reason why an OS kernel doesn't use it.
>>
>>57620655

Is calling basic recursion dynamic programming a meme or something?
>>
>>57621934
>c standard library was quite unpredictable
What do you mean by that?
Are you saying that the functions are non-deterministic or some shit?
>>
>>57621985
Can you repeat that?
>>
File: 1420099814802.jpg (13KB, 250x239px) Image search: [Google]
1420099814802.jpg
13KB, 250x239px
how do i abnormally exit a child process in c so that the wait() returns -1?

my instructor is making us put an artificial error into a child function.
>>
>>57619434
return (1 + 2) / 2
>>
>>57622038
_Exit(-1);
>>
>>57622038
Have you tried abort()
>>
Whats a good starting point for embedded device programming ?
>>
>>57622028


Is calling basic recursion "dynamic programming" a meme or something?
>>
>>57622038
If you skilled you mount the call stack until main and return non 0. If you're not skilled you use exit.
>>
>>57622111
>you mount the call stack until main and return non 0
What an extremely pointless thing to do.
I bet you think that functions should only return from 1 place too.
>>
>tfw probably going to get stuck doing WinForms at my c# junior dev job.

How fucked am I for my future?
>>
>>57622108
Thanks.

Did you misread "functional" as "dynamic"?
>>
>>57620484

> implying you need classes to do a simple struct
>>
>>57622122
Filthy code monkey.
>>
>>57619390

that's still anime it's just american niche anime
>>
>>57622059
this worked. thanks senpai
>>
>>57622155
I know that you're probably just full of shit, but what possible advantage does "return from 1 place" and "only exit from main" have?
All it does is complicate the structure of your code by having to hand all of these error conditions around.
>>
>>57622131
what would you rather do?
>>
How do i make g++ recognize [code ]#include<mylib.h>[/code] instead of
#include"../mylib/mylib.h"
?
Preferably without mucking with system PATH variables.
>>
>>57622211
You're not capable of appreciate such a thing, you only see shit everyday. You always take the easiest way. You don't know what a master can do. Try to always remount to main and return for sub processes. When you'll master that you'll start to understand what I know about coding. I'm a wizard, you're nothing.
>>
>>57622258
Don't you know how to Google?
>>
>>57621673
C standard library is pretty garbage.
There's pretty much nothing you can actually use from it.

string.h - Zero terminated strings are garbage, inefficient and horrible to use. The only functions worth using are the mem* functions, but they are trivial to write yourself.

stdlib.h - String<->number conversions are shit, terrible error handling. rand/srand garbage, qsort/bsearch garbage, memory allocation functions garbage (terrible interface, cannot be made efficient). Only sane function there is exit().

stdio.h - formatted output is fucking runtime parsing of strings every time, it's a nice interface but too slow. File functions are ok, but some redundant and shitty ones.

time.h - Fuck off, useless.

math.h - Nothing to complain about, but some functions of questionable importance, and some useful ones missing.

ctype.h - Fine.

inttypes.h - Should just be built into the language.

threading stuff - Fine I guess, but in practice not widely supported.

The rest is just a bunch of environmental querying stuff, who cares.

Any half decent C programmer can (and will) replace most of the standard library and add more utility functions anyway.
>>
>>57622279
I'm too tired to condense my post into a good search string.

It's fine. I understand if you don't want to help.
>>
>>57622252

Something that doesn't have the possibility of being replaced by WPF sometime in my life.
>>
>>57622305
CODE MONKEY
>>
>>57622305
>time.h - Fuck off, useless.
lol okay
>>
>>57622305
>Any half decent C programmer can (and will) replace most of the standard library and add more utility functions anyways
They won't replace them just because they are the most optimized functions in the program
>>
>>57622329
Clocks of non-dependable resolutions and precisions.
Conversion functions uses internal buffers making them fucking non-reentrant.
>>
Why do you faggots torture yourselves?
>>
yes lads, please help a retard out
ive been using System.out.printf("%s[%s] %8s %23s%n" to format my print outs bla bla bla
but now ive had to change sysout... to array.add("bla bla bla+ bla"
and I print my array out by using
for(int i=0; i<totalArray.size(); i++) { System.out.println(Array.get(i).toString
I cant throw a format or .f or a percent anywhere my brain is fried
and yes I know im stupid
Thanks
>>
>>57622405
Because i need a job to buy food and a roof, and programming was the least horrible thing i could think of that they would actually let me do.
>>
>>57621403
kys gay suburban teenager
you'll be replaced by an indian soon

>>57621409
yeah, what's wrong with casting into float?
>>
String concatenation.
>>
>>57622354
>because they are the most optimized functions in the program
lol no.
Most of the standard library cannot be made efficient because of their mandated interfaces.
malloc/free is the perfect example since they just return and take a single pointer, and any good alloctor must store meta data about the blocks, but because it's just a single pointer free() cannot quickly retrieve it (store hidden data before the pointer and you destroy your cache by loading useless data you're about to free)
>>
>>57622441

how did you trick them into letting you do it for money?
>>
>>57622452
kek, please tell me you're a pajeet
>>
>>57622402
Okay fair enough.

I can't think of anything wrong with plain old time(0) though.
>>
>>57622455
I haven't. Yet.
>>
>>57622453
what about it
>>
>>57622457
No, I'm not indian, but i'm not american either.
You're still going to be jobless though.
>>
Why isn't there some obvious way to write a cookie that tracks the number of visits a user has made to a given site? Seems like this is a tiny little script that should be the first google result on stackoverflow
>>
>>57622441
Who are "they" and why would "they" care what you do, let alone disallow you from it?
>>
>>57622476
what are you then? A shitskin?
>>
>>57622471
Learn it. It's the solution to your problem.
>>
>>57621613
It's impossible is ironically love Ada, since it's so great
>>
>>57622464

we're not going to make it
>>
>>57622491
concatenating strings will get me a gf?
>>
Just because the linux kernel was made in C doesn't mean C is great, in fact it took literal thousands of people to make it work.
>>
>>57622038
You can't. Exit codes are in the range 0 to 255 inclusive. exit(-1) will behave identically to exit(255).
>>
File: xkcd.png (44KB, 740x633px) Image search: [Google]
xkcd.png
44KB, 740x633px
>>57619390
>>
>>57622514
wait() can still return -1, read the man page for it.
>>
>>57622526
Do you think he was [LITERALLY SHAKING] too?
>>
>>57622485
I'm a better person than you, that's for sure.
>>
>>57619390
nothing i don't program.
>>
File: 1474221441087.png (67KB, 616x596px) Image search: [Google]
1474221441087.png
67KB, 616x596px
>>57622542
maybe, I don't give a fuck
>>
>>57622483
They being society, authorities and the laws of fucking physics.
>>
>>57622526
more like XDkc, right?
>>
>>57622555
>Posts frogs
You definitely are in the absolute lowest-tier of person.
>>
>>57622305
> Only sane function there is exit().
Translation: "the only thing libc is any good for is killing yourself".

> ctype.h - Fucking bullshit locale system
FTFY.
>>
>>57622476
What country are you from? I'm British
>>
>>57622507
Derp. Didn't realise i didn't link the post i thought i was replying to. Ah, never mind.

And no, string concatenation will ~probably~ not get you a girlfriend.
>>
>>57622314
Probably some shit like -I/path/to/headers before the files you want to compile
>>
File: 1478702446794.png (307KB, 700x700px) Image search: [Google]
1478702446794.png
307KB, 700x700px
>>57622526
>>
>>57622557
Hmm I thought you meant like parents or something. "I wanted to be in a band, but my mom made me go to college"
>>
File: 1474231100639.png (170KB, 500x335px) Image search: [Google]
1474231100639.png
170KB, 500x335px
>>57622566
stay mad
>>
>>57622526
>>57622589
Let's be honest, he'd lose his income if he wasn't
>>
Help me god damn it, how do I write a cookie that tracks page visits?
>>
>>57622611
why would that be a cookie?
>>
>>57622533
> wait() can still return -1, read the man page for it.
You mean the actual function return value, not the status (which is returned via the argument pointer)?

wait() can fail with ECHILD or EINTR. Neither of those can be forced by the child process (other than via debug mechanisms like ptrace()).
>>
>>57622590
Nah, my parents have been patient and supportive above and beyond the call of duty.
>>
>>57622611
You don't because that's cancer
>>
So after reading through the thread thinking of making a palindrome checker in python am I correct tihs would work
>remove spaces
>remove grammar
>remove numbers
>convert to lowercase
>reverse it
>save as reverse1
>compare reverse 1 to the string just before reversal
>if it matches it's a palindrome
>>
If I have a very simple program in C++ that I need to write again in Python, would it be a simple matter of just copying it and changing the syntax?
>>
>>57621405
print("I'm not a pajeet")
>>
>>57622665
pretty much, assuming by grammar you mean punctuation.
>>
>>57622692
I do, sorry I'm a dumbcunt
>>
>>57622670
yes, although you will find a direct one to one translation to be unidiomatic and suboptimal.
>>
>>57622707
Hmm. It's just part of an assignment and the program is really really basic.

If I wanted to actually learn from this what would I do differently? Flat out write the program again?
>>
Has there ever been an attempt at implementing a first person dungeon crawler kind of view (think Wizardry) with ncurses and c/c++?
>>
>>57622835
>Has there ever been an attempt at
Yes
>>
>>57622754
I would try to translate it line by line.
>>
>>57622842
Ok, maybe I should rephrase.

A SUCCESSFUL attempt?
>>
>>57622754
for example, say you have
int array[size];
for (int i = 0; i < size; i++) {
// do stuff with array[i]
}

so directly converting to python you might get
for i in range(0, len(array)):
# do stuff with array[i]

when it's arguably better and more idiomatic to use a foreach-style loop
for e in array:
# do stuff with e
*

_____
* unless you also need the array index but then you can do
for i, e in enumerate(array)
>>
>>57622628
>>57622635
Man I'm perfectly aware but all my professor wants me to do is write wicked outdated and useless shit. Biggest waste of $600 for this class, I learned a million times this through free internet stuff.
>>
>>57622844
that's basically what I was going to do anyway.
>>
>>57622835
If you do a good job of modularizinng your game, using ncurses or something else for your rendering context shouldn't matter.
>>
>>57619434
#include <stdio.h>
int main(){
int x = ?;
int y = ?;
int hi = x > y ? x : y;
int lo = x > y ? y : x;
while(lo < hi){
++lo; --hi;
printf("%d, %d\n", lo, hi);
}
if(hi == lo)
printf("%d\n", hi);
else
printf("%d.5\n", lo > 0 ? hi : lo);
return 0;
}
>>
>>57622915
Hell, you could write an openGL wrapper for ncurses and render Quake in your terminal window.
>>
So what's the gold standard for argument parsing in C these days? getopt? argp?
>>
>>57622973
ya but can it run crysis
>>
>>57622973
SDL has a libcaca backend, this is possible already.
>>
>>57622989
String comparisons
>>
>>57622997
See?

>>57622993
Nothing can run crysis.
>>
>>57622611
You use google analytics.
>>
File: enough.gif (646KB, 295x221px) Image search: [Google]
enough.gif
646KB, 295x221px
>Decide to try out Haskell since the sperglords on /dpt/ never stop talking about it
>Read through the tutorials, write FizzBuzz
>Compile it
>Binary is 1.7 MB
>wtf
>Check binary size of C++ program I wrote that downloads all images from a 4chan thread
>467 kB

I think I'll ditch this meme language. These binaries are bloated like a rotting dead carcass.
>>
File: 1479771776.jpg (419KB, 1918x1180px) Image search: [Google]
1479771776.jpg
419KB, 1918x1180px
>>57623018
>>
>>57623020
all functional programming languages do this
>>
>>57623037
So what's actually taking up 1.7MB in a FizzBuzz binary?
>>
>>57623020
all modern languages seem to like to statically link everything. it's not just functional languages.

>>57623047
the standard library / runtime, linked statically.
>>
>>57623020
ghc -O2 --make -dynamic fizzbuzz.hs
strip fizzbuzz
>>
>>57621689
Is work rough on you? I go to work then do side projects because the side projects are a sweet release from the pains at work.
>>
>>57621689
I did. Ended up losing my job.
Now I only do side projects, as a NEET.
>>
>>57623138
shit how'd you lose your job
>>
>>57623149
Addicted to side projects, was too much to also hold a job
>>
>>57623055
and in the case of common lisp, the fucking debugger and compiler

maybe save-lisp-and-die isn't the right way to do things, i don't know
>>
why does this crash as soon as I try to run it? I'm trying to do an exercise in k&r where you delete each character in a string that matches any character in another.

#include <stdio.h>

void squeeze (char s[], char t[]);

int main ()
{
char s[] = "test";
char t[] = "te";
squeeze(s, t);
printf("%s", s);
}

void squeeze (char s[], char t[])
{
int i , j, k;
int found = 0;

for (i = j = 0; s[i] != '\0'; i++) {
found = 0;
for (k = 0; t[k] != '\0'; i++) {
if (t[k] == s[i]) {
found = 1;
}
}
if (found == 0) {
s[j++] = s[i];
}
}
s[j] = '\0';
}
[\code]
>>
>professor has us write a program in rust
>get a ton of compiler errors
>put entire program in an unsafe block
THATS BETTER
>>
File: Screenshot_2.jpg (2KB, 64x78px) Image search: [Google]
Screenshot_2.jpg
2KB, 64x78px
>>57623258
wew lad, I just saw the mistake
>>
>>57619390
Just added an installer for my R/a/dio player, MSI ain't that bad.
>>
File: 1476243946138.jpg (1MB, 2507x3541px) Image search: [Google]
1476243946138.jpg
1MB, 2507x3541px
@ECHO OFF
:loop
set /P link="Enter your link "
set name=%link:~30,41%
set command="C:\Users\YUU\ffmpeg.exe" -i "%link%" -c copy "C:\Users\YUU\streams\%name%.ts"
set encode="C:\Users\YUU\ffmpeg.exe" -i "C:\Users\YUU\streams\%name%.ts" -vcodec copy -acodec copy -bsf:a aac_adtstoasc "C:\Users\YUU\streams\%name%.mp4"
%command%
%encode%
del C:\Users\YUU\streams\%name%.ts
echo Done!
goto loop


How would I get this batch to read from a text file a bunch of links? Ex
links.txt
link1
link2
link3
[.code]

And have the first code go through the list and download each link
>>
>>57619782
Isn't i out of scope
>>
>>57619434
Someone do it in C+=
>>
>>57623380
C+= is a real language? I thought it was a /g/ joke.
>>
>>57623380
assuming that they are ints would not compile
>>
>>57619390
This image only appeals to newfags failing to use tensorflow. It's easy to do image recognition now.
>>
>>57619791
Beautiful Soup
>>
>>57619434
Cast both integers into a bigger data type and then do the arithmetic.
>>
>>57623421
>It's easy to have someone else do image recognition for you.
ftfy
>>
>that feel when your 4chan download script finally works correctly

Why does 4chan have two image servers though?
>>
>>57623783
Because 4chan was made by pajeets.
>>
>>57623806
But moot is white?
>>
>>57623925
pajeet is a state of mind
>>
>>57624066
this
you reach pajeet by accepting java into your heart
>>
>>57624125
I really dislike Java, but /dpt/ insists on calling me Pajeet anyway :(
>>
>>57624158
if it isn't java or jvm based then you aren't pajeet
the fact that redditors who love le memes decide to use words wrong is just part of life
>>
File: oh no.jpg (3KB, 125x125px) Image search: [Google]
oh no.jpg
3KB, 125x125px
c makes me want to jump into a noose.
>>
>>57624187
noosi don't work that way anon
>>
c-can someone help me with this question on a study guide?

Point a = new Point(5,5);
Point b = new Point(5,5);
Point c = b;
if (a == b)
{
System.out.println(“They’re the same.”);
}
if (a.equals(c))
{
System.out.println(“They’re equal.”);
}

Which one prints out and why? Thanks.
>>
>>57624203
You're using Java, so == isn't actually value equality
>>
>>57624234
Right. So it would print out "They're equal" because a would not be able to == b, because wrong data types?
>>
>>57624255
== compares addresses
a and b do not share the same address

but a.equals(c) is true, because .equals() is equality
>>
>>57623783
I'm too proud not to post it, rate my 4chan download script, it's in python, really beautiful language to work with

import sys, re, os
os.system("wget -4 -O /tmp/thread.html -o /dev/null "+sys.argv[1])
for l in set(re.findall('/\w{1,4}/\d*\.(?:png|jpe*g)',open("/tmp/thread.html", "r+").read())):
os.system("wget -4 -o /dev/null i.4cdn.org"+l)

>>
>>57624294
Oh I see. Thank you anon.
>>
File: 1467019345752.jpg (10KB, 180x157px) Image search: [Google]
1467019345752.jpg
10KB, 180x157px
>>57624296
>'/\w{1,4}/\d*\.(?:png|jpe*g)'
>text based programming languages
>>
>>57624203
In Java:
== checks for equality of primitives.
.equals() checks for equality of objects.
>>
>>57624356
Not him, but Regex are pretty usefull.
>>
>>57624396
I think you misunderstood
>>
File: 1461607773688.png (70KB, 755x801px) Image search: [Google]
1461607773688.png
70KB, 755x801px
Why do Pajeets like Java so much? Is it because Java developer's shat the floor with it?
>>
>>57624699
It's easy, cross-platform and has a huge amount of "high level" frameworks and libraries.
>>
Why would I use regex when I can use parsec's monad transformer?
>>
Math is hard. ):
>>
File: 1467754418255.jpg (35KB, 560x420px) Image search: [Google]
1467754418255.jpg
35KB, 560x420px
** new thread **
>>57625015
** new thread **
Thread posts: 341
Thread images: 30


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