[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: 335
Thread images: 37

File: prog.jpg (105KB, 473x496px) Image search: [Google]
prog.jpg
105KB, 473x496px
What are you working on, /g/?

Previous thread:>>61469216
>>
First for anime is /dpt/ related
>>
File: Felix.Argyle.full.2018176.jpg (576KB, 1000x1414px) Image search: [Google]
Felix.Argyle.full.2018176.jpg
576KB, 1000x1414px
Rust
>>
>>61477091
gay
>>
>>61477059
>What are you working on, /g/?
Just started learning C and did my first fizzbuzz. Please rate and don't be too harsh, please. I am open for good adivce though

??=include <stdio.h>

int main()
??<
for(int i=1; i < 100; i++) ??<
if((i%5==0) ??' (i%3==0)&(i%5==0)) ??<
printf("FizzBuzz\n");
??> else if(i%3 == 0) ??<
printf("Fizz\n");
??> else if(i%5 == 0) ??<
printf("Buzz\n");
??> else ??<
printf("%d\n", i);
??>
??>

if(!(1 ??!??! 2) ??' 2)
printf("Hello world!\n");

return 0;
??>

>>
first for idris is the best slow piece of garbage i've ever used
>>
>>61477091
Rust is absolute garbage. It makes even the simplest tasks complicated as fuck. I really want to like it but it's just so annoying.
>>
This might not be the most well-received question (and I understand entirely), but I guess it couldn't hurt to ask: Where should I go for online computer science programs? Or is there a non-biased site that grades universities?

I've gotten through the basics by myself just fine, and I know that what employers really want to see are your projects and independent drive, but I specifically need a bachelors degree in a field that I plan on working in.
>>
>>61477080
Eighth for so are kawaii hijab-wearing cuties.
>>
>>61477129
t. brainlet
>>
>>61477134
https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/

https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-structure-and-interpretation-of-computer-programs-spring-2005/
>>
>>61477110
>trigraphs
Nice try anon.
>>
File: s.png (59KB, 1680x1050px) Image search: [Google]
s.png
59KB, 1680x1050px
>>61477059
>What are you working on, /g/?

Exploring the deepest, darkest corners of Racket.
>>
>>61477152
xD epic cumback, btfo
>>
>>61477280
i don't like nyan mode because the colors don't fit into any theme. besides nyan cat theme i guess.
>>
>>61477059
What do you think about new features in C and/or its standard library with the following conditions:
> Already stood the test of time in either C++ or GNU C
> Are small, non-intrusive, design to make it easier on the programmer

For example, I think most of the programmers say that C99 is a better language than C89, only with some disagreeing on VLAs (which were made optional in C11, so I don't know how much is that relevant)

I personally, enjoy new C11 features like unnamed structures and unions, I'm yet to try out generic macros which I think are great, I love the <threads.h>, it's a pity glibc hasn't implemented it for 6 years already, I think it would be great to have it.

What would you think about the following feature:
> automatic type inference using auto

It wouldn't break the language, old code would continue compiling as it does today, it's already tested in C++, and they seem happy about it.

Or this:
> nested functions
Functions continue being an exception, because you can nest everything else except functions. AFAIK this has been done to simplify compiler creation, which, I think, is not *that* much relevant now, since CS has advanced a lot and there are less architectures to port stuff. It's already in GNU C. I personally used nested functions for encapsulation, that is, putting functions that clearly belongs to a bigger one and can't be used by other ones out of the translation unit namespace.

> Switch ranges.
I personally didn't find a need to use them, but GNU C has them, so maybe they're useful, I just put it here as an another example on non-intrusive extension.

I have the 1570.pdf C11 draft and I read it from time to time, and I see that this language is truly beautiful. I'm not saying we should try to turn it into C++, but I think small, slow, non-breaking, already-practiced, positive extensions could be made.

What do you think?
>>
>>61477164

I need the piece of paper, specifically. I'm not at a loss for how to study. Really, it just needs to be someplace that won't be blacklisted as a diploma mill before I graduate, and the courses need to be online.

Thanks for the resources, though.
>>
File: bPSVXle.jpg (2MB, 3000x2000px) Image search: [Google]
bPSVXle.jpg
2MB, 3000x2000px
>>61477309
likewise
>>
>>61477353
Look at your options and evaluate them:

>look at the curriculum: the more maths / theoretical cs the better
>read reviews
>look what people with that degree are doing today (linkedin)
>>
>>61477280
>Exploring the deepest, darkest corners of Racket.
what did he mean by this?
>>
Tomorrow i have a big exam that will change my life.

wish me luck, guys
>>
File: Kaneda_large_8728.jpg (11KB, 300x300px) Image search: [Google]
Kaneda_large_8728.jpg
11KB, 300x300px
Can't find a job? sent out 1000 applications? Expert programmer? Can you compile C to x86 in your head? Let me tell you a story that will make you lose faith in all since of justice. My coworker somehow got a job and is simply the dubest motherfucker I've ever met in my life. Here's some anecdotes about him

>4.0 gpa
>accepted into engineering school at our university (not a top school but still a demanding program)

>gets hired at internship at our company
>we work on a web app in Javascript mostly
>writes everything he does outside of the project folder and tests in an isolated environment and not in the actual web application
>if he needs to write a function to do something, he writes it in a separate file and runs that function by itself either from node or by dropping it into a blank html file
>he then pushes the code without actually testing it in our webapp
>surprise, it doesn't fucking work

>He needs to get some data, format it, and display it
>he can't figure out how to change the data in a polling loop. Just keeps making new divs every time he makes an ajax request
>I give him the following pseudo code:

// functions availabe
// create - create new div with info
// set green - turn div green
// set grey - turn div grey

//objects available
//dom = {} - object contains doms; old data
//agents = {} - object contains new data from XHR

for(var i in agents)
if(dom[i]) //if dom already exists, check for new data
if(dom[i].connected && !agents[i].connected) //if different, change accordingly
set green
else if(!dom[i].connected && agents[i].connected)
set grey
else //if dom doesn't exist, create new div
create

>he's been studying the white board for 20 fucking minutes
>finally says "is this a logic table?"

(cont'd ...)
>>
>>61477902
anal exam?
>>
>>61477905
>Can you compile C to x86 in your head?
B-but C is a legacy language and x86 a deprecated architecture, why would you even wanna learn that?
>>
>>61477902
Good luck man
>>
File: oaiioGa (1).jpg (30KB, 360x360px) Image search: [Google]
oaiioGa (1).jpg
30KB, 360x360px
>>61477905

>we work in two week sprints
>each sprint, I divide up our labor
>I end up doing some of his side because he's taking so long and I finish mine in a couple days
>he complains and asks me not to do that
>I tell him "what do you want me to do, sit here and do nothing and wait for you to catch up?"
>"yes, I want to make sure the work is 50/50"
>I tell him "If you want the work to be 50/50, you need to start doing at least 50% of the work. In a real job, would you tell your boss that everybody has to stop and wait for you to finish?"
>no reply

unrelated to CS, but the other day he asked me if it's illegal to tip a waitress under 15% and if the restaurant can sue him

>we're working on bug fixes
>I get a bug to fix on 3 different platforms
>takes me a week to do the bug on all 3 platforms

>he gets a bug fix
>essentially "add a
readonly
attribute to these 5 or 6
<input>
tags
>it takes him 2 months to get done
>he never tests anything
>turns in this bug fix and it's still broken
>pull request is rejected
>he finishes, pushes it again
>still not done because he NEVER FUCKING TESTS ANYTHING
>finally after 3 attempts, his changes are "satisfactory"

Another story: our company had a get-together
with catering, some beers, etc. and he saw a piece of gouda cheese with some crackers and a cheese knife. He put it on his plate and walked away with it. Later I sit next to him and see the block of cheese with a chunk bitten out of it. He tells me "I don't really like this cake"

You can take this story one of two ways: Either be an optimist and say that if this fucking mongoloid can get a job, then so can I, or you can give up any hope that the universe has any kind of justice
>>
File: 1499178532486.jpg (681KB, 1971x1971px) Image search: [Google]
1499178532486.jpg
681KB, 1971x1971px
>>61477998
>he saw a piece of gouda cheese with some crackers and a cheese knife. He put it on his plate and walked away with it. Later I sit next to him and see the block of cheese with a chunk bitten out of it. He tells me "I don't really like this cake"

Now that's pretty good
>>
>>61477905
>My coworker somehow got a job and is simply the dubest motherfucker I've ever met in my life
Never fall for the meritocracy meme, anon.

Capitalism DOES NOT reward excellence as they have brainwashed you to believe.
>>
File: 1qwer5tesghfdg.jpg (515KB, 1097x985px) Image search: [Google]
1qwer5tesghfdg.jpg
515KB, 1097x985px
>>61477905
>>61477998
>>
>>61477919
paternity test
>>
Fastest way to add a list of integers

https://gist.github.com/anonymous/e103d264cecf10e31e6dadfb1c398007
>>
File: Janna math.jpg (164KB, 900x693px) Image search: [Google]
Janna math.jpg
164KB, 900x693px
How do I change my emacs.d to automatically turn on certain modes?

For example, I found the "electric-pair-mode" and "auto-complete-mode" pretty useful for C programming, but I don't want to have to reactivate them every time I open up Emacs.

Sorry for low-tier question.
>>
>>61478260
Put it in your ~/.emacs
>>
>>61477351
>automatic type inference using auto
C not being strongly typed, there could be ambiguous cases easily.

>nested functions
Standard C must be easily translatable to assembly. In most (if not all) assembly languages, there's no notion of second-order procedures, so having a second-order function does not translate very neatly to assembly. Of course, it's doable and permits to limit scope of function, but it does not fit with the mindset of C.

>switch ranges
Same thing there. Switch statements in C are basically a sequence of conditional jumps. Conditional jumps don't test ranges. And testing ranges is easily done without switch anyway.

There's a reason C why is very conservative. Keep the experimental gotchas for C++.
>>
>>61478269
My bad... I meant emacs.d

I usually have to do
 M-x electric-pair-mode 

or something similar to turn it on. What does this (roughly) translate to in EmacsLisp?
>>
>>61478288
Usually
(electric-pair-mode)
But you can ask the help of emacs. It will describe the function.
>>
>>61478314
This worked! Thanks, man!
>>
File: KYS.png (379KB, 582x480px) Image search: [Google]
KYS.png
379KB, 582x480px
>>61477080
KYS
>>
>>61478260
>>61478288
https://www.gnu.org/software/emacs/manual/html_node/ccmode/CC-Hooks.html

(add-hook 'c-mode-hook 'electric-pair-mode)
>>
Fucking c++
#include <array>

template <typename T, size_t S>
class fish {
public:

template<typename... Args>
explicit fish(Args ...args) : array{std::forward<Args>(args)...} {}

std::array<size_t, S> array;
};

int main(int argv, char** argc) {
//fish<int, 3> test{1, 2, 3}; // doesn't work and gives the compile error
fish<int, 3> test{size_t{1}, size_t{2}, size_t{3}}; // works
}

Error: C2397 conversion from 'int' to 'size_t' requires a narrowing conversion
>>
>>61478722
why are you doing this to yourself?

do you want to go insane?
>>
>>61477059

> have function written to run on input from a file
> uses fopen, fgetc, frewind, etc..
> want to run it on an std::string

fuck me
>>
https://www.zerynth.com/blog/the-rise-of-python-for-embedded-systems/

Why aren't you learning Python, anon?
>>
File: 14999586448940.jpg (401KB, 1242x2208px) Image search: [Google]
14999586448940.jpg
401KB, 1242x2208px
Guys, how can I add helping highlights for python in Atom just like in IDLE? Like show which method or function does what. Can't find any package which does so, but, I guess, I am searching with wrong keywords.
>>
>>61478771
Try open_memstream or fmemopen

That gives you a FILE*
>>
>>61478738
Trying to implement a multi-dimensional array but the templates aren't doing what I want them to do.
>>
>>61478800
W-who is th-that sperm succubus?
>>
>>61478841

Fuck yes thank you anon
>>
>>61477280
font?
>>
>>61478846
It's fucking easy with coq.
Axiom array : Type -> nat -> Type.
Check array.

Axiom mk_array :
forall (T : Type) (n : nat),
(forall i : nat, i < n -> T) -> array T n.
Check mk_array.

Fixpoint multi_array (T : Type) (dims : list nat) :=
match dims with
| nil => T
| cons dim dims => array (multi_array T dims) dim
end.
Check multi_array.

Definition test : multi_array Prop (cons 2 (cons 2 (cons 2 nil))) :=
mk_array _ 2
(fun i _ =>
mk_array _ 2 (fun j _ => mk_array _ 2 (fun k _ => i + j = k))).
Check test.

Maybe it's time to use a real language anon.
>>
>>61479005
This is fucking unreadable my friend. But does your array allow you to create an array of 3 x 5 x 6 x 2 of contiguous elements?
>>
>>61479091
Everything is possible. So yes. The only difference, is that with coq you produce code with zero bugs.
>>
>>61478937
http://laemeur.sdf.org/fonts/
>>
>>61479115
>The only difference, is that with coq you produce code with zero bug
explain

how can code be free of bugs !?

you can't prove that
>>
>>61479091
>unreadable
i hate C style codelets
>>
>>61479166
>explain
Do you really understand the power of dependent type?
>how can code be free of bugs !?
When there is no bugs in it.
>you can't prove that
Were you sleeping during math class?
>>
File: Coq.png (239KB, 798x633px) Image search: [Google]
Coq.png
239KB, 798x633px
>>61479166
1 million years in mspaint.net
>>
>>61479166
>>61479202
Every valid program is a proof of some logical statement.

But the program may also prove something else rather than what you actually wanted to prove. Bug-proof languages can't prevent this kind of problem, the difference between intent and result.
>>
>>61479340
>Every valid program is a proof of some logical statement.
Yes.
>something else rather than what you actually wanted to prove
You have to explicit your theorem. If you don't know what to prove, no tools can help you.
>>
File: e1439908377867.jpg (45KB, 640x418px) Image search: [Google]
e1439908377867.jpg
45KB, 640x418px
>>61479171
>create esoteric programming language
>get triggered when coders point out the fact that it's unreadable
>>
I’m currently exploring a bit the assembly language, and for some reason I keep getting segfaults when I try to call output functions such as printf, fwrite or fprintf.
Does anyone see what’s wrong in these lines?
  .globl  foo
foo:
subq $16, %rsp
movb $119, 9(%rsp)
leaq .L.str.1(%rip), %rdi
leaq 9(%rsp), %rsi
callq fopen@PLT
movq %rax, 8(%rsp)
xorq %rax, %rax
leaq .L.str.2(%rip), %rsi
movq 8(%rsp), %rdi
movl $0, %eax
callq fprintf@PLT
movq 8(%rsp), %rax
call fclose@PLT
addq $16, %rsp
movl $0, %eax
ret

.type .L.str,@object
.L.str:
.asciz "%d\n"
.size .L.str, 4
.L.str.1:
.asciz "test.txt"
.size .L.str.1, 8
.L.str.2:
.asciz "Hello World!\n"
.size .L.str.2, 14
>>
File: succ.png (16KB, 855x324px) Image search: [Google]
succ.png
16KB, 855x324px
>his language doesn't provide a function called S U C C
>>
>>61479591
>esoteric

>when you can't even understand forall a b. (a -> b) because it doesn't involve some horrible hodgepodge of &, *, --, ++, for(;;), int and return
>>
>>61478722
Fix yo' types nigga:
#include <array>

template <typename T, size_t S>
class fish {
public:

template<typename... Args>
explicit fish(Args&& ...args) : array{std::forward<Args>(args)...} {}
std::array<T, S> array;
};

int main(int argv, char** argc) {
fish<int, 3> test_int{1, 2, 3};
fish<size_t, 3> test_size_t{size_t{1}, size_t{2}, size_t{3}};
}
>>
>>61479598
Dear god please use Intel syntax
>>
>>61479640
>>
>>61479666
>int(*)((const char*)(*float))
No it's
int (*) (cost char * (*) (float))

Nice triples.
>>
>>61479658
The only thing in my post that needed fixing was the && in the constructor the std::array<size_t, S> holds the dimensions not the type of data.
>>
>>61479667
no
>>
>>61479696
deleted because of satan triples


anyway the point is
int (*) (cost char * (*) (float))
is still fucking ugly and hideous and nonsensical compared to
(float -> string) -> int

also ignoring string/const char, even if you had

(float -> const (pointer char)) -> int
it's better
>>
>>61479735
I agree, I am the one posting the Coq code for fun. But I just wanted to point out that you made a mistake.
>>
>>61479699
Then are you not using the template parameter T at all? That is pretty misleading.
>>
>>61479760
I don't think I did, what's wrong with putting const char * in parentheses? It looks slightly less ridiculous that way
>>
>>61479651
Show me anything relevant written in your washed up toy language then, smartass.
>>
>>61479760
>>61479779
oh i just checked
i had *float
i meant
(*)(float)
you're right
>>
>>61479794
Yes I right. I did check your code with Coq.
>>
>>61479782
Why are you so hostile to sanity?
Does it really offend you that C could easily have had better syntax?
>>
>>61479816
So you have nothing to show for it?

Didn't think you did.
>>
>>61479833
Start arguing any time buddy, you can't just stay mad in the knowledge that C made a mistake and could fix it any time
>>
>>61479833
Coq/Agda > Idris > Haskell > Scala > *
>>
>>61479866
>Scala
>>
>>61479863
>C made a mistake
Not that guy but the syntax is very nice considering BCPL was what we had before.
>>
>>61479866
All irrelevant meme languages.

>>61479863
Still waiting for that example of anything relevant written in your hobbyist esoteric language.
>>
>>61479919
>Still waiting for that example of anything relevant written in your hobbyist esoteric language.
you're embarassing yourself

here we are, telling you C could be much better
and what are you saying? that C shouldn't have had a better function syntax "because the other languages that have it aren't as popular as C"?
>>
>>61479919
>Still waiting for that example of anything relevant written in your hobbyist esoteric language.
The first proved C compiler:
http://compcert.inria.fr/
Ho strangely it's made by the same guy that made OCaml.
>>
>>61479937
>defend a literal esoteric syntax as an "improvement"
>tell me I'm embarrassing myself
The irony is almost palpable.
>>
File: Screenshot_2017-07-20_17-39-45.png (298KB, 646x470px) Image search: [Google]
Screenshot_2017-07-20_17-39-45.png
298KB, 646x470px
Work on the parser continues
>>
>>61479960
>esoteric
Have you never heard of a fucking arrow before?

So this is how big the rock C programmers are living under!
>>
Struggling through K&R, but also kind of amazed just how versatile pointers are.

Speaking of pointers, I implemented the "strcat" function that joins two strings using pointers, but I keep getting "Bus Error" when I do
char* test1 ="This is a ";
char* test2 = "test";
strcat_ptr(test1, test2);

but not when I do it with arrays like this:
    char test1[100] = "This is a ";
char test2[100] = "test";


Why can't I modify a pointer to a string literal? Is it because it's stored in static memory?

Another thing, is there a bug in my strcat_ptr function?
/*strcat_ptr : strcat, but with pointers */
void strcat_ptr(char* s, char* t)
{
while(*s++ != '\0')
; /*find end of s */
while((*s++ = *t++) != '\0')
; /*copy t */
*s = '\0'; /*end string */
}

It seems to not assign characters to *s once the first while loop finishes
>>
>>61479958
>gets desperate
>names something irrelevant which nobody has ever heard of
kek

Can't make this shit up.
>>
>>61479986
?
>>
>>61479985
Install Pelles C.
>>
>>61479598
You're not calling fopen with enough arguments.

foo:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
leaq str(%rip), %rsi
leaq str1(%rip), %rdi
call fopen@PLT
movq %rax, -8(%rbp)
movq -8(%rbp), %rax
movq %rax, %rcx
movl $13, %edx
movl $1, %esi
leaq str2(%rip), %rdi
call fwrite@PLT
movq -8(%rbp), %rax
movq %rax, %rdi
call fclose@PLT
nop
leave
ret
>>
>>61479998
I think he just moved the goalposts, anon.
>>
>>61479986
>>names something irrelevant which nobody has ever heard of
In few decades all C code in embed world will be compiled with that compiler. You're ignorant anon.
>>
>>61479981
Why are you writing the perser?
>>
>>61480032
the what?
>>
>>61480032
Unrecognized token: 'perser'
>>
>>61480042
>>61480061
parser*
>>
File: 1492085644340.png (339KB, 387x550px) Image search: [Google]
1492085644340.png
339KB, 387x550px
>>61479982
C is short for cancer. Can't believe that shit hasn't been deprecated and banned from use for safety issues yet.
>>
Is C worth learning?
>>
/o/ here, i've managed to get my pay up so high that i can afford to live off of part time. In addition to taking up some more rigorous exercise programs, i thought i would learn to program to sharpen my mind and give me a new skill. I'm set on C/C++ so what is your recommended literature and resources? In addition to that, what about IDEs vs text editors and manual compiling. Running Arch on a 10 year old computer, C2Q6600 and 4GB RAM.
>>
>>61480103
kys
>>
>>61480028
In a few decades, there won't be any more C code in existence, anon.
>>
>>61480123
kek
>>
>>61480113
how will you pay for a family?
>>
>>61480077
For compilers and shit
>>
>>61480113
You need to learn Icelandic and Japanese in order to be able to use the best programming resources
>>
>>61480028
But that's not clang, anon.
>>
>>61479985
>is it because it's stored in static memory
Exactly. It's stored in the data section of your program which is usually read only. If you explicitly make the strings stored on the stack like you do here it's fine. I'd assume you get a segfault.

>strcat
Your strcat assumes you've got enough allocated space after s to store t.
I'd assume this also segfault.
>>
>>61479985
C string literals are constant, what you manipulate is a pointer to the location where they are stored.
int main(void)
{
char* s = "a string";
// s[0] = 'b'; Segmentation fault -> trying to modify the literal
return 0;
}

If you want to join two strings, you should have a buffer to place the joined string in.
>>
>>61480123
You're cute anonkun.
>>
>>61480140
I'm too young for a family. I'll go back to full time or pick up another job when I'm ready for a family.
>>
>>61480229
>too young
That's bullshit, if you were too young you wouldn't be allowed on this site
>>
>>61479986
>I'm retarded and want everyone to know it!
>>
>>61480274
We knew that the minute he said "I'm a C programmer"
>>
>>61480243
okay, i consider 19 to be too young for a family, bite me
>>
>>61480156
Sort of, it gives me "Bus Error: 10".

Now I changed the implementation to have a temporary char* variable, but I'm still not getting the desired result:

#include <stdio.h>

/*strcat_ptr : strcat, but with pointers */
void strcat_ptr(char* s, char* t)
{
char* temp;

while((*temp++ = *s++) != '\0')
printf("Processing...%c\n", *temp); /*find end of s */
while((*temp++ = *t++) != '\0')
printf("Processing...%c\n", *temp); /*copy t */
*temp = '\0'; /*end string */
s = temp;
}

#include <string.h>
int main()
{
char test1[100] = "This is a ";
char test2[100] = "test";

strcat_ptr(test1, test2);
printf("%s\n", test1);
}

>>
>>61480308
Forgot... Pic related is the output:
>>
>>61480308
>strcat, but with pointers
char * s_TRcat( char *s1, char *s2 )
{
char *p = s1;

while( *s1 ) ++s1;
while( *s1++ = *s2++ );

return p;
}
>>
>>61480327
You didn't allocate temp anon.
>>
Any engineers doing MATLAB? I just barely passed it in my first year. And I'm probably going to be doing it if i ever get an engineeing job so I'm gonna buy a book and stat from scratch.

How Much am I going to want to an hero?
>>
>>61480346
Install Scilab.
>>
>>61480346
dude, fuck matlab, it's such a pain to deal with programmatically
>>
>>61477059
it is my cake day i am twenty one and :D
>>
File: 1500508193979.jpg (3MB, 6000x4000px) Image search: [Google]
1500508193979.jpg
3MB, 6000x4000px
>>61480357
:DDD
>>
>>61480345
I don't think K&R has gone over allocation of memory... Would I need to do :
char* temp = (char *) malloc( strlen(s1) + strlen(s2))


>>61480337
Dumb question, but what was the main difference between the code you wrote, and this:
void strcat_ptr(char* s, char* t)
{
while(*s++ != '\0')
; /*find end of s */
while((*s++ = *t++) != '\0')
; /*copy t */
*s = '\0'; /*end string */
}
>>
>>61480407
>Dumb question, but what was the main difference between the code you wrote, and this:

this
 while(*s++ != '\0')


is the same as this
 while(*s++)


and this
while((*s++ = *t++) != '\0')


is the same as this
while((*s++ = *t++))
>>
File: lili.jpg (77KB, 600x600px) Image search: [Google]
lili.jpg
77KB, 600x600px
Need help with php.

So I am writing this for a shop. This func returns false whenever they are closed (opening at 9:30 and closing at 22:45).

I need it to ALSO return false when the current day of the week is Saturday or Sunday.

Here is the function:

function can_order_now_timeframe(){

$morning= new DateTime("09:30", new DateTimeZone('Europe/Budapest'));
$night = new DateTime("22:45", new DateTimeZone('Europe/Budapest'));


$morning_u = $morning->format('U');
$night_u = $night->format('U');

$datenow = new DateTime("now", new DateTimeZone('Europe/Budapest'));
$timestampnow = $datenow->format('U');


if(($morning_u<$timestampnow) && ($timestampnow < $night_u)){
return true;
}else{
return false;
}

}


Thanks for the help.
>>
>>61480427
I didn't word it very well, but I meant to ask, why did you use a temporary variable?
Because (at least for me) this works:
char*  strcat_ptr(char* s, char* t)
{
char* temp = s;

while( *s ) ++s;
while( (*s++ = *t++ ) );
return temp;
}


But this doesn't:

void strcat_ptr2(char* s, char *t)
{
while(*s++) ; /*find end of s */
while((*s++ = *t++)) ;
}


Here's the test I'm running in pic related:
int main()
{
char test1[100] = "This is a ";
char test2[100] = "test";

strcat_ptr2(test1, test2);

char test3[100] = "This is a ";
char test4[100] = "test";

strcat_ptr(test3, test4);
printf("Result of My Code: %s\n", test1);
printf("Result of Anon's Code: %s\n", test3);
}

>>
>>61480356
Mate I know, MATLAB gave me such a bad impression on programming in general until I met CS and software engineering students.
>>61480350
I googled a bit and it's apparently just like matlab? Also jobs require MATLAB explicitly
>>
File: 1498108612020.webm (924KB, 600x336px) Image search: [Google]
1498108612020.webm
924KB, 600x336px
>>
>>61480530
I never really understood this webm. Seems well made tho
>>
>>61478800
Did you search "python"? Make sure you are searching for available extensions instead of being on your "Installed Extensions" screen.
>>
How does one into rust?
>>
just wrapped my entire code base in a try/catch block

what did you do today?
>>
>>61480907
Buy it on Steam
>>61480920
idk, stuff
>>
>>61480954
Ebin post 、 NAISU !
>>
File: large.jpg (25KB, 500x554px) Image search: [Google]
large.jpg
25KB, 500x554px
>>61480972
Arigato
>>
>>61479598
ld -o <output> /lib/crt0.o hello.o -lc

You have to link libc.
>>
test post
>>
>>61479640
At least it is short, look at this monster
https://facebook.github.io/react/docs/test-utils.html#scryrendereddomcomponentswithclass

scryRenderedDOMComponentsWithClass(element, className)


No wonder it got replace for an extra Js library.
>>
>>61480907
You dont, rust is shit.
>>
>>61481034
Looks like it failed
>>
>>61480016
Thank you!
Though I thought the lines
  leaq  .L.str.1(%rip), %rdi
leaq 9(%rsp), %rsi

kind of do the same thing as
    leaq    str(%rip), %rsi
leaq str1(%rip), %rdi

with the ascii value for 'w' in 9(%rsp), but obviously it didn’t work

>>61481010
thanks for the answer, but gcc and clang both seem to find libc automatically, and the answer of anon I answered above seem to work.
>>
>BBCODE AND SCHEME ARE THE ULTIMATE LANGUAGES
But really, BBCode is a very comfortable formatting language. Extremely comfy. I'd use it over markdown on Github if I could.
>>
what's wrong with my scheme code?
using guile by the way

(define (for i        ;;start val
Rule ;;how 'i' changes
MaxorMin ;;limit
Bool ;;we want to run as long as we're below the limit, right? if not, pass false.
Expr) ;;expresiion to be ran by the for loop

(if (Bool)
(if (i < MaxorMin)
(set! i (Rule i))
(Expr i)
(for i Rule MaxorMin Expr))
(if (i > MaxorMin)
(set! i (Rule i))
(Expr i)
(for i Rule MaxorMin Expr))))
>>
>>61480475
return ($dayOfWeek - 5 <= 0) and ($maxTime - $currentTime >= $minTime)
>>
>>61481151
fucking 4chan. nothing in that should be green
that's the apostrophe in "we're" in the comment causing that
>>
>>61481163
>
 Rule     ;;how 'i' changes
MaxorMin ;;limit
Bool ;;


What is this nonsense with the double semi-colon?
>>
>>61481193
that's how comments work in scheme

everything after ; on a line is ignored
to the left of the comments are the parameters to the function "for", which I'm trying to define
>>
Lead dev here. Here has been my week.
>silently fix another team's project that I've never touched before between meetings
>fix a bug that people with way more experience have been looking at for 2 weeks in 1 hour because I finished that early
>rewrite an entire page in a day because it's the end of the sprint and it's completely fucked
I want to go back to being an entry level programmer.
At least I can work at pace instead of "delegating" to worse programmers while I clean up after them.
>>
File: Screenshot_20170720_170137.png (31KB, 916x293px) Image search: [Google]
Screenshot_20170720_170137.png
31KB, 916x293px
>>61481151
>>61481163
>>61481193
here's a better picture of the code
from emacs
>>
>>61481233
is it humblebragging
i am confused
>>
>>61481233
>fix a bug that people with more experience have been struggling with in 2 weeks
You're probably not understanding the full impact of the problem, they haven't actually spent any time on it or your solution doesn't treat all cases.
>silently first another team's project
Don't do this ever.

Also yes being a project lead is awful. Stressful work with little rewards. At my company at least
>>
who /passes off bugs as features/ here
>>
>>61481097
It has to be a /pointer/ to the char literal, so you'd need to push it + null byte to the stack, then lea it to rsi. Or use a global constant (easier).
>>
>>61481337
Every C/C++ programmer
>>
Recently been working on making my portfolio, starting with the website (already have a few projects lined up to showcase) - probably going with Django and begun putting shit together but I've mainly just been throwing together general designs for the last two days and perfecting them getting it all ready and solidifying making it all reactive.
It's my first major webdev project so I think there's areas I can really improve on but I'm glad html/CSS/js is easy as fuck.

Any cool ideas for projects to put in the portfolio? I was thinking of maybe using OpenGL or maybe just UE4/Unity to make something graphical and interesting both to view and make.
>>
>>61481319
>You're probably not understanding the full impact of the problem, they haven't actually spent any time on it or your solution doesn't treat all cases.
They straight up could not get a package to work after importing it.
I got the package to work in their case while it still works in other cases.
It has been a few days and they have no more problems importing it.
>Don't do this ever.
I was asked to.
>>61481293
Yes, I have a big head from working with this company. I also have no one to vent to about this that doesn't work there.
>>
>>61481399
I like hearing enterprise woes as fuel to keep me away from that hell, feel free to share more lad.
>>
>>61481452
My client company stopped doing automated tests because one group of tests broke and they didn't want to update it.
Now they don't allocate time for automated tests and there was a bug that cost a state over a million dollars because QA didn't test it with a certain kind of user.
>>
>>61481501
>Now they don't allocate time for automated tests and there was a bug that cost a state over a million dollars because QA didn't test it with a certain kind of user.

Lol. there are quite a few examples of this in real life:

> Project Mercury’s FORTRAN code had the following fault: DO I=1.10 instead of ... DO I=1,10

>An F-18 crashed because of a missing exception condition: if ... then ... without the else clause that was thought could not possibly arise.

> In simulation, an F-16 program bug caused the virtual plane to flip over whenever it crossed the equator, as a result of a missing minus sign to indicate south latitude.

> The Bank of New York (BoNY) had a $32 billion overdraft as the result of a 16-bit integer counter that went unchecked.
>>
>>61481501
sugoi.
>>
>>61481552
> In simulation, an F-16 program bug caused the virtual plane to flip over whenever it crossed the equator, as a result of a missing minus sign to indicate south latitude.
That's hilarious holy shit
>>
>Var swap in C# 7

(y, x) = (x, y);


nice
>>
>>61481602
actually pretty dank
t b h
>>
>>61481602
This is idiotic
>>
>>61481637
What's wrong with that?
>>
>>61481602
x = x ^ y;
y = y ^ x;
x = x ^ y;
>>
>>61481602
C++'s std::swap or Rust's mem::swap are better because they actually have important semantics and aren't just flowery syntax sugar
>>
>>61481552
This bug was also in real life
>>
>>61481670
>only works on very specific types

>>61481681
It's not "flower syntax sugar", it's tuple construction and deconstruction.
You are literally trying to criticise it for being concise.
>>
>>61481664
let (x, y) = (23, 11);
x = y; //x = *&y
y = x; //y = *&x = *&*&y = y

Proper way:
let (x, y) = (12, 37);
swap(x,y); //variablw swapping goes here
or
swap(&x, &y);
>>
>>61481699
Does it redefine x and y or shadow with new variables?
>>
>>61481726
I don't know C#.
It might not even be an in-place swap.
>>
>>61481602
kek, this is literally pyshit tier
>>61481681
Not just C++ and Rust, any non-brainlet language uses swap() method
>>
>>61481095

It was successful.
>>
>>61481965
rekt
>>
Hey guys

Which is best, Guile Scheme or CHICKEN Scheme?
>>
>>61482083
uninstalling scheme
>>
>>61481811
I basically never see swaps used outside of these two things
1. atomics (cmpxchg)
2. code written by morons

I don't know why having a dedicated non-atomic swap is really that important
>>
>>61482148
What should I use instead?
>>
>>61482208
people just like gimmicks.
Personally i think its a bad habit and will lead to spaghetti unless you do something like:
int x = 1, y = 3; 
immutable a = x,b =y;

But even that im not too keen on.
>>
>>61482083
chicken probably. it's fater and has a lot more library support iirc

that said guile can be used to write extension for GNU shit + you can write in javascript or emacs-lisp and have it compile to guile bytecode
+ guile was also built from the ground up for FFI use, which makes it more complete for applications needing that

so basically:
probably chicken, but guile maybe too
>>
>>61482301
thanks, helpful explanation
>>
Lisp: Code is also data!
Forth: Data is also code!
Javascript: null is an Object

Fucking hell.
>>
Anyone got any recommendations to learn how to configure Emacs? I will be using evil mode so I don't need to know about the editor commands, just the features.
>>
>>61482378
null is not an object in js

typeof null is 'object', but that is a mistake because it's not an object, see this https://stackoverflow.com/questions/18808226/why-is-typeof-null-object
>>
>>61481726
redefines x and y, I'm sure. no language would shadow in that situation. it's just destructuring assignment

>>61482378
data is also code in JS
eval('[1,2,3].map(x => x**2)')

get on my level :^)
>>
What's the best thing to do if you need to have different parts of your program communicate but they're written in different programming languages? Is it develop some sort of communication protocol / messagequeue?
>>
>>61482614
depends on if you need speed or isolation

speed: write C bindings and link them together
isolation: write HTTP-based migroserbices
>>
>>61482593
>x**2
n-nai?!
>>
>>61482628
I was thinking going that microservices route. Or maybe seeing if I could do something with something like ZeroMQ,RabbitMQ,etc
>>
>>61482614
>What's the best thing to do if you need to have different parts of your program communicate but they're written in different programming languages? Is it develop some sort of communication protocol / messagequeue?
look up FFI "foreign function interfaces"
>>
>>61482658
desu yo
>[1,4,9]
>>
>>61482679
I was thinking that making a C wrapper to create those bindings would be going way farther out of the way than if I where to just use the language's native library for something like zeromq which is just like a socket?
>>
>>61482680
oh
[1,2,3].map!(x => pow(x , 2)).writeln;
>>
>>61482662
Probably don't use a message queue unless your design dictates it

http://programmingisterrible.com/post/162346490883/how-do-you-cut-a-monolith-in-half
>>
File: spaceShooter.png (2MB, 1933x1365px) Image search: [Google]
spaceShooter.png
2MB, 1933x1365px
What is the best place to get open source sound effects/music for my Space-Shooter? Opengameart is too limited.
>>
>>61482250
What for?
>>
>>61482731
I can try to cook you up something, what all do you need?
>>
>download android studio
>it's 500mb
>it starts downloading an additional 1gb
>tmp partition fills up
>it crashes
so this is the power of android
>>
>>61482771
No, that't the power of Bloated IDE.
And also, you being a brainlet.
>>
>>61482771
> Android Studio
kek, literally the worst IDE ever

> additional 1GB
that's the fucking simulator
>>
>>61482731
http://www.sonniss.com/gameaudiogdc2017/
Consider this.
I'm not sure how much this overlaps with opengameart. But they're relatively high quality compared to most sources I've found.

You can also look at earlier years.
>>
>>61482771
I just uninstalled it after seeing it took 5gb on disk.
I have difficulty understanding how you manage to bloat software that hard. They don't have a bunch of image assets that could possibly take that space. I should have looked into what files make up the most of that.
Visual studio is another hog and I just don't see how they make it that big.
>>
File: mfw.png (313KB, 418x418px) Image search: [Google]
mfw.png
313KB, 418x418px
>>61482771
>using anything based off JetBraindead unIntelliJ ImDEAdinside
>>
asm("xchg %0,%1\n\t" : "+r" (x), "+r" (y) : "r" (x), "r" (y));


swap for register values in a single instruction
>>
File: reee.png (17KB, 472x69px) Image search: [Google]
reee.png
17KB, 472x69px
>>61481151
`if` only has two child expressions: one for when the condition is true, and optionally one for when it is false.
If you want multiple things to happen when a condition is true/false, you will need to wrap them with a `begin`, similar to `progn` in CL. Alternatively, since you have a repeated pattern of
(if cond (begin foo bar))

you could write a macro to simplify this (like CL's `when`).
>>
>There are seriously people in this thread who would use globalist botnet software such as Visual Studio, Sublime and Eclipse over the socialist-endorsed text editor Vim
>>
>>61483027
>there are seriously people in this thread who use vim instead of ed
>>
>>61483027
>Visual Studio
I use it as a debugger.
It's pretty nice for that.
>Vim
It would never be as convenient as VS or me as I do a lot of remote debugging.
>>
>>61483036
>>61483027
>there are seriously people in this thread who don't use
cat > file
>>
File: real_programmers.png (83KB, 740x406px) Image search: [Google]
real_programmers.png
83KB, 740x406px
>>61483056
>there are seriously people in this thread who don't use butterflies
>>
>>61483027
>burning money on Africans
Vim is trash.
>>
File: fuk_ur_mom.png (35KB, 697x315px) Image search: [Google]
fuk_ur_mom.png
35KB, 697x315px
>>61483037
also try reading the error and see if you can work shit out yourself
if you don't understand the syntax etc. of a language start doing things small. Scheme/lisp is gud, once you have the basics down, everything just composes or some shit
>>
>>61483072
>eddy currents
What did he mean by this?
Seems like they're mixing things up here. I mean sure it's so outlandish that they might mean eddy currents.
>>
>>61481399
>they couldn't import a package
>they're experienced programmers
I'm confused.
I guess you just work for a company of incompetent programmers.
>>
>>61483110
https://en.wikipedia.org/wiki/Eddy_(fluid_dynamics)
I think he means eddies, not eddy currents.
>>
>>61483044
this
I don't think there is a person in this world who unironically uses gdb+vim
>>
>>61483148
I still do (though I prefer cgdb over plain gdb).
>>
File: 1491733159198.jpg (43KB, 450x443px) Image search: [Google]
1491733159198.jpg
43KB, 450x443px
>>61483148
>tfw I unironically use Vim/GDB or, as I've recently taken to calling it, Vim+GDB
>>
>>61483146
That does make way more sense.
He could still mean Eddy currents but it's a roundabout way of putting it at best.
>>
File: 1491873683712.gif (969KB, 225x225px) Image search: [Google]
1491873683712.gif
969KB, 225x225px
>Second year undergraduate CS student
>Applying for programming internships
>Haven't done a single project
>>
>>61483214
youll fit right in then
>>
File: 1200px-Blank_whiteboard.jpg (62KB, 1200x900px) Image search: [Google]
1200px-Blank_whiteboard.jpg
62KB, 1200x900px
>>61483214
Can you inverse a tree though, huh, kid? Can you count graph automorphisms? Can you or can you not write counting sort right here, right now, on the spot, champ?!
>>
>>61483257
no, no, and no.
>>
>>61482700
>[1,2,3].map!(pow(2)).writeln
>>
>>61483299
pow needs two args
>>
What kind of file should I use to read a couple of doubles and rewrite one of them after some calculations in java?
>>
>>61483333
xe did pass 2 :^)
>>
>>61483365
uwotm8
>>
>>61483340
>What kind of file
What do you mean?
>>
I can't write this stupid fucking exercise from K&R and it's making me feel retarded.

>Write a function invert(x, p, n) that returns x with the n bits that begin at position p inverted
>>
How to I find the 'middle' of a for loop when
for(a = b; a < c; a = a + d)
>>
>>61483452
>
a < c;

it's this part anon
>>
>>61483452
length / 2
>>
>>61483479
(a+c)/2 don't work because of the a = a + d
>>
>>61483428
CSV, XML, binary, txt, etc.
Binary is out of the question because I want it to be humanly readable.
The question might be stupid because I'm not a programmer. I just want an efficient format that also lets me change one of the values without too much trouble.
>>
>>61483498
Or maybe I just keep the values that the program itself updates in a different file.
>>
Guys I've been writing python code for a year and just got my first dev job. I'm 25 and I feel like I've finally found something that I could do until I die without getting bored. I want to learn C or C++ next, can anyone recommend me some good CS books that could help me make up for my lack of knowledge in that area? I don't have a CS degree and don't want to pay for college.
>>
>>61483559
Learn lisp instead
>>
>>61483498
>>61483528
CSV is probably the best choice if you're just working with an array of doubles. Text (using newlines as delimiters) might be somewhat easier to read, but would run into portability issues.
>>
>>61483587
Thanks anon.
>>
>>61483582
fuck off kike
>>
>>61483559
https://archive.org/details/TheCProgrammingLanguageFirstEdition
>>
I want to write a script to scrape specific posts from a MyBB forum. What language will make this the least painful?
>>
>>61483659
qBasic
>>
>>61483659
python with selenium?
>>
>>61483675
>Microsoft
>>61483684
Thanks, I'll look into Selenium. I know basic python already
>>
How can I improve this function, strend?

/*EXERCISE 5.4 - Write the function strend(s, t), which
returns 1 if the string t occurs at the end of string s,
and zero otherwise */
#include <stdio.h>

int strend(char *s, char *t)
{
for(; *s != '\0' ; s++)
for(char* temp = t, char* s_copy = s; *s_copy == *temp; temp++, s_copy++)
if(*temp && *s_copy) return 1; /* we're done if the characters all match and we reach the end of the string */
return 0;
}

>>
>>61483655
>>61483559
pdf version
http://net.pku.edu.cn/~course/cs101/2008/resource/The_C_Programming_Language.pdf
>>
>>61482731
I can make you some stuff. I use a bass and an old mpc and can send you some stuff.
>>
>>61483713
1. Reformat it to fit into 72 columns.
2. Relocate declarations from the for loop to the beginning of the function block.
3. Place the indirection operator in pointer declarations adjacent to the identifier name, rather than the type pointed to.
>>
>>61483713
writefln("%s", "abc def ghi".endsWith("ghi") ? 1 : 0);
>>
File: 12506712.jpg (20KB, 331x315px) Image search: [Google]
12506712.jpg
20KB, 331x315px
>>61483776
This is why people don't use C anymore
>>
>>61483776
>calling a member function on a string literal
>>
>>61483806
That's not a member function
>>
>>61483659
Something with an HTML DOM. Unironically, JavaScript.

>>61483806
>not calling a method on a number literal
Math.PI.toFixed(2)
>>
>>61483659
Python

>>61483559
>spending a year on python
Good lord anon.
Here's a list of CS books from my university's CS program, theres a lot of overlap so pick one book from each section which you think sounds the most interesting/useful:
>Computer Architecture
>Stallings, W, 2012, Computer Organization and Architecture
>Tanenbaum, A, 2012, Structured Computer Organisation
>Clements, A., 2006, The Principles of Computer Hardware

>Network fundamentals
>Forouzan, B.A., 2012, Data Communications and Networking,
>Elahi & Elahi, 2006, Data, Network and Communications Technology
>Stallings, W., 2010, Network Security Essentials: Applications & Stanards
>Schiller, J., 2003, Mobile Communications

>Operating systems
>Tanenbaum, A. S., 2008, Modern Operating Systems 3e
>Tanenbaum, A. S. and Woodhull A. S., 2006, Operating Systems: Design and Implementation 3e
>Patterson, D.A. and Hennessy, J.L., 2009, Computer Organization and Design - The Hardware/Software Interface 4e

>Databases
>Elmasri, R. and Navathe, S.B., 2004, Fundamentals of Database Systems
>Pratt J, Last M, 2009, A Guide to SQL
>Connolly, T. and Begg, C., 2015, Database Systems: A Practical Approach to Design, Implementation and Management

>Data structures and algorithms
>M. Goodrich & R. Tamassia, 2015, Algorithm Design and Applications
>E Koffman and Paul A T Wolfgang, 2016, Data Structures, Abstraction & Design Using Java

>Some web shit the uni was pushing
>Goodman, D., 2007, Dynamic HTML - the definitive references
>Herron, D, 2016, Node. JS Web Development Third Edition

>Software engineering
>Pressman, R., 2000, Software Engineering: a Practitioner's Approach
>B. Bruegge, A.Dutoit, 2010, Object Orientated Software Engineering Using UML and Java 3rd Ed

>Parralel Programming
>Tanenbaum, A.S. & Maarten, V.S., 2014, Distributed Systems, Principles and Paradigms

Thats up to third year material, the rest is fuzzy logic, security and advanced networking. Also, go through K&R right now.
>>
>>61483844
name
>>
File: mesosad.jpg (82KB, 944x712px) Image search: [Google]
mesosad.jpg
82KB, 944x712px
>Think of myself is a pretty meh programmer
>Try leetcode to see what the fuss is about
>Even the easy problems stump me
>When I do finally have a solution I'm implementing it wrong

Maybe I'm stupid after all.
>>
>>61483655
>>61483749

Got it, I'll read these. Any stuff thats lower level that will help me grasp whats going on when I write stuff in python? I was thinking of playing around with assembly for the education.
>>
>>61483862
whats one that stumped you?
I already know im a shit programmer, but i'd like a reminder.
>>
>>61483713

int strend(char *s, char *t)
{
char *u = t;

while (*++s);
while (*++t);
while (t > u && *s-- == *t--);

return t == u;
}
>>
>>61483844
Thanks for the list anon.
>>
>>61483875
this is old (32 bit ASM), but I hear it's a great book on ASM
https://download-mirror.savannah.gnu.org/releases/pgubook/ProgrammingGroundUp-1-0-booksize.pdf


if you ever want to learn some more abstract stuff, you gotta read the SICP
http://web.mit.edu/alexmv/6.037/sicp.pdf

and if you walk away from that wanting to write more lisp, common lisp is a good dialect, and this is the most fun book to learn it in
http://www.gigamonkeys.com/book/
>>
>>61483812
Sure looks like one.

>>61483824
>Math.PI.toFixed(2)
Math.PI is not a literal.
>>
>>61482700
what language is that

>>61483713
you're not declaring using proper C syntax there. get rid of the char* before s_copy

first off you're incrementing s_copy past the end of the string - this doesn't work. next problem is you return 1 if your characters are equal on the very first iteration...

here's a working solution that doesn't use strlen
int strend(char *s, char *t) {
for(; *s; s++);
size_t l = 0;
for(; *t; t++) l++;
for(; l; l-- ) if(*--s != *--t) return 0;
return 1;
}


except >>61483888 is better
>>
>>61483941
Whenever you see a "writeln" ITT, it's probably D
>>
>>61483824
>not a literal
fuggg, busded XDD
(123.456).toFixed(2)
>>
>>61480530
>>61480842

Govno is the Russian word for "shit" apparently, and "Govnokod" means "shit code"

http://govnokod.ru/
>>
>>61483941
Actually, mine didn't properly check the length of s, here's a fixed version

int strend(char *s, char *t)
{
char *u = s;
char *v = t;

while (*++s);
while (*++t);
while (s > u && t > v && *s-- == *t--);

return t == v;
}
>>
>>61483984
lmao mine doesn't either. this is why memory safe languages are a thing
>>
>>61483438
Just break it out into functions?
#include <stdio.h>

int get_bit(int x, size_t n)
{
return (x & (1 << n));
}

int set_bit(int x, size_t n, int set)
{
if (set) {
return (x | (1 << n));
} else {
return (x & (~(1 << n)));
}
}

int invert(int x, size_t n, size_t p)
{
int result = x;

for (size_t i = 0; i < n; ++i)
{
result = set_bit(result, n + p - 1 - i, get_bit(x, i + p));
}

return result;
}

int main()
{
printf("0x%x should read 0x122b34\n", invert(0x12d434, 8, 8));
return 0;
}
>>
>>61483941
Its D
void main()
{
import std.algorithm: map;
import std.math: pow;
import std.stdio: writeln;
[1,2,3].map!(x => pow(x , 2)).writeln;
}
>>
>>61484007
well, ideally, if we were given the lengths of the buffers explicitly, we would have

int strend(char *s, size_t s_len, char *t, size_t t_len)
{
char *u = s + s_len;
char *v = t + t_len;

while (u > s && v > t && *u-- == *v--);

return v == t;
}


but yes, safe buffer handling is a major weakness of C
>>
>>61483713
qbool MyApplication::Strings::QStrend(const QString& s, const QString& end)
{
return s.endsWith(end);
}
>>
>>61483969
>(123.456).toFixed(2)
That's disgusting. At least do
(new Number(123.456)).toFixed(2);
>>
>>61483974
That's interesting, thanks.
>use google translate
>line numbers turn to shit like "thirty" and "17th"
>>
>>61484036
declare your imports at the top of the file not the top of the method you autist
>>
>>61483806
It's valid to call member functions on string literals. Don't micro-optimize unless you need to.
>>
>>61484058
D is not C, local imports are a thing for a reason.
Use import at the nearest reasonable scope.
>>
>>61483885
>Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice.

I just made a nested for loop (i =0, and j = i+1) and then checked if the values when added equaled the target. Apparently my solution was full of errors and I gave up trying to figure out what was wrong.
>>
>>61484036
What's the point of distinct imports like that? D is not an interpreted language static imports exist
>>61484058
>>
>>61484078
Because in functions you can only import and bring what you need intsead of having one giant wall of them at the top. It helps to keep things modular and clean.
>>
>>61484071
I have written D before, don't assume I don't know shit

you're cluttering the file with useless per-method fluff that would honestly be better off as a file-level declaration and not a per-method declaration unless for some reason you /really/ needed that
>>
File: Vqr4p1E.png (116KB, 1515x663px) Image search: [Google]
Vqr4p1E.png
116KB, 1515x663px
>>61477059
>Going after my Bachelors in Comp Sci.
Should I go for a BA or BS, the BS seems more obvious but I've never taking any math past Trig and Calculus/Discrete Mathematics scare me.
>>
>>61484088
you can import only*
You dont have to*
>>
>>61484050

Why would you unnecessarily allocate extra memory? I think that:
[code123.456.toFixed(2);[/code]
is ideal.
>>
File: comfy black man.jpg (36KB, 600x800px) Image search: [Google]
comfy black man.jpg
36KB, 600x800px
what does your CVs personal profile look like, /g/? im trying real hard not to sound like an autist but its not working
>>
>>61484097
do your math m8, theres some shit you straight up wont get without a proper understanding of some higher level mathematics, and changing your course wont solve that
>>
>>61477905
>>61477998

Life isn't fair. Stop being a whiny little bitch. Doesn't matter how good you are at something no one wants to work with someone who has a shitty attitude ergo you'll never get hired.
>>
>>61484096
compare:

void range_pow(int[] range)
{
import std.algorithm: map;
import std.math: pow;
import std.stdio: writeln;

[1,2,3].map!(x => pow(x , 2)).writeln;
}

void main()
{
int[] range = [10,20,30,40];
range_pow(range);
}


vs
import std.algorithm: map;
import std.math: pow;
import std.stdio: writeln;

void main()
{
[1,2,3].map!(x => pow(x , 2)).writeln;
}
>>
>>61484130
oops, forgot to actually use the range, but you get the idea.
>>
>>61484130
you're comparing apples to oranges there m8, those are definitely not the same

import std.algorithm: map;
import std.math: pow;
import std.stdio: writeln;

void range_pow(int[] range)
{
range.map!(x => pow(x, 2)).writeln;
}

void main()
{
int[] range = [10,20,30,40];
range_pow(range);
}


this looks quite fine compared to unnecessarily putting the imports inside the range_pow delcaration
>>
>>61477059
Qsort isn't good enough performance, so I'm writing a bubblesort.
>>
reminder that idris is such a memelang it literally lets you invent new numbers
data x: Nat

x is not a declared but undefined variable, the data keyword makes its declaration its definition so it's actually an entirely new Nat guaranteed not to be an alias of any existing Nat
in other words x is just a new fucking number now
there's 1, 2, 3, etc
and then off to the side somewhere there's just
x
>>
>>61484149
My point is scope-local imports are superior because you know exactly what is being used where instead of having to traverse a block of imports at the top. Its a bad habit from too much C / C++ use. The example would work better with more extended code but i cant be fucked.
>>
>>61484169
>Hello, Im from Mt. Stupid, listen to my silly tales of ignorance
>>
>>61484097
Go for the BSc and pickup "Mathematics for Engineers" by Anthony Croft and Robert Davidson. Then sit down daily with it for 1-2 hours. That should give you about 2/3 of the maths you need and that final third will be fairly easy if you put the work into the first 2/3.

A BA will put you at a massive disadvantage on the job market if you're competing against people with a BSc.
>>
>>61484187
how is it ignorance if I'm right
try it yourself if you don't believe me
>inb4 "it gives me a warning so it's not valid idris anyway"
no
wrong
it gives you a warning and therefore it's BAD idris
it WORKS, and therefore it's still VALID idris
>>
>>61484175
I would be inclined to agree if every method you wrote was a horrific monolith but don't think that really applies for files composed of <10 smaller methods
>>
>>61484050
>new Number
Why? I like the old number.
>>
>>61484212
>of <10 smaller methods
Obviously its not necessary for quick /dpt/ snippets, but its good to do it anyway. Seeing people write D like C makes me vomit.
>>
>>61484208
X is type Nat, whats the issue exactly?
Do you not know what 'Nat' is?
>>
>>61484050
>>61484104
Sorry, but neither of you are right.

According to the ECMAScript spec, upon property access, GetValue is called on the expression being accessed: https://www.ecma-international.org/ecma-262/8.0/index.html#sec-property-accessors-runtime-semantics-evaluation

Inside of GetValue, it replaces the result with ToObject(result) if it is a primitive: https://www.ecma-international.org/ecma-262/8.0/index.html#sec-getvalue

What this means is that, from the standard's perspective, the object's being allocated either way. And converting it to an object yourself is a waste of code and time. The JS implementation is free to optimize but there's almost no chance it reacts differently between initializing with a number literal and a new Number containing a literal, since object/primitive conversion is ingrained so deeply into the JS standard and it has to be optimized everywhere.
>>
>>61484253
Yes, I know what Nat is, Nat is a natural number.
But X is not merely of type Nat. If you wanted a variable X of type Nat, you'd do this:
X: Nat
And then you'd presumably define it, because if you just left it declared but undefined, it would be reported as a hole.
But the fact that I'm instead doing
data X: Nat

makes X a variable holding a NEW value of type Nat. It's not just any Nat, it's X, and X is the Nat which it is, and there is no other Nat which it is other than X. X is the only natural number that is X. It's not a variable holding some other number, it IS the number, specifically it's a number we just fucking invented.
Because Idris lets you do that.
Because it's a piece of garbage.
>>
File: smug_animu.png (349KB, 477x530px) Image search: [Google]
smug_animu.png
349KB, 477x530px
CONST = 1
CONST = 2
puts CONST

class Holder
@@var = 99

def Holder.var=(val)
@@var = val
end

def var
@@var
end
end

@@var = "top level variable"

a = Holder.new
puts a.var
Holder.var = 123
puts a.var

class Top
@@A = "top A"
@@B = "top B"
def dump
puts values
end
def values
"#{self.class.name}: @@A = #@@A, @@B = #@@B"
end
end

class MiddleOne < Top
@@B = "One B"
@@C = "One C"
def values
super + ", C = #@@C"
end
end
class MiddleTwo < Top
@@B = "Two B"
@@C = "Two C"
def values
super + ", C = #@@C"
end
end
class BottomOne < Middle One; end
class BottomTwo < Middle Two; end

Top.new.dump
MiddleOne.new.dump
MiddleTwo.new.dump
BottomOne.new.dump
BottomTwo.new.dump


>rubyfags will defend this
>>
>>61484227
> quick /dpt/ snippets
I generally try my hardest write all my code in files of methods no more than 20 lines and no more than 10 methods. If I have to go over, it's usually relegated to boilerplate or copypasta code.

More than two screens of code and I'll probably try to think of a way to split the design.

Locally scoped imports are, under this method of coding, literally just redundant fluff. All you have to do is press PgUp to find an external definition that wasn't in the file.
>>
>>61484281
Wow, its like you dont understand the purpose of dependent types.
>>
>>61484292
>CONST = 1
>CONST = 2
irb(main):001:0> CONST = 1
=> 1
irb(main):002:0> CONST = 2
(irb):2: warning: already initialized constant CONST
(irb):1: warning: previous definition of CONST was here
=> 2
irb(main):003:0>

Shit code tbhfam.
>>
>>61484292
gtfo cunt that's not even valid ruby
>>
>>61484307
That's the point famalam

>>61484311
It is valid you shitstain
>>
>>61484227
Then I might make you cringe
object
.method
.method
.method
.method
.method;

Not him btw :^)
>>
>>61484298
>arbitrary limits
i mean okay, but thats dumb. D by nature keeps things relatively simple though so i dont have to worry.
>have to do more work to check things
But why, when you could just have them right there. You need to let go of C habits m8.
>>
>>61484315
no it isn't autist

$ ruby /tmp/test.rb
/tmp/test.rb:2: warning: already initialized constant CONST
/tmp/test.rb:1: warning: previous definition of CONST was here
2
/tmp/test.rb:17: warning: class variable access from toplevel
top level variable
123
/tmp/test.rb:49:in `<main>': uninitialized constant One (NameError)
>>
>>61484306
Wow, it's like you don't understand the inarguable fact that
data X: Nat

just fucking invents a new number called X that didn't exist before.
Purpose of dependent types my ass, there is never an excuse to invent a new possible value of a type that ought to be closed to such operations, such as a number line.
If you need a subtype of Nat that only applies to Nats > 13 for example, you fucking declare that, you don't just invent a new god damn number.
>>
>>61484328
Stick to hasklet m8, Idris seems to be too much for you.
>just fucking invents a new number called X that didn't exist before.
Why does this matter? Its not like you can just break the universe with entirely new maths. Idris's whole point is fine-grained types.
>>
>>61484326
Yeah, it still works, all it does is give an error. Also, the final error was because there was an error in the code because I accidentally put spacing in the class name it should be:
class Top
@@A = "top A"
@@B = "top B"
def dump
puts values
end
def values
"#{self.class.name}: @@A = #@@A, @@B = #@@B"
end
end

class MiddleOne < Top
@@B = "One B"
@@C = "One C"
def values
super + ", C = #@@C"
end
end
class MiddleTwo < Top
@@B = "Two B"
@@C = "Two C"
def values
super + ", C = #@@C"
end
end
class BottomOne < Middle One; end
class BottomTwo < Middle Two; end

Top.new.dump
MiddleOne.new.dump
MiddleTwo.new.dump
BottomOne.new.dump
BottomTwo.new.dump
>>
I want to create a project that boils down into accepting a user paste (not free input), analyzing that data and spitting out some conclusions about that data after scrapping a relevant webpage. I want to present it in a neat little GUI, but I've never done anything with an actual GUI before. And that's my problem. What would be the best approach to this? I immediately went to python/a web solution, but I'll take any ideas.
>>
>>61484346
>>61484326
Fuck, I mean
class Top
@@A = "top A"
@@B = "top B"
def dump
puts values
end
def values
"#{self.class.name}: @@A = #@@A, @@B = #@@B"
end
end

class MiddleOne < Top
@@B = "One B"
@@C = "One C"
def values
super + ", C = #@@C"
end
end
class MiddleTwo < Top
@@B = "Two B"
@@C = "Two C"
def values
super + ", C = #@@C"
end
end
class BottomOne < MiddleOne; end
class BottomTwo < MiddleTwo; end

Top.new.dump
MiddleOne.new.dump
MiddleTwo.new.dump
BottomOne.new.dump
BottomTwo.new.dump
>>
>>61484345
>Why does this matter?
Because it's inelegant.
>Its not like you can just break the universe with entirely new maths.
Yeah, but it's inelegant.
>Idris's whole point is fine-grained types.
YEAH BUT IT'S FUCKING INELEGANT.
Why would you ever declare an entirely new, previously nonexistent natural number.
The fact that it doesn't "break the universe" is irrelevant, it simply makes no goddamn sense and has no conceivable use case that wouldn't be better suited by an approach less resembling dark magic, such as a monad.
I don't care that you can just not do it if you don't want to, it's so utterly disgusting that it shouldn't even be legal, and I therefore revile the fact that it is.
>>
>>61484320
The best kind of writing is constrained writing. It is the same with coding. You have to really think about what you want to do in order to get a good design.

Method length is one of the most important factors of code readability. Not cluttering the method declaration with imports goes a ways towards reducing method length.


>>61484358
@@class_vars behave strangely in Ruby due to some fuckery by Matz. You can try using class-level @ivars instead. IIRC those will behave as expected.
>>
>>61484381
>such as a monad.
Ah yes, the hasklet reveals himself at last.
>>
just switched from guile 2.0.12 to guile 2.2.2
what am I in for lads
>>
>>61484394
>its the same with coding
Not really, having to force arbitrary limits for KISS is silly. If your function is 21 lines it does not make a difference. If you split that function into 2 because you cant keep to your limits then thats an issue.
>>
New thread, now with double dubs:

>>61484433
>>61484433
>>61484433
>>
proper new in a sec lads hold on
>>
>>61484428
They're not hard limits. They're guidelines. Shakespeare didn't write every line in exact iambic pentameter, he just stuck to it more often than not.
>>
>>61484444
waiting on you Mr quads
>>
>>61484398
>implying monads are a haskell thing
If you honestly think using a dedicated new natural number you invented out of thin air to mean "nothing" is a better paradigm than just Maybe Nat you're delusional
>>
proper new
>>61484482
>>61484482
>>61484482
>>
New thread
>>61484482
>>61484482
>>61484482
Thread posts: 335
Thread images: 37


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