[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 33
File: new year cola.png (2 MB, 1920x1080) Image search: [Google]
new year cola.png
2 MB, 1920x1080
old thread: >>52181140

Have you had your morning cola today?
>>
>>52184052
My local McD's sales refills for 60 cents. I just went and got 100 ounces of Coca Cola for $1.20
>>
>>52184072
>100 ounces of cola

But.. why?
>>
Don't post new threads before the bump limit, fag.
Delete this shit.
>>
In C, what constitutes an opaque type?

stackoverflow describes the FILE typedef as an opaque type, but what makes it an opaque type?
>>
>>52184078
Don't be jealous.
>>
>>52184052
stupid umaru poster
even the hime faggot was better
>>
>>52184085
One that you know nothing about the members of and is implemented in an unseen library source file.
>>
>>52184109
So does that mean that no struct typedef that i create can be considered opaque, since I designed it and know exactly how it is implemented?
>>
Threadly reminder that you should not refer to the act of programming as coding. It is improper and makes you look like a 15 year old

You are a programmer, not a coder
>>
>>52184052
sleep tight hammers
>>
File: ayy.png (174 KB, 437x512) Image search: [Google]
ayy.png
174 KB, 437x512
>>52184052
just finished
>>
>>52184085
struct thing;

That is an opaque type. It's not defined in that translation unit.
You can still pass pointers to this type around, but you cannot access this type directly.
>>
>>52184052
No, but I've had this
>>
>>52184116
I suppose if your memory is real good no type you ever design would be opaque.
>>
>>52184131
so C is confirmed cool?
>>
>>52184139
>you cannot access this type directly
but why?
Does it not have any members?
Or is there a special C keyword in it's header prototype declaration that prevents me from accessing it's members?
>>
>>52184116

It means that the user shouldn't know what the fields are and how it operates internally.

They should just know that using structType_doThis and structType_doThat do what you expect them to do.
>>
>>52184152
I mean if you think being old is cool....
>>
File: dojo-photos-1.jpg (99 KB, 480x360) Image search: [Google]
dojo-photos-1.jpg
99 KB, 480x360
>>52184131
This is more accurate for Python
>>
>>52184072
you don't have free refills?
usually, the policy is unlimited refills on the same visit only, but that doesn't stop some people from bringing back their cups or simply bringing a giant thermos and stealing soda
>>
>>52184154
>but why?
Because the compiler does not know what the struct contains, so it cannot generate any offsets or whatever to access anything.
Each compilation is separate, so the library code knows what it contains, but the client code does not.

Here is an example of how opaque types are used:
/* public_header.h */
struct test;


struct test *new_struct();
/* lib_implementation.c */
#include "public_header.h"

struct test {
int a;
};

struct test *new_struct()
{
struct test *t = malloc(sizeof *t);
t->a = 10;
return t;
}

/* client_implementation.c */
#include <public_header.h>

int main()
{
struct test *t = new_struct();
}
>>
>>52184201
>stealing
I'm not black
>>
>>52184213
>struct test *new_struct();
That's supposed to be a part of the code block above it.
>>
>>52184213
>struct test *t = malloc(sizeof *t);

So close, yet so far away.
>>
File: circles.png (1 MB, 1750x900) Image search: [Google]
circles.png
1 MB, 1750x900
>>52184052
No, but I've had this
>>
>>52184240
Never fucking reply to me again unless you are contributing to the thread.
>>
>>52184052
>>52184124
I'm really starting to get concerned about the amount of cola and snacks this girl is consuming.
>>
>>52184232
What are you memeing about?
>>
File: isthisniggaserious.png (16 KB, 409x270) Image search: [Google]
isthisniggaserious.png
16 KB, 409x270
>>52184244
>>
File: xTIe9QX.png (62 KB, 608x531) Image search: [Google]
xTIe9QX.png
62 KB, 608x531
>>52184240
>>
>>52184250
Can't back up a struct with only the space for a mere pointer to it.
>>
I have been looking through documentation on rust's linking process, and how .rlib shit is supposed to compare to the .a and .so files I am used to on C and C++.

>>52184154

No keyword, it's just that the struct definition doesn't exist. When I make something like:

struct foo;


That tells me, "there is a struct type called foo." At this point, I can make a pointer to an object of type foo. What I can't do is declare an object of type foo on the stack. Why? Because I don't know how big it is and I don't know what its members are. If you do something like:

struct foo bar;


The compiler's basically going to ask "the fuck you want me to do? How big is bar supposed to be? I don't fucking know!". But if instead you do this:

struct foo *bar;


The compiler's just going to assume bar is the size of a void pointer, and whatever it points to is someone else's problem. But you can't do pointer arithmetic with it, because it doesn't know what *(bar + 1) even means.
>>
>>52184272
You don't know C, do you?
It's allocating the size of what t is pointing to.
>>
>>52184283

It's 'preferred' only by shitters. Just use sizeof(struct type).
>>
>C can refer to a name declared on the LHS of an assignment in the RHS
What the fuck
>>
File: 1446332888264.png (711 KB, 1600x2162) Image search: [Google]
1446332888264.png
711 KB, 1600x2162
>>52184293
>Violating the DRY principle for absolutely no reason
Fucking idiot
>>
File: circles2.png (720 KB, 1750x900) Image search: [Google]
circles2.png
720 KB, 1750x900
>>52184262
I forgot to align one correctly
>>
>>52184311
>using sizeof(struct type) violates DRY

sudoku
>>
>>52184131
java should be an indian

javascript should be the hipster
>>
>>52184324
struct test *t = malloc(sizeof *t);

>Variable written twice
>Change type: Just werks
>Change variable name: compilation error, because 't' doesn't exist. Allows you to find and fix the error
struct test *t = malloc(sizeof(struct test));

>Type written out twice
>Change type: passes compilation and secretly fucks up your code, being hard to track
>Change variable name: No difference
>>
QUICK; POST CODE TO GENERATE 100 FIBONACCI NUMBERS FROM 1,1 IN YOUR LANGUAGE OF CHOICE
>>
>>52184366
Not doing your homework for you
>>
>>52184274
>>52184213
Alright, this makes sense.
Let's say I want to avoid making my types opaque and want the user to have full access to the struct members.
Where would I put their struct prototypes?
In the header file?
>>
>>52184363
>>Change type: Just werks

That's never going to happen.
>>
>>52184378
>Where would I put their struct prototypes? In the header file?
Yes
>>
>>52184354
I think I should switch Haskell and Java out,
>m-muh functional language
>>
>>52184311
struct object *ptr = (struct object *) malloc(sizeof(struct object));
>>
>>52184381
>Originally allocating float
>Decide you need more accuracy, change to double
I don't see that sort of case being uncommon. Obviously you wouldn't allocate a single float or whatever, but the effect only gets worse with arrays.
>>
>>52184386
So there's no way to keep the full struct prototype in a separate .c file without making it an opaque type?
>>
Holy shit.

Guy in /agdg/ is trying to argue that C structs are objects (as in OOP) because when you allocate a struct you are actually allocating a "struct shaped object", and that all "object" means is "data in memory".
>>
Hey guys can anyone help? I'm going through A smarter way to learn Javascript and I'm stuck on this problem here:
var cleanestCities = ["Cheyenne", "Sante Fe", "Tucson", "Great Falls", "Honolulu"];
var cityToCheck = prompt("What is yor city?");

var matchFound = false;

for (i = 0; i <= 4; i++); {

if (cityToCheck === cleanestCities[i]) {
matchFound = true;
alert ("it's one of the cleanest cities");
}
}
if (matchFound === false) {
alert ("it's not on the list");
}

I can't get "it's one of the cleanest cities" to print out after typing one of the cities in the array into the alert box. It just goes straight to "it's not on the list" I'm trying to utilize a flag variable, but it's not working. Any help would be appreciated. Also, anyone have any js resources they highly recommend?
>>
>>52184366
fib = [1,1]
for i in range (98):
fib.append(fib[-1] + fib[-2])


>>52184372
??? It's not
>>
>>52184423
He's not wrong, you know.
OOP existed before OOP was even a word.
You probably think objects aren't objects unless they have 100 member functions in them
>>
>>52184366
fib:
stosd
xadd ebx, eax
loop fib
ret
>>
>>52184421
>So there's no way to keep the full struct prototype in a separate .c file without making it an opaque type?
It's opaque to OTHER source files. It's not opaque to the source file itself
>>
>>52184423
K... KEEP ME POSTED
>>
>>52184439
I understand that structs can be used to implement objects, but structs are not objects.

It might help to note that he is saying this to "prove" that something totally unrelated to OOP implemented in C using structs is actually OOP.
>>
>>52184449
based
>>
>>52184423
It's a useless definition because then everything becomes 'objects'.
>>
>>52184366
Wrote this last night when I was hammered beyond common speech

I think I posted it here last night

def main
100.times do |i|
puts fibo(i)
end
end

def fibo(n)
if n == 0
return 0
elsif n == 1
return 1
else
return fibo(n-1)+fibo(n-2)
end
end

main
>>
>>52184411
>I don't see that sort of case being uncommon.

Hmm, fair enough. I was really only thinking about its use in the implementation of your opaque data type.
>>
>>52184423
That's a pretty fucking broad definition of an object.
>a 'char' is an object
>a struct as an object
>a pointer is an object
>the stack is an object
>>
>>52184480

...

def fibo(n)
if n < 2
return n
else
return fibo(n-1)+fibo(n-2)
end
end

...



return n if n < 2
>>
for (i = 0; i <= 4; i++); {


Get rid of the semicolon after the closing parenthesis.
>>
How can I compile scheme on windows? I have MinGw installed
>>
>>52184480
>>52184505
Jesus fuck, that is inefficient.
>>
>>52184509
http://stackoverflow.com/questions/304815/scheme-ide-for-windows
>>
>>52184131
What's the picture for common lisp?
>>
>>52184529
Nobody said anything about optimization

Also fibonacci problem is older than my balls, everyone knows you can optimize this shit
>>
>>52184529
Yeah it looks pretty but goes slow as fuck.
>>
File: 1438564025693.jpg (147 KB, 632x576) Image search: [Google]
1438564025693.jpg
147 KB, 632x576
>>52184529
I did state I was drunk beyond common speech
>>
>>52184124
but senpai I'm a hacker
>>
>>52184563
Bullshit, a drunk person would go with the obvious implementation that also happens to be a million times faster than the pretty one.
>>
>>52184585
>implying the naive O(n!) solution is at all pretty compared to the godly O(n) recursive implementation
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
>>
One more question about opaque types.
I've noticed that many libraries will use what appear to be opaque data types for passing data between function calls, but they're not actually opaque, since you're free to put them on the stack.
regex.h does this with the regex_t type
openssl/md5.h does this with the MD5_CTX type

Should I just avoid opaque types when writing library code?
>>
>>52184585
desu family that's the first time i've implemented the fibo sequence

I lied a little and pulled it from memory

here was my first implementation of the fibo sequence

static void Main(string[] args)
{
int MAX_VALUE = 200;
int FiboNum = 0;
while (FiboNum < MAX_VALUE)
{
Console.WriteLine(Fibo(FiboNum));
FiboNum++;
}
}

public static long Fibo(long n)
{
if (n == 0)
{
return 0;
}

if (n == 1)
{
return 1;
}
else
{
return(Fibo(n-1)+Fibo(n-2));
}


}
>>
>>52184598
Opaque types solve a problem, which is primarily about ABI and less about encapsulation. If you don't have that problem, you don't need to use opaque types.
>>
>>52184603
if (n < 2)
{
return n;
}
>>
>>52184366
forget all these scrubs you don't need to be able to find the nth number, only output them in sequence
int main() {
unsigned long long fib[2] = {1,1};
for (int i = 0; i < 100; i++) {
cout << fib[i%2] << endl;
fib[i%2]+=fib[i%2-1];
}
return 0;
}

desu

it'll only make it to the 93rd number, haven't tested it though
>>
>>52184598
>Might consider changing the type in a future version
Opaque type
>Type is set in stone, it's never going to change
Non-opaque type
>>
>>52184624
>i%2-1
FUCK
(i+1)%2)
>>
>>52184635
That's a pretty overly conservative criterion for choosing to use an opaque type. Breaking ABI changes are to be expected between major versions, for example.
>>
>>52184638
okay that is not what I wrote at all
what's up with code tags only showing up when they feel like and butchering all of my perfect square brackets when they do?
[(i+1)%2]
>>
>>52184661
[(i+1)%2]
>>
>>52184052
U M R
M
R

Umaru is so precious. I wan to to adopt one.
>>
>>52184427
var cleanestCities = ["Cheyenne", "Sante Fe", "Tucson", "Great Falls", "Honolulu"];
var cityToCheck = prompt("What is yor city?");

var matchFound = false;

for (i = 0; i < cleanestCities.length; i++) {
if (cityToCheck === cleanestCities[i]) {
alert("it's one of the cleanest cities");
matchFound = true;
break;
}
}
if (!matchFound) {
alert("it's not on the list");
}


You don't want a semicolon on this line
for (i = 0; i <= 4; i++); { 


Also if you're done with your for loop, you should always break out of it so you don't keep on unnecessarily continuing when you already have the data you want. It doesn't matter so much in a small loop like this, but it's good practise to get used to it anyway.
>>
>>52184652
True. But for types that are in flux and COULD be changed in minor versions, opaque types are the way to go. You don't want to lock-out any changes you could have done or break the ABI just because you didn't use an opaque type.
>>
>>52184131
So basically if I only focus on C and Assembly, I am a respectable programmer?
>>
File: gears.webm (3 MB, 640x480) Image search: [Google]
gears.webm
3 MB, 640x480
I want to learn c++
the resources that I got are outdated
Which ones do I get?
>>
>>52184696
Respectable programmers choose the right language for the job (which is rarely C or assembly)
>>
So I'm a bit confused with the results I'm getting from SBCL and two compiled functions. I'm currently testing the performance between a recursive function and a tail-recursive function in Common Lisp, however, so far I'm getting that the recursive function is faster. Is there any particular reason for this? Here are the two functions:
(defun fac (n)
(if (= n 0)
1
(* n (fac (- n 1)))))
(defun fac (n)
(if (= n 0)
1
(* n (fac (- n 1)))))

And the results(The bottom one is the tail-recursive results):
Evaluation took:
0.001 seconds of real time
0.000874 seconds of total run time (0.000713 user, 0.000161 system)
100.00% CPU
1,588,213 processor cycles
499,392 bytes consed
---------------------------------------------------------------------
Evaluation took:
0.001 seconds of real time
0.001033 seconds of total run time (0.000843 user, 0.000190 system)
100.00% CPU
1,796,861 processor cycles
589,392 bytes consed
>>
>>52184706
>rarely
usually*
>>
>>52184715
**always
>>
>>52184710
The functions are the same. Copy paste error?
>>
>>52184710
I pasted the recursive one twice. Here is the tail-recursive function:
(defun -fac (n &optional (acc 1))
(if (= n 0)
acc
(-fac (- n 1) (* acc n))))
>>
>>52184715
Embedded is pretty rare

Note that the amount of devices is irrelevant, the amount of programs is relevant
>>
>>52184715
>>52184730
>Need to parse text files in C
>Have to literally create a text parsing library before even starting
>Couple of lines in Java, Python

Just leave fucken nerds.
>>
>>52184733
The optional parameter is fishy, to me, though I don't have any experience with optimizing SBCL.

What happens if you write the tail-recursive one with a helper function instead?
>>
>>52184744
C does have libraries, you know.
>>
If I put an enum within a struct, the enum values in that struct are only accessible when that struct is an lvalue in an expression, or do they pollute the global namespace?
>>
>>52184744
>Have to literally create a text parsing library before even starting
Once, then you can reuse it for further projects.
(If you even need it, lots of times ad-hoc parsing works just fine)
>>
>>52184765
They pollute the global namespace.
>>
>>52184767
>Once, then you can reuse it for further projects.

Yeah that really justifies weeks of extra work
>>
>>52184697
get atom
write your code in there
remember
#include <iostream>

using namespace std;

int main() {
//write some shit here
return 0;
}


use
g++ filename.cpp

in the terminal to compile
then
./a.out

to run


your tasks:
write hello world
write fizzbuzz
output the first 100 fibonacci numbers
output the first 1000000 prime numbers, without it taking over a minute to calculate
>>
>>52184773
enrich* the global namespace
>>
>>52184733
the optional parameter creates an extra runtime check for every call so it's at least another branch in the assembly/bytecode. if you require it (and optionally create a helper function) it should run faster
>>
Is Mono actually good? I sorta wanna use C# on linux.
>>
>>52184773
So is there even any point in nesting a typedef enum inside of a struct?
>>
>>52184052

God damn, debugging Theano is fucking hell on Earth.
>>
>>52184775
>weeks
Why would it take weeks just to write some text parsing code?
>>
C is only the right language choice if your time is worthless.
>>
>>52184789
Not really. enums are VERY weak in C. You could just use an ordinary int and #defines to the exact same effect, but enums are a bit more self-documenting.
>>
C is only the right language choice if C++ can't be compiled to your target platform.
>>
>>52184778
oh yeah and if you're still using windows, the time you learn c++ is about the time to switch to linux

get xubuntu for babby's first
>>
File: ferrofluid.webm (3 MB, 1280x720) Image search: [Google]
ferrofluid.webm
3 MB, 1280x720
>>52184778
thank you very much my friend
>>
>>52184788
It works well on Windows
>>
>>52184794
Has the documentation gotten any better? I remember I tried using it a year ago and it was shit.
>>
C++ is never the right choice.
>>
File: 1415785682446.jpg (127 KB, 768x1024) Image search: [Google]
1415785682446.jpg
127 KB, 768x1024
>>52184833
Why the hell would you use Mono on windows?
>>
C++ is always the right choice
>>
>>52184843

The documentation doesn't seem that terrible, just the actual debugging is, cause you're basically twice removed from the running code.
>>
Question. I have code that queries an external API and stores the results in a database. I want this code to be run 5-ish times a day, preferably at the same time every day, but can't really manually go and run it on my computer 5 times every day.

Is there some sort of service I can pay for that will do this automatically for me?
>>
>>52184874
cron jobs
>>
>>52184886
Ok, should clarify. I'm running this off my PC and I can't even guarantee that my computer will be turned on at those times every day.

Was hoping for some sort of external service I could pay for, or even better with limited free service.
>>
>>52184907
Get a VPS then.
>>
>>52184859
I wanted to see if newer Mono versions still had the same bugs as the version of Mono Unity uses
>>
>>52184747
>>52184784
The optional parameter doesn't appear to be it.
I'm now getting the following results without the optional argument(The bottom being the tail-recursive one again):
Evaluation took:
0.001 seconds of real time
0.000917 seconds of total run time (0.000761 user, 0.000156 system)
100.00% CPU
1,585,760 processor cycles
501,600 bytes consed
----------------------------------------------------------------------
Evaluation took:
0.001 seconds of real time
0.002166 seconds of total run time (0.002166 user, 0.000000 system)
200.00% CPU
1,809,797 processor cycles
588,832 bytes consed

The tail-recursive function is now:
(defun -fac (n acc)
(if (= n 0)
acc
(-fac (- n 1) (* acc n))))

Which is called with an argument of 1
>>
>>52184922
These benchmark results just look weird to me.
>200.00% CPU
>0.000000 system
>>
Trying to make c# work in my emacs config, but the indenting is wrong. I've made a function to change it, but it doesn't seem to be triggered by the hook

(defun my-csharp-mode-fn ()
(interactive)
(setq c-basic-offset 4
c-indent-level 4
c-default-style "bsd"))
(add-hook 'csharp-mode-hook 'my-csharp-mode-fn t)


Lets also hope I remember how to do code blocks
>>
>>52184922
maybe SBCL just uses a weird calling convention that makes multiple arguments really slow?
also is the 200% CPU just a typo?
>>
File: 1440868433643.jpg (36 KB, 221x397) Image search: [Google]
1440868433643.jpg
36 KB, 221x397
I have to review a codebase at my job written by another department
honestly, after all the shit added to C++ I think move semantics were the absolute worst
half of every '''modern''' codebase is now either T&& or std::move. It's literally just fucking everywhere because they can.

fuck scott meyers
>>
anyone know a language that's like python except statically typed and non-whitespace based?

basically c++ except low lines-of-code
actually ignore what I said about python, just c++ but takes less time to write is what I want
>>
>>52184963
F# with
#indent "off"
as the first line
>>
>>52184963
C
>>
>>52184938
>>52184945
Oddly enough it is not a typo. Here's the results again after running it a few times:
Evaluation took:
0.001 seconds of real time
0.000916 seconds of total run time (0.000728 user, 0.000188 system)
100.00% CPU
1,586,035 processor cycles
501,600 bytes consed
----------------------------------------------------------------------
Evaluation took:
0.001 seconds of real time
0.000990 seconds of total run time (0.000786 user, 0.000204 system)
100.00% CPU
1,801,437 processor cycles
588,832 bytes consed

Perhaps the time function should be called into question? Is it even suitable for benchmarks?
>>
>>52184958
>reviewing C++
>isn't prepared to read code with everything optimized to hell and back
>>
>>52184963
Have you looked at Crystal or Nim?
>>
>>52184978
There's clearly something wrong with your test method. In order to get an accurate number you need to run it like 10,000 times and average the result, are you doing that?
>>
File: 1431731405480.jpg (125 KB, 1102x967) Image search: [Google]
1431731405480.jpg
125 KB, 1102x967
>>52184980
It's not even optimized though, half this shit looks like it was copy-pasted off of stackoverflow.
I have tens of thousands of lines of heavily templated code written by H-1B visa workers with documentation in a foreign asian-snake looking language
I think they're going to replace me with an H-1B worker anyways so I'm considering just quitting
>>
Okay, so, I think I've gotten a hold on how the fuck Rust's linking system works. The preferred method of handling separate compilation would appear to be with .rlib files, which contain function, module, and type information. They are imported into a file through extern crate, and exported by using #![crate_type = "lib"]. In this sense, a file is allowed to know a little bit about how it is being linked, rather than all of this information being in the command itself.

Files can be exported as assembly, object code, or llvm bytecode using the --emit option for rustc. It does not appear, however, that one can link against plain old object files as one can in C. If one wishes to use .o files made in C within Rust, one must convert them into either a static library (.a) or dynamic library (.so, .dll) and note this with an extern block with a link attribute. Functions used this way can only be used in an unsafe block.

Cargo is not necessary to produce Rust libraries or to include them within one's codebase, but it seems to be the preferred build system for doing so. There is not much "magic" behind it, however.
>>
>>52184978
the time function is pretty standard for benchmarks AFAIK. if you suspect something's wrong with the function maybe try switching the order that you run the tests in and see if that changes anything
>>
>>52185002
does rust built system require proof of cuckolding yet?
>>
Made a >python script to extract the timetable data for all programmes and modules off my university's website and am currently writing a REST API using flask

MongoDB backend as well, I went full hipster

First time using python for anything slightly big because I normally just shit on it but I'll admit, it's really easy to use for something like this
>>
>>52185012
/brit/ wahey
>>
>>52185007

By the looks of things, it is licensed both under MIT and Apache licenses. So no, no such requirement.
>>
>>52184990
I am not, however, I am running the factorial function with an argument of 1000. I'll try running the test several thousand times and averaging the results.
>>
>>52185024
It's likely that's the issue. Standard timing functions don't tend to be sufficient when milliseconds count.
>>
>>52185023
Free software doesn't include hate software
>>
Hey anon
yes you

how many leap years were there between 1776 and 1969?
>>
>>52185022
;-)
>>
>>52184706
>He thinks that learning languages for the sake of learning them is bad
Stay a shitty high level programming slave then, fag.
>>
>>52185072
Not doing your homework for you
>>
>>52185072

Is this an inclusive range or an exclusive range? That is, are we including 1776 and 1969 in this count?
>>
>>52185139
it's okay, we don't want him either
>>
>>52184917
Cool, thanks. That's exactly what I'm looking for.

Can anyone recommend any cheapish VPS for personal use? I'd need at least 20ish gigs storage and a few hundred megabytes ram.
>>
typedef struct {
int re_magic;
size_t re_nsub; /* number of parenthesized subexpressions */
const char *re_endp; /* end pointer for REG_PEND */
struct re_guts *re_g; /* none of your business :-) */
} regex_t;
>>
>>52185190
That's actually a pretty decent way of doing things if you want things to be user-accessible, but allows you to change the internals without breaking the ABI.
>>
>>52185214
http://c2.com/cgi/wiki?PimplIdiom
>>
>>52185189
If you're a student get $100 of digital ocean credit for free with the github student pack
Or use Amazon AWS EC2 free for a year, that's got 30gb ssd I think
>>
>>52185222
That shit is about Meme++ though.
The code snippet posted was C.
>>
>>52185072
46 not including 1776
47 including 1776
>>
>>52185255
Same shit, and it's really more useful in C since it's the only way to have private members.
>>
>>52185261
I knew I'd get one

post code
>>
>>52185189
time4vps is really cheap, I don't use them but I know some people who do and they swear by it
>>
>>52185072
>>> def leap_years(begin_year, end_year):
... leap_year_count = 0
... for i in range(begin_year, end_year+1):
... if i % 4 == 0 and i % 100 != 0 or i % 400 == 0:
... leap_year_count += 1
... return leap_year_count
...
>>> leap_years(1776, 1969)
47
>>>
>>
>>52185311
print(47)
>>
>>52184156
>tfw you change your "home" board and the tripfags from the old board follow you
>>
class Integer
def leap_year?
((self % 4 == 0) && (self % 100 != 0)) || (self % 400 == 0)
end
end

(1776..1969).count &:"leap_year?"


Evaluates to 47,
>>
>>52185326
>tumblr
>>
>>52185323
why would you iterate through every year and not just go to the first multiple of 4 after begin_year and add 4 to the iterator each time?
>>
>>52185326

I've been posting in /dpt/ for a good while, now. Pretty much the only good thread on /g/.
>>
>>52185328
>monkey patching
disgusting
>>52185348
because I'm a fucking retard, happy now?
all you have to do is change
for i in range(begin_year, end_year+1)

to
for i in range (begin_year, end_year+1, 4):
>>
>>52185364
They were much better before you arrived
>>
>>52185311
ok here
http://www.onlineconversion.com/leapyear.htm
>>
>>52185375
oh wait, nevermind
I'm too fucking tired to properly read
kill me
good night
>>
File: umarusecret.webm (2 MB, 960x540) Image search: [Google]
umarusecret.webm
2 MB, 960x540
Ask your much beloved programming literate anything.

>>52184052
Thank you for umaru-chan.
>>
>>52185391
Have you taken Jesus into your heart and accepted him as your personal saviour?
>>
>>52185348

The amount of time saved by doing so would not exceed the amount of time lost by typing out the extra code.

>>52185375

Got a problem with monkey punching?
>>
Rate my fib
let rec fib = mem <| function
| x when x < 2I -> x
| x -> [|1I; 2I|] |> Array.sumBy (fib << (-) x)


Array.Parallel.init 50 (bigint >> fib) |> Array.iteri (printfn "%A -> %A")


Mem is a memoizer
>>
>>52185311
There's a leap year every ~4.16 years. Just use division dumbass.
>>
>>52185328

Console.WriteLine(Enumerable.Range(1776, 193)
.Where(x => leapyear(x)).Count());


:^)
>>
>>52185434
how many leap years are there between 1899 and 1903 then?
>>
>>52185378

You've only been posting on here for 3 weeks, scrub.
>>
>>52185434

That'll give an approximation, but it won't give an exact value. Consider, for example, that there are 0 leap years between 1897 and 1903 inclusive. And yet that includes 7 years. Dividing by 4.16, whether you round down or up, the result is still greater than 0.
>>
>>52185450
C# is deprecated
open System
[1776 .. 1969] |> List.filter DateTime.IsLeapYear |> List.length |> printf "\n%i"
>>
>>52185464
>hurr durr incredibly specific data range disproves proven rule of thumb
why are you so fucking stupid?
>>
>>52185450

Yes, we effectively did the same damn thing. But what looks more elegant? That mess, or this:
(1776..1969).count &:"leap_year?"
>>
Would ptp satisfy my need for gook movies?
>>
>>52185328
[1776..1969].grep({$_ %% 4 && $_ !%% 0 || $_ %% 400}).elems

not sure how to make any shorter but then again i haven't spent much time this week learning perl6
>>
>>52185554
why would you spend any time learning perl 6?
>>
>>52185565
why wouldn't I?
>>
>>52185575
cuz its shit
>>
>>52185428
For some reason Array.Parallel.init doesn't like more than about 10000, but if you just use Array.init you can get a lot more (albeit slower)
>>
>>52185529
>mess

Look, it's a C-style language full of parens and semi-colons and everything else. That's just how it is.
>>
File: dpt.jpg (185 KB, 800x547) Image search: [Google]
dpt.jpg
185 KB, 800x547
>>
>>52185582
what's "shit" about it other than your opinion of a language that you haven't even bothered trying?
>>
you guys actually get jobs programming without college?
or is that just a meme
>>
>>52185616
If you're good, yes.
The hardest part is getting your first job.
After that, your degree becomes largely meaningless.
Even with a degree, you'll still have to pass lots of retard tests because of the amount of retards with CS degrees.
>>
>>52185616
>implying i plan on getting a job in programming
>>
File: 1444589252682.png (14 KB, 426x364) Image search: [Google]
1444589252682.png
14 KB, 426x364
What music do you listen to while programming?
>>
>>52185616
>>52185646

From experience...college degrees help. Like this guy says, they massively increase the likelihood that someone will trust that you're competent and decrease the number of hoops you'll have to jump through to prove that you are.

What's more, if you can get yourself into a good school (like top 10) that effect gets even better. I go to a good CS school and virtually everyone I know is getting jobs at Google, Microsoft, Facebook, Palantir, etc right out of college. It helps a ton.
>>
>>52185657
Never fucking reply to me again unless you are contributing to the thread.
>>
>>52185657
kpop :3
>>
>>52185616
Yeah. The easiest way is to get some short short term contract positions till you can bullshit your way through interviews. Relying on github as a resume can also work.
>>
>>52185598
Comfy as fuck.
>>
>>52185657
japanese schoolgirl music
>>
Holy shit trying to compile QT 5.5 for Windows is hell.

I get a shitton of errors saying "No exception handling mode specified" and then the compile ended in a series of fatal errors with codes 0x1 and a bunch of 0x2.

Plz help
>>
>>52185378
gtp has been here for a long time, friend
probably longer than you have been alive
a year+ maybe i think
>>
>>52185740
>a year+
>long time
>>>/out/
>>
>>52185616

Even the NSA takes people without college.
>>
>>52185740
>gtp has been here for a long time, friend
About a year or so. Are you implying that is a long time?
I'm not claiming to be some /dpt/ old-fag, but I've been around a lot longer than that.
>>
>>52184052
I had coffee in the morning.
>And cola at lunch

What will I have for dinner?
Nobody knows.
>>
>>52185750
>>52185756
consider the context anons, the other anon said that he just switched his home board and gtp followed him
I'm not saying gtp is ancient here or whatever
>>
>>52185391
why do i get "Error: Unbound module Llvm" even though i already opam install llvm?
>>
>>52185616
>sign up for some obscure challenge site
>solve a bunch of problems
>poojoosh pajeesh spams my email address for like a year asking me to work for his codemonkey sweatshop in bangladesh
it happens
you don't even have to be good
>>
I was trying to do fancy stuff with make files today but it somehow kept ending up in weird directories and I don't know why :(
>>
Hmmm... this doesn't look so bad in Rust....

fn leap_year(year: &i32) -> bool {
((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)
}

fn main() {
let count = (1776..1969).filter(leap_year).count();
println!("{}", count);
}
>>
Are there any GUIs other than QT for C++ Windows development that are modern but easy to install for VS2015 community edition?
>>
>>52185616
resolving the halting problem on a programming challenges website helped me find a job. you too can become a computer scientist by learning javascript on codecademy.
>>
File: linus torvalds.png (213 KB, 640x359) Image search: [Google]
linus torvalds.png
213 KB, 640x359
>>52185891
>C++
>Windows
>for VS2015
>>
>>52185891

>VS2015 community edition
Think I found your problem.
>>
>>52185616

You can get a job, but don't expect many promotions.

Also, it's easier to find a job with a bachelor's and no experience than it is with anything less. "No degree" or "Highschool Diploma" hires generally want a few years of experience from you. Being a drop out can hurt your chances because your employer will take it as a sign that you don't have a good work ethic.
>>
>>52185940
But it's free

>>52185926
Eat a dick m8
>>
>>52185255
>he doesn't like c++
what's the matter? too hard for java babby to understand?
>>
>>52185970
so is linux, vim, gcc, etc..
>>
>>52185880

I told you Rust wasn't just for SJW niggers.
>>
>>52185970

so is Powershell.
>>
>>52185999
I need to use the wintab API
>>
>>52186000

Aye, the more I look into it, the more it seems like a reasonable enough system's language that I might just dedicate some time to. Even if it's got some bugs to break out still.
>>
File: 1402886051076.jpg (126 KB, 856x704) Image search: [Google]
1402886051076.jpg
126 KB, 856x704
>>52185988
>Sepplesfag trying to talk down on anybody else
>>
>>52185988
Here's F# code for memoizing a function

let mem (f : 'T -> 'S) = 
let mutable map = new System.Collections.Concurrent.ConcurrentDictionary<'T,'S>()
fun x -> map.GetOrAdd(x, f)


Post C++ version
>>
>>52183823
>As you know, this won't work because the two Jim's will have a driver string that shares the same reference.
It would work just the same, no matter how manipulate the strings, as long as you don't use == to compare them since strings are compared by reference
>>
File: no prisoners.jpg (58 KB, 559x263) Image search: [Google]
no prisoners.jpg
58 KB, 559x263
would /dpt/ mind if I asked a not-explicitly code related question? This is the comfiest part of this board desu
https://www.youtube.com/watch?v=Ag1AKIl_2GM&t=3m34s
He says companies can charge for software and it can still be 'free' according to his definition, but how does he expect a company to charge for software if anyone can redistribute an exact copy, and even sell it themselves?
Is he advocating donation-ware / PWYW systems or is his philosophy just incoherent?
>>
>>52186670
He's an idiot
>>
>>52186349
I really don't like the syntax for annotating type signatures in F#
>>
Daily reminder that if your language of choice is not on this list you should probably give up and kill yourself:
- C++
- C#
- Lua
- Python
- Elixir
- Haskell
- Bash
- Clojure
- D
>>
>>52186670
Last I heard he advocates for companies charging for support and development work, while the fruits of their labour (the code) is Libre and Ethical.
>>
>>52186750
Jesus Christ stop forcing Elixir already
>>
>>52186742
Really? What part bothers you?
>>
>>52186757
No, in fact, a new version has been released, you should give it a go.

https://github.com/elixir-lang/elixir/blob/v1.2.0/CHANGELOG.md
>>
>>52186757
It's about time someone made it obvious
>>
You know what, QT's built in editor isn't so bad. Y-yeah, not terrible
>>
>>52186784
B-but that doesn't mean it's good b-baka
>>
>>52186670
> He says companies can charge for software and it can still be 'free' according to his definition

"Free" software is free in the sense of "free speech", not "free beer". If you're not prohibited from modifying or distributing it, then it's "free".

> but how does he expect a company to charge for software if anyone can redistribute an exact copy, and even sell it themselves?
Who cares?
>>
File: 0036 - Gy5UAxw.jpg (947 KB, 2000x2000) Image search: [Google]
0036 - Gy5UAxw.jpg
947 KB, 2000x2000
hold me /g/ i got an 83 in my data structures class
>>
>>52186960
Dumb frogposter.
>>
>>52186890
Fuck off commie
>>
File: 0055 - mPWN7uP.jpg (294 KB, 1148x1122) Image search: [Google]
0055 - mPWN7uP.jpg
294 KB, 1148x1122
>>52186963
>>
File: barely 9000.gif (2 MB, 500x281) Image search: [Google]
barely 9000.gif
2 MB, 500x281
>>52186960
>only 83
>>
File: 1451551029327.png (402 KB, 1024x768) Image search: [Google]
1451551029327.png
402 KB, 1024x768
>>52184052
Threadly reminder
>>
>>52186960
I got 96 in my High Performance Computing class >:D
>>
>>52186980
I barely tried in it TBh senpai so I was surprised to see that high of a mark :^)

Also I live in a city where the tech sector is starting to grow so it's not like I need marks to back up my piece of paper :^)
>>
Does anyone ever get this fucking midget code in visual studio? Where you have like lines half the size they should be?

The fuck microsoft?
>>
File: fizz.jpg (61 KB, 961x127) Image search: [Google]
fizz.jpg
61 KB, 961x127
what are you lads working on?

>>52186989
neat
>>
>>52187181

Pouring through pages of documentation on how Rust's Cargo build system works. I really, REALLY don't like magic in my build systems. It's half the reason why I don't touch IDEs.
Thread replies: 255
Thread images: 33

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.