[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: 19
File: himegoto.jpg (407 KB, 600x800) Image search: [Google]
himegoto.jpg
407 KB, 600x800
old thread: >>51848054

What are you working on, /g/?
>>
File: 1444756832016.jpg (678 KB, 2400x3600) Image search: [Google]
1444756832016.jpg
678 KB, 2400x3600
>>51850125
First for D
>>
I can't have fun programming
>>
>>51850143
Who is this man?
>>
Exploring Xcode, literally making an overpowered hello world
>>
File: layne staley.jpg (32 KB, 500x365) Image search: [Google]
layne staley.jpg
32 KB, 500x365
>>51850157
>man
>>
>>51850167
Would you hit on him?
>>
>>51850156
how do they do it?
>>
I am literally obsessed with type theory.
>>
>>51850156
(a + b) / 2
>>
https://github.com/philipl/pifs

>2015
>not storing all your data in πfs
>>
>>51850175
MOOOOOODS
MODS
MODS
MODS
>>
>>51850207
wut
>>
>>51850156
what's the memory model?
>>
>>51850193
undefined behavior
>>
>>51850156
>not using c++
>>
I had a project, to design an automated container terminal, but it's PLC programming. Though if anyone has a good guide to structured text it would be nice. So far it's all in ladder but I'm not sure ladder is the best way for some parts of it.

Heck, anyone with a good guide to PLC programming, I would sure appreciate it.
>>
>>51850255
lol, that's literally the definition of average, retard
>>
>>51850156
not doing your homework
>>
>>51850156
>guaranteed replies
>>
>>51850029
Like I said, there are abstractions that will move the state around for you, and then it isn't that painful. I don't see how systems programming changes it very much, as you still benefit from the safety. And if you're already doing something in IO (which you often will be in systems programming), you can just use IORef, MVar, etc., which don't use the function representation, and are literally just mutable cells. The important thing is that you can't get values from these in pure functions, which allows you to enforce a separation of your IO stuff and pure stuff.

And also in general, the mutation that's *required* by systems programming is manipulation of data at explicit memory locations for interacting with the system, and not for keeping internal state of your program - I really wouldn't use "faked state" for it. In that case the situation is almost the same as C, you have functions for filling some memory location with data or reading. Just at the same time, you get the benefits of a nice language, and it's easier to create nice interfaces to these operations.

A type-safe mutable reference like an IORef is guaranteed to point to valid data (as long as it's in scope), and can't be cast to other types.

I think in most cases where you would just have some mutable variables on the stack, it would not be much overhead to translate it to the "pass-new-values" method, though.
>>
>>51850390
No offense mate, but I think it's a bit of a step in the wrong direction to try and justify purity for systems programming by talking about Haskell.
>>
>>51850167
Ugly man. Very ugly man.
>>
I'm getting frustrated trying to learn how to do GUI stuff and trying to pick a toolkit.
>>
>>51850432
GTK
>>
>>51850214
There was literally nothing wrong with that pic.
Fucking reddit.
>>
>>51850415
There is an operating system written in haskell.
>>
>>51850418
make a program to convert strings to this with fewest lines possible
>>
>>51850497
Sure, but with Haskell you're sacrificing a ton of efficiency, and pure functional programming doesn't have to be like Haskell (doesn't have to be lazy, doesn't have to be garbage collected, etc.)
>>
>>51850444
I was thinking about using wxWidgets but I've never worked with C++ before, I figure I'll use something like wxGlade to do the UI stuff and write the actual program in straight C.

GTK seems nice but I hear it doesn't look good on anything besides X11.

Maybe just learning all the native toolkits would be best but this seems like a maintenance nightmare. I already hate this.
>>
>>51850480
The mods disagreed, so something was not right. Go fuck yourself, pedo.
>>
>>51850522
Can you prove that you lose efficiency due to these properties? The set of optimizations that you can apply to pure functional programs is different from the set of optimization that you can apply to programs where states can change at any point in time. As such, haskell programs can be optimized more aggressively in many parts than the equivalent procedural program.
>>
How do I program a rube goldberg machine equivalent?
>>
>>51850506
I already did, m8. of course this would be shorter in python... I suppose
btfo.c
License: GPLv3 or superior
#include <stdio.h>
#include <string.h>

int main (int argc, char *argv[])
{
int i = 1;
char spaces[strlen(argv[1])];
char chr;
printf("%s\n", argv[1]);

while (argv[1][i]) {
spaces[i-1] = '\0';
chr = argv[1][i];
printf("%c%s%c\n", chr, spaces, chr);
spaces[i-1] = ' ';
i++;
}

return 0;
}
>>
>>51850546
The mods are huge SJW keks and adore removing 100% on-topic threads while letting threads which sole purpose is shitposting fester on the board until way past their bump limit, so if you think mod decisions are worth shit in 2015, you should get the fuck back to reddit or tumblr, whichever place you came from.
>>
>>51850560
I just said that I'm still talking about pure functional programming. You get the same optimization opportunities as Haskell WITHOUT any of the caveats, the biggest one being GC (I'll hold back on laziness since you can force strictness).

I shouldn't have to prove to you that, all other things being equal, a GC that you can't work around as well as everything going on the heap makes a language slower.
>>
>>51850581
>underage sexualized child
>100% on-topic
pedophile confirmed
>>
>>51850572
def shitpoststring(s):
print s
for i in range(len(s)-1):
print s[1:][i] + i * " " + s[1:][i]

yup, shorter in Python
uu
p p
, ,

s s
h h
o o
r r
t t
e e
r r

i i
n n

P P
y y
t t
h h
o o
n
>>
>>51850506
public void memeString(String s){

String spaces = "";
System.out.println(s);

for(int i = 0; i < s.length(); i++{
char c = s.charAt(i);
System.out.println(c + spaces + c);
spaces += " ";
}
}
>>
not sure if I should abandon this thread...
>>
>>51850706
how is jailbait programming related?
oo
w w

i i
s s

j j
a a
i i
l l
b b
a a
i i
t t

p p
r r
o o
g g
r r
a a
m m
m m
i i
n n
g g

r r
e e
l l
a a
t t
e e
d d
? ?
>>
>>51850706
>EAGAIN
>>
>>51850418
M   SEMEM
E E
M M
E E
SEMEMEMES
E E
M M
E E
MEMES M

local s = arg[1] and table.concat(arg, " "):upper() or "LONDON"

local function q(n)
return (" "):rep(n)
end

local sl = #s
local sr = s:reverse()

print(s:sub(1, 1)..q(sl-2)..sr)
for i = 2, sl-1 do
print(s:sub(i, i)..q(sl-2)..sr:sub(i, i))
end
print(sr..s:sub(2))
for i = 2, sl-1 do
print(q(sl-1)..s:sub(i, i)..q(sl-2)..sr:sub(i, i))
end
print(s..q(sl-2)..s:sub(1, 1))
>>
im working on a hello world in batch
but i dont know whow to safe it as a batch
>>
>>51850563
Write it in Java.
>>
>>51850572
while(<>) {
chomp; say;
$_ = scalar reverse; chop;
for(my $s = 0; my $c = chop; $s++) {
say $c, ' ' x $s, $c;
}
}
>>
>>51850506
import System.Environment
memeString s = unlines $ zipWith aLine s [1..]
where aLine d 1 = s
aLine d n = map (\x -> if x == 1 || x == n then d else ' ') $ zipWith const [1..] s
main = getArgs >>= putStr . memeString . (!!0)


Output:
  codesnips  runghc gchallenge.hs "ayy lmao"
ayy lmao
yy
y y

l l
m m
a a
o o
>>
>>51850683
one liner:
def shitpoststring(s):
print('\n'.join([s[1:][i] + i * " " + s[1:][i] if i > 0 else s for i in range(len(s)-1)]))
>>
>>51850951
thanks perl
>>
>>51850930
kek
>>
#include <stdio.h> 

HKEY
WinMain(DWORD ARGUMENTCOUNT, DWORD **PROGRAMARGUMENTS)
{
printf("Hello, world!\n");
__builtin_trap();
__builtin_unreachable();
}
>>
>>51850958
A line shorter:

import System.Environment
memeString s = unlines $ s : zipWith aLine (drop 1 s) [2..]
where aLine d n = map (\x -> if x == 1 || x == n then d else ' ') $ zipWith const [1..] s
main = getArgs >>= putStr . memeString . (!!0)
>>
>>51850601
But everything doesn't go on the heap. lrn2c--, faggot. Moreover, a gc is much more efficient than, say, reference counting in practice, let alone when using pauseless GCs or realtime GCs.
>>
>>51851009
Why is the Windows API so fucking ugly?
>>
>>51850979
Haskell version of this solution:

memeString2 s =
unlines $ zipWith (\x c -> if x == 1 then s else c : replicate (x - 2) ' ' ++ [c]) [1..] s
>>
>>51851114
oh, I guess I didn't print

memeString2 s =
putStr . unlines $ zipWith (\x c -> if x == 1 then s else c : replicate (x - 2) ' ' ++ [c]) [1..] s
>>
>>51851033
>Moreover, a gc is much more efficient than, say, reference counting in practice
I didn't say everything had to be like shared_ptr. I'm talking granularity of malloc and free or even lower level than that.
>>
How can I make bindings to C functions for haskell?
>>
going over the LEAN fs specifications. Is there a 32-bit spec?
>>
>>51850563
https://github.com/mame/quine-relay
>>
>>51850497
Well I guess that settles it. You are using that OS to post this right?
>>
Can we all agree that stdio.h is pronounced studio h?
>>
>>51850979
btw, I don't know why the other anon used s[1:][i]... but this solution was wrong.

working solution, even shorter:
def shitpoststring(s):
def shitpoststring(s):
print('\n'.join([s[i] + i * " " + s[i] if i > 0 else s for i in range(len(s))]))

>>>
shitpoststring("btfo")


I hadn't noticed that it's wrong, my head hurts and I'm sleepy...
>>
>>51851176
I pronounce each letter desu
ess tee dee eye oh dot aitch
>>
>>51851176
standard i o dot h
>>
>>51851176
I pronounce it esteedeeayoh h
>>
--haskell
why doesn't
main = (\(IO a) -> print a) fmap id getCurrenDirectory

work?
it even says IO is not a constructor
how do I pattern match against
 IO sometype 
then?
>>
>>51851176
I say studio dot h
>>
>>51851226
You do not pattern match over IO. You have to use fmap, bind, etc.
>>
>>51850951
while(<>) {
chomp; say;
map { state $s = -1; say $_, ' ' x $s, $_ if $s >= 0; $s++ } split //;
}
>>
>>51851226
>getCurrenDirectory
>Curren
>>
>>51851194
nice one!

what's wrong with s[1:][i]?
>>
>>51850125
Please stop the programming trap meme
Thanks,
>>
File: 1449335320934-0.jpg (123 KB, 605x807) Image search: [Google]
1449335320934-0.jpg
123 KB, 605x807
>>51851176
I've never said stdio.h aloud. I guess I say it something like "stid io dot h" in my head.
>>
>>51851133
http://book.realworldhaskell.org/read/interfacing-with-c-the-ffi.html
>>
>>51851226
Another error is that the way you have it, you are applying (\(IO a) -> print a) to arguments fmap, id, getCurrentDirectory. This is wrong because (\(IO a) -> print a) would take only one argument, even if IO was a visible constructor.
>>
>>51851150
fuck it. let's go long mode.
>>
>>51851270


fuck off
>>
>>51851257
I mean, I took >>51850683 and made >>51850979 , but I just copied it blindly. s[1:][i] is absolutely unnecessary, because you are basically copying (I assume) a substring every time, and s[1:][i] is actually the same as s[i+1] anyway.
>>
>>51851270
I am refactoring a C99 library in a dress and there's nothing you can do about it.
>>
>>51851226
>how do I pattern match against
IO sometype

unsafePerformIO
, of course
>>
>>51851296
>>51851255
yeah sorry, its was something similar to what I typed earlier
sourcing the file gives
main = (\(IO a) -> print a) $ fmap id getCurrentDirectory

>>51851238
the point is to not bind anything
it might seem easier, but I really like one liners
>>
>>51851226
I imagine getCurrenDirectory has type IO String? You want
main = getCurrentDirectory >>= putStrLn
-- or
main = do
dir <- getcurrentDirectory
print dir

I used putStrLn over print because print a = putStrLn (show a) and you dont need to call show on a string.
>(\(IO a) -> print a)
This is not a valid function. Apart from matching on IO, it tries to print a generic a. The type of print is
print :: Show a => a -> IO ()

so you cant feed any old a into print. a has to be an instance of Show.
>>
>>51850572
>>51850702
Shit implementation.
Here's mine:
#include <stdio.h>
#include <string.h>

int main(int argc, char **argv)
{
char *str = argc < 2 ? "Please provide a string" : argv[1];
size_t len = strlen(str);
puts(str);

for (size_t i = 1; i < len; i++)
printf("%c%*c\n", str[i], i, str[i]);

return 0;
}

$ ./a.out "faggot nigger"
faggot nigger
aa
g g
g g
o o
t t

n n
i i
g g
g g
e e
r r
>>
>>51850156
Is this a new meme now?

>Can I average those two ints for you?
>I like averaging ints.
>>
>>51851426
Also, fmap id = id, this is one of the Functor laws. So
 fmap id getCurrentDirectory = id getCurrentDirectory = getCurrentDirectory 
>>
>There are people itt right now who can't average two ints in java
>>
>>51851434
It would be a valid function if IO was a constructor. It would just be inferred to have the Show constraint. And then it's being applied to getCurrentDirectory so it would be specialized to String (I think that's what getCurrentDirectory gives?)
>>
>>51851444
hah, nice trips, nice program :P
guess you could move
size_t len = strlen(str);

inside the loop

>>51851477
I can, but not using Integer's!!
>>
>>51850560
Oh jesus christ is there just one idiot who thinks haskell is fast or are there multiple people?

The whole language is made out of linked lists, the retarded black sheep of data structures.
>>
>>51851033
> gc more efficient than reference counting

Except in any language that isn't an academic pipedream meme, values go on the stack and most heap allocation has single ownership so that reference counting is almost never needed.
>>
CONVINCE ME TO USE C# OVER C++.

AND.... GO!
>>
>>51851523
How to spot the inbred.jpg
>>
>>51851518
>guess you could move
>
size_t len = strlen(str);

>inside the loop
Why the fuck would you do that? are you retarded? why do you think calling strlen unnecessarily every loop iteration is a good idea when you could just simply call it once outside of the loop and get the same result?
>>
>>51851415
explane?
>>51851434
I see my erros now.
ah,I forgot about monads since I've been avoiding them 'cause I don't understand them well.
>>
>>51851557
RC requirements are ALWAYS low, even with full GC, in real life programs. For over 50% of variables, RC doesn't reach 5, for another 40%, it doesn't reach 10, and the rest typically doesn't reach 60. RC performance is always much lower than GC performance except in degenerate cases. Deal with it.
>>
>>51851568
Nice reasons retard. Go write more 1 liner quicksorts that aren't actually quicksorts and jerk off to how elegant all the code no one will ever run is.
>>
>>51851566
Fuck off.
>>
>>51851566
Well /fa/ggots?

Explain to me why I should use C# over C++.
>>
>>51851603
>>51851602
>>
>>51851570
>why do you think calling strlen unnecessarily every loop iteration is a good idea
I didn't say that. I said to move it to reduce the # of lines
>>
>>51851566
Use D
>>
File: 1447858697930-2.jpg (134 KB, 819x1024) Image search: [Google]
1447858697930-2.jpg
134 KB, 819x1024
>>51851523
Haskell is faster than C.

Take this example of a brainless C programmer who hasn't programmed a lick of FP in his life thinking he can "prove" his Turing Tarpit of a language is faster than anything:

https://stackoverflow.com/questions/6964392/speed-comparison-with-project-euler-c-vs-python-vs-erlang-vs-haskell

When the procedural dunce wrote the Haskell program, it was 6x slower than C. However, when a group of experienced Haskellers tackled the problem, they were able to make the program run slightly faster in Haskell than in C!

What this proves is that while imperative mental midgets may cry about linked lists and garbage collection, the pure type-safe expressiveness of Haskell comes out on top for speed over everything.
>>
>>51851602
>>51851624
shut up cukcold bois

Go suck the creampie out of your girlfriend's pussy
>>
>>51851628
>I didn't say that. I said to move it to reduce the # of lines
>hur dur less lines = better performance
>>
>>51851648
No one fucking gives a shit wether you use C# or C++, no one fucking cares about you.
Fuck off and kill yourself.
>>
>>51851590
What the fuck are you even talking about? You do realize that in real languages that people actually use most variables are on the stack, and 99% of the heap allocations don't use reference counting and are just cleaned up based on ownership.

Then there is concurrency where thread local heap allocation has no synchronization when done by ownership.

Then there is the issue of controlling maximum memory, which garbage collection is very poor at.

TL;DR - You're a total and complete idiot who needs to write real software to understand what you are talking about.
>>
>>51851671
>No one fucking gives a shit wether you use C# or C++, no one fucking cares about you.

Yeah you'd much rather argue about the OP image of the thread right?
>>
>>51851649
are you retarded or just baiting?
the "challenge" was >>51850506
>make a program to convert strings to this with fewest lines possible
do you understand this?
>>
>>51851523
Linked lists in real code are mainly used as a control structure - they are perfectly fine when you are operating on one element at a time, and there are optimizations that will erase intermediate lists for this purpose. Even without optimizations, the laziness of lists mean that when you have a function producing a list, and a function consuming a list, you will often only have one element in memory at a time, if you string them together. Often something you would do with a loop in another language is an operation over a list in Haskell.

The reason lists are such a visible part of the language, other than the uses I've described, is that they're a simple polymorphic data structure, and thus good for teaching. It is true they are pretty bad for random access.

They have some other uses as data structures (like stacks), but there is a good selection of other types to use for actually storing data. These include Map, Set (implemented with R-B trees like in C++), Seq and other data structures, Vectors and Arrays (Mostly useful if you are not mutating individual elements, because they are immutable), mutable vectors and arrays, etc.

In particular, String (an inefficient linked list of characters) has the efficient alternative Text, which packs strings more tightly, while still retaining the semantics of a unicode string. There is also ByteString if you want an array of bytes.
>>
>>51851692
There's something to be admired about this irony.

>/dpt/
>argue about the OP image
>talk about fizzbuz otherwise

Thnx 4chan.
>>
>>51851729
And you have tuples or product types if you want just store some random things together, like you would with a struct.
>>
>>51850156
a>>1 + b>>1 + (a&1+b&1)>>1
>>
>>51851638
I thought you were serious, I didn't realize you were just trolling until now, you got me good man.

8/10
>>
>>51851740
4chan is a meme website.

>Post legitimate technical question
>No responses

>Post some retarded b8
>hundreds of replies
>>
>go to job interview
>tfw they ask me to average 2 ints in C
I'm not gonna make it lads
>>
>>51851729
Interesting, you would think Haskell wouldn't be so slow if all that was true.

Seems like a lot of effort to go through when you can make a vector and loop through it in two lines of C++.
>>
>>51850193
naw nigga u want low + ((high-low)/2) to prevent integer overflows
>>
>>51851566
Use D instead
>>
>>51851812
INT_MIN, anything greater than 1.
>>
File: GsL1Goz.png (4 KB, 552x120) Image search: [Google]
GsL1Goz.png
4 KB, 552x120
>in C
you guys are making this too hard
just pick a better language :^)
>>
>>51851874
Now test it using numbers that would overflow, that was the main challenge, not simply adding and dividing any 2 small numbers
>>
>>51851907
That doesn't happen in Python... All numbers can be arbitrary precision.
>>
>>51851907
I overflowed your mom's pussy with semen
>>
>>51851907
Python transparently upgrades to bignums when a result would overflow.
>>
>>51851933
Which is nice, but why it and Pypy perform like shit.
>>
>>51851931
>>51851933
>Tfw Python and other high level languages are superior to C* plebshits

lmao

Why are you still debugging programs for days, writing 50 lines of code, etc when things can be done in a few lines using a high level library in a non-pleb language?
>>
>>51851933
Lisp does too! >:D
>>
Rewriting the lunix kernel in ALGOL
>>
>>51851907
import sys

def avg(a, b):
return (a + b) / 2.0

print(avg(sys.maxsize, sys.maxsize))
>>
>>51851959
Python is one of the few languages that does that. BigInts exist in C, gmp is a very mature library (probably what Python uses) and if it's too big for you bc is less performant, less feature-ful, but only 1300 lines of C.
>>
>>51851959
Because I'm not doing a CS101 assignment and other people might actually use the software I write
>>
>>51852031
>people might actually use the software I write
lmao, less people are using C nowadays

even Python gets more usage due to frameworks like Django
>>
>>51852063
>Django
flask is the new meme
>>
Rate my programs fags

#include <iostream>
#include <windows.h>

int main()
{
using namespace std;

HKEY hkey;
DWORD key_type = REG_SZ;
LPBYTE lpvalue = NULL;
DWORD dwSize;

if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"), 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS)
{
RegQueryValueEx(hkey, ("ProcessorNameString"), NULL, &key_type, NULL, &dwSize);
lpvalue = (LPBYTE)malloc(dwSize);
RegQueryValueEx(hkey, ("ProcessorNameString"), NULL, &key_type, lpvalue, &dwSize);
RegCloseKey(hkey);
}
else
{
MessageBox(NULL, "Cannot open the registry.", "Error", MB_OK);
}

cout << lpvalue << endl;
free(lpvalue);

return 0;
}
>>
>>51852072
>flask
Serious? I've seen it too on many job postings, but I can't keep up with the memes. If true, I suppose it's good, I hadn't gotten into Django yet anyway
>>
>>51851570
if your compiler can't optimize that, then it's a shit compiler
>>
>>51851798
I've seen Haskell rated fairly competitively. Most of the benchmarks in https://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=ghc&lang2=gcc have Haskell within an order of magnitude of C, though C++ is probably faster. I don't know where to find performance comparisons for more realistically-sized programs.

I haven't found using data structures in Haskell to take much effort. The APIs for them are pretty straightforward, and include higher-order functions for doing complex operations on the structures like e.g. you want to intersect two maps, but if two values are in the same key, you want to merge them, and you want your function to take the key as an input also.

C++ in contrast has heavy syntax for even something relatively simple, like transform.

Another thing is while both Haskell and C++ have abstractions over specific types, the way Haskell does it (typeclasses, parametric polymorphism, no templates, the syntax) makes the load for using these structures a lot lighter. There are even extensions that will allow you to have code automatically written that will make it so your data structure can be mapped over or be traversed while doing monadic things.
>>
>>51852075
><windows.h>
0/10
>>
How the fuck long have we taken to average 2 ints in C?

Other people are probably programming robots at this point
>>
>>51852150
Nice Linux meme idiot
>>
>>51852152
It's been done for a while. Hell I did it in the last thread without using any conditionals. It's just the new and very shitty meme.
>>
File: tIxAI4c.png (9 KB, 551x168) Image search: [Google]
tIxAI4c.png
9 KB, 551x168
thanks, best lang
>>
>>51852163
And shit like DWORD, TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0") and RegQueryValueEx aren't horrible Windows memes?
>>
>>51852237
How are they?

Dword is a data type, the other is a registry subkey, and RegQueryValueEx is a function to get a registry value... What is confusing about it?
>>
>>51852404
They're fucking retarded and ugly.
>>
>>51852452
Good argument by faggot linux NEET
>>
>>51852186
By the same logic, you could say nobody can add two ints in C either. People only fall for the average bait because it's not a built-in operation.
>>
>>51852460
Windows:
HANDLE WINAPI CreateFile(
_In_ LPCTSTR lpFileName,
_In_ DWORD dwDesiredAccess,
_In_ DWORD dwShareMode,
_In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
_In_ DWORD dwCreationDisposition,
_In_ DWORD dwFlagsAndAttributes,
_In_opt_ HANDLE hTemplateFile
);

POSIX:
int open(const char *path, int oflag, ...);


How the hell is Windows not a horrible meme?
>>
>>51852547
Oh nooo does it have too many parameters for baby?

Awww baby can't fill in a few simple arguments to pass to function?
>>
>>51852572
What kind of retarded Hungarian shit is "dwCreationDisposition"?
That shit is completely retarded and only some retarded pooinloo would possibly defend it.
>>
>>51852547
All I see is that Windows has way more features. Like, where is the POSIX security attributes feature? Is there seriously none? Is POSIX inherently less secure?
>>
>>51852609
You modify file descriptor attributes after you create them with other functions.
People who just want simple file descriptors don't have to worry about all of that other ugly shit.
>>
>>51852601
>What kind of retarded Hungarian shit is "dwCreationDisposition"?

Creation disposition in the form of a 32bit unsigned integer(dw aka Dword)... It says it all in the fucking MSDN documentation LITERALLY RIGHT UNDER the function.

>That shit is completely retarded and only some retarded pooinloo would possibly defend it.

I didn't write the Windows API. I just use it to create Windows programs that interact with the OS on a low-level.
>>
>>51852635
Yeah, I guess the WinAPI really is too unreasonable for me to troll effectively.
>>
Since I browse too many generals and they sometimes get lost in my 200 tabs I was thinking of making a minimal 4chan browser so I could browse all of the generals I visit. Is something like this easy to make light-weight and not resource intensive at all? If it turns out to pull as much resources as firefox then there wouldn't be much of a point to go through with it.
>>
>>51852225
how can C programmers defend this?
GHCi, version 7.10.2: http://www.haskell.org/ghc/  :? for help
Prelude> maxBound :: Int
9223372036854775807
Prelude> (9223372036854775807 * 5) + 9900000000000000000 / 2
5.106686018427388e19
>>
>>51852075
>windows.h
It's shit.
>>
>>51852635
>>51852729
I don't get it.

Do you NEETs just never program for Windows? I don't understand how when it's by far the largest marketshare. How do you make money by programming if you don't sell memes to Windows users?
>>
File: puFq35M.png (6 KB, 584x96) Image search: [Google]
puFq35M.png
6 KB, 584x96
>>51852701
>5.1066860184273879e+19
>5.106686018427388e19

>184273879
>18427388
python is more precise
>>
>>51852104
Ofcourse it can, but why would you move it anyway? it's better off where it already is.
>>
Somewhat optimized AoC Day 7. Should be self-explanatory:

data=open("Advent7_1.txt").read().split("\n")

lines=[]

for i in data:
lines.append([])
lines[len(lines)-1]=i.split()

while True:
solved={}
toDelete=[]

for c,i in enumerate(lines):
oldSolved=len(solved)
if len(i)==3 and i[0].isdigit():
solved[i[2]]=i[0]
elif len(i)==4 and i[1].isdigit():
solved[i[3]]=str(65536+~int(i[1]))
elif len(i)==5 and i[0].isdigit() and i[2].isdigit():
if i[1]=="AND":
solved[i[4]]=str(int(i[0])&int(i[2]))
elif i[1]=="OR":
solved[i[4]]=str(int(i[0])|int(i[2]))
elif i[1]=="LSHIFT":
solved[i[4]]=str(int(i[0])<<int(i[2]))
elif i[1]=="RSHIFT":
solved[i[4]]=str(int(i[0])>>int(i[2]))
if len(solved)>oldSolved:
toDelete.append(c)

if "a" in solved:
print solved["a"]
break

while len(toDelete)>0:
i=toDelete.pop()
del lines[i]

for a,i in enumerate(lines):
for b,j in enumerate(i):
if j in solved:
lines[a][b]=solved[j]
>>
>>51852745
1) write for jvm
2) write for servers
3) write for embedded
4) write for labs

winapi desktop applications aren't the only meme
>>
>>51852676
It was worth a shot Anon
>>
>>51852801
python is interpreted
>>
>>51852701
C is indefensible, but it makes sense now that Haskidiots love it so much, they are only working with a couple numbers!

I usually work with billions at a time, I see the difference now.
>>
>>51852846
interpret my cock, dude
>>
>>51852868
you can only work with a few billions
>>
>>51852881
lmao'd
>>
>>51852745
Almost no one writes to the windows API for the majority of a program.

But fucking shit is it fast. Remember when uTorrent was good? 600KB and everything was instant. Not just smooth or quick, but instant. Everything could be like but microsoft just loves to reinvent the wheel and never make it round.
>>
File: 1434905542712.gif (1 MB, 500x281) Image search: [Google]
1434905542712.gif
1 MB, 500x281
>>51850563
This may help.
>>
>>51852825
>winapi desktop applications aren't the only meme

Yes but they are a nice meme for making dosherdoo.

Why aren't you making kewl programs for windows rn, /g/?
>>
>>51852801
True, but I'm sure you can force either language to be arbitrarily precise.
*Prelude> let a =((9223372036854775807 * 5) + 990000000000000000000) / 2
*Prelude> a == a - 1
True -- tfw loss of precision
*Lib> import Data.Ratio
*Prelude> let a =((9223372036854775807 * 5) + 990000000000000000000) / 2 :: Ratio Integer -
*Lib Data.Ratio> a == a - 1
False -- huray
>>
>>51852929
>Almost no one writes to the windows API for the majority of a program.

Then how do they deal with low-level things without importing a zillion libraries?
>>
>>51852939
Cuz all my programming shit is on Arch
>>
AYYYY
>>> 0.1
0.1
>>> 0.2
0.2
>>> 0.1 + 0.2
0.30000000000000004
>>>
>>
>>51852959
In C# i just import 1 dll and i have access to an entire wave of low level functions.
>>
>>51853004
Isn't pinvoke.net a meme?

And how is that any different from winapi in C++?
>>
File: 200.gif (503 KB, 297x200) Image search: [Google]
200.gif
503 KB, 297x200
>>51852905
I guess most Haskell guys don't know how to parse english either. It's ok, you'll have time to learn while your program pointer chases through big ints on one core. I'll leave you to it since ISPC can burn through 7 billion ops on one core and 9 billion on two cores, maxing out the memory bandwidth.

Try that with Haskell them let us know the results next week.
>>
>>51852959
They write to a different API? What the fuck kind of question is that. Also did you miss 'majority'?
>>
>>51853033
C has been my main language for a couple years, I picked up Haskell 3 days ago, but even I know that parallel computing in haskell is easier than in C
>>
>>51853065
Who's talking about C?

Also it's even easier in python.
>>
>>51852998
>what is FP math
niceba.it
>>
>>51853033
That ghci session didn't have any actual number coercion going on. If you're using an Int it stays as an Int, unless you explicitly convert. They were just copying the meme.
>>
>>51853104
>python
>parallel
>easy
no
>>
>https://www.google.com/patents/US6007232?dq=6007232
>Calculating the average of two integer numbers rounded towards zero in a single instruction cycle
dude
patents
lmao
>>
File: Capture.png (62 KB, 1017x430) Image search: [Google]
Capture.png
62 KB, 1017x430
I dont know why this shit's not working, i just copied it from the book and it gives me shit
>>
>>51853247
Take all the java out and see if that fixes it
>>
>>51853247
Try reading the error the compiler gives you which tells you exactly how to solve your problem.
>>
x/2 + y/2 + (x%2) * (y%2)
>>
>>51853247
What the hell is 'extends' in java?
>>
>>51853460
what do you think
>>
>>51853460
I'm pretty sure it means inherits from a class, but I'm not sure
t. not a poo in loo shitter
>>
>>51853484
yeah it does
>>
File: 1431825274494.gif (1 MB, 305x360) Image search: [Google]
1431825274494.gif
1 MB, 305x360
>>51853484
>>
>>51851674
>my experience in programming comes from googling how2progrem
>am smert gais pls belib me 1!11
>>
What do loops evaluate in bash? Specifically while and until

I know that until is

UNTIL [false] do; blabla; done



and while is

while [true] do' blabla; done



But, ultimately, is what it's evaluating an exit code? 0 for true non-zero for false?

Also, what happens in this scenario:

while [ $(program) ] 
?

What will while evaluate, the output of the program or its exit code?
>>
>>51853122
>functional programming is so shit that it uses different math than real math
>>
>>51853585
Why don't you just try it and see what happens?
>>
>20 minutes til AoC Day 14
We're already over half-way there lads. Let's hope this one is slightly more challenging now
>>
Alright lads, is it an animu night or a let's-learn-how-compilers-work night
>>
>>51853738
It's an AoC-in-1-minute-so-we-can-stop-arguing-about-averaging-2-ints-in-c night
>>
>>51853594
I tried to test if it was the output by using a function that will echo 1 as the argument to be evaluated, but I'm not sure what to make of the output...

    #!/bin/bash

function program {
echo 1
}

while[ program ] do;
echo Hello!;
done


output:
$ ./test.sh 
./test.sh: line 7: while[ program ]: command not found
Hello!
./test.sh: line 9: syntax error near unexpected token `done'
./test.sh: line 9: ` done'
>>
>>51852129
Alioth examples are usually good to determine the overhead cost of a language v.s. C, but not much else. For claims such as the suitability of GC, linked list, functional programming, etc. much more thorough tests are required, especially with much more complex, "unsolved" problems and soft realtime problems.

Nevertheless, here's a goodish analysis with regard to the benchmark games: http://blog.gmarceau.qc.ca/2009/05/speed-size-and-dependability-of.html

A more reliable brenchmark based on realworld, soft-realtime requirements:
https://www.techempower.com/benchmarks/#section=data-r11
Of course, this benchmark has its own issues. The design of the framework can drastically impact performance, it's unclear how much of the framework is really in the specified language as opposed to C, etc. Still, it's much more reliable, I think, than the benchmarkgames. Would be great if we had more benchmarks for something similar, i.e. for application-driven frameworks that tend to be feature-equivalent up to a point.
>>
>>51853808
my suggestion: learn bash scripting.
a relatively good guide is
$ man bash
>>
>>51853585
[ is literally just a short name for a program called /bin/test

Read the manual for it, and the manual for your shell to see what $() does.
>>
>>51853846
Thanks for the resource.
>>
>>51853878
>[ is literally just a short name for a program called /bin/test

My mind is blown, thank you.
>>
>>51853846
Also, I like how the Ur programming language (a purely functional ml-family language that takes from haskell and ML, with a more complex type system)'s framework is the second fastest on the list, despite all the java, c and c++ entries.
>>
>>51850125
Why OP needs to be such a fucking faggot every time?
>>
>>51851208
I'm with this guy.

Calling it studio makes no sense.
>>
>>51853917
in the studio you record and play back
input and output
:%)(
>>
>>51853587
I think you're misinterpreting what he meant.
>>
>>51854013
s/he's joking, m8
>>
>>51853938
But the amplifier doesn't record a thing, not while it plays back. I guess if you pass it to a sound manipulation program but there's a whole buffer involved there and then on top of that you are using the program.

Don't take this to mean that I think you're wrong and the analogy doesn't hold, the more I think on it the more it makes sense, but I'm still not sold on studio as a whole. Perhaps you could make the argument for it being one such modality in aspect of instrument/peripheral notions. As a guitar you could use input and output all at once but you aren't using stdio if you input to a sound manip program and you aren't just using stdio. That's mainly my point of dissonance. You gotta remember that there are autists about.

No offense autismo buddies.
>>
>>51854044
Pretty sure she wasn't. He might've been.
>>
Learning mememacs
>>
>Developers: What syntax you want senpai?
>Rust: You know C++?
>Developers: Say no more
>>
I don't even know where to get started with day 14's challenge...
>>
File: advent tree.jpg (111 KB, 703x657) Image search: [Google]
advent tree.jpg
111 KB, 703x657
>>51854148
What help do you need?
>>
>>51854192
like...
how do you simulate 6 reindeer simultaneously without writing a bunch of ugly decrementer loops for each reindeer.
>>
>>51851566
despite what you see amongst the speshul snowflake posters on this board, none of us actually care which language you prefer

now fuck off :^)
>>
>>51854148
Post the problem you nigger.
>>
>>51854218
nigga that's the way I wrote it
>>
>>51854232
--- Day 14: Reindeer Olympics ---

This year is the Reindeer Olympics! Reindeer can fly at high speeds, but must rest occasionally to recover their energy. Santa would like to know which of his reindeer is fastest, and so he has them race.

Reindeer can only either be flying (always at their top speed) or resting (not moving at all), and always spend whole seconds in either state.

For example, suppose you have the following Reindeer:

Comet can fly 14 km/s for 10 seconds, but then must rest for 127 seconds.
Dancer can fly 16 km/s for 11 seconds, but then must rest for 162 seconds.
After one second, Comet has gone 14 km, while Dancer has gone 16 km. After ten seconds, Comet has gone 140 km, while Dancer has gone 160 km. On the eleventh second, Comet begins resting (staying at 140 km), and Dancer continues on for a total distance of 176 km. On the 12th second, both reindeer are resting. They continue to rest until the 138th second, when Comet flies for another ten seconds. On the 174th second, Dancer flies for another 11 seconds.

In this example, after the 1000th second, both reindeer are resting, and Comet is in the lead at 1120 km (poor Dancer has only gotten 1056 km by that point). So, in this situation, Comet would win (if the race ended at 1000 seconds).

Given the descriptions of each reindeer (in your puzzle input), after exactly 2503 seconds, what distance has the winning reindeer traveled?
>>
>>51854254
did you hardcode them in, or do you get their parameters and even the number of reindeers by parsing the input?
>>
>>51854256
Guy who solved it here. I actually used math to calculate it for part 1, but for part 2, you will need incrementers or decrementers:

--- Part Two ---

Seeing how reindeer move in bursts, Santa decides he's not pleased with the old scoring system.

Instead, at the end of each second, he awards one point to the reindeer currently in the lead. (If there are multiple reindeer tied for the lead, they each get one point.) He keeps the traditional 2503 second time limit, of course, as doing otherwise would be entirely ridiculous.

Given the example reindeer from above, after the first second, Dancer is in the lead and gets one point. He stays in the lead until several seconds into Comet's second burst: after the 140th second, Comet pulls into the lead and gets his first point. Of course, since Dancer had been in the lead for the 139 seconds before that, he has accumulated 139 points by the 140th second.

After the 1000th second, Dancer has accumulated 689 points, while poor Comet, our old champion, only has 312. So, with the new scoring system, Dancer would win (if the race ended at 1000 seconds).

Again given the descriptions of each reindeer (in your puzzle input), after exactly 2503 seconds, how many points does the winning reindeer have?
>>
File: OOP.png (152 KB, 1948x858) Image search: [Google]
OOP.png
152 KB, 1948x858
sounds like a job for OOP
>>
>>51854306
oranges again?
>>
>>51854277
For part 1, I did math to calculate the distance I travel in the next number of running or resting seconds. When I got close to the ending number of seconds, I only calculated the distance I'd make in those remaining seconds if I was running, or stopped there if I was resting. I added it into an array of distances, and printed the max

For part 2, I have an array of arrays of 3 numbers from parsing the input values (an array of km/s, run time, rest time). I also made separate arrays of running time or resting time left, distances traveled by each reindeer, and points accumulated

>>51854306
I probably could have benefited from OOP, though it's still pretty short without

>>51854279
Forgot code doesn't wrap, would've made it look nicer

--- Part Two ---

Seeing how reindeer move in bursts, Santa decides he's not pleased with the old scoring system.

Instead, at the end of each second, he awards one point to the reindeer currently in the lead. (If there are multiple reindeer tied for the lead, they each get one point.) He keeps the traditional 2503 second time limit, of course, as doing otherwise would be entirely ridiculous.

Given the example reindeer from above, after the first second, Dancer is in the lead and gets one point. He stays in the lead until several seconds into Comet's second burst: after the 140th second, Comet pulls into the lead and gets his first point. Of course, since Dancer had been in the lead for the 139 seconds before that, he has accumulated 139 points by the 140th second.

After the 1000th second, Dancer has accumulated 689 points, while poor Comet, our old champion, only has 312. So, with the new scoring system, Dancer would win (if the race ended at 1000 seconds).

Again given the descriptions of each reindeer (in your puzzle input), after exactly 2503 seconds, how many points does the winning reindeer have?
>>
File: fgf43.jpg (64 KB, 1024x768) Image search: [Google]
fgf43.jpg
64 KB, 1024x768
>Instance variables of reference types such as String are initialized to _______ by default

can someone please answer this for me, heres kirsty gallacher as a thank you in advance
>>
How do I reset a for loop? I tried i = 0 but that didn't work.
>>
>>51854335
Protip: Always, ALWAYS, A L W A Y S, say what programming language you are talking about when asking a question.
>>
File: haskell.png (54 KB, 600x600) Image search: [Google]
haskell.png
54 KB, 600x600
What should I read to learn Haskell?

>>51854362
If you're using any sane language, it should work.
>>
>>51854362
for(int i = 0; i < x; ++i)
{
//code

i = -1;
}
>>
>>51851774
Is that why you shit all over your duties as mod?
>>
>>51854362
What are you doing that needs this?
>>
>>51854306
This is enough OOP right?

typedef struct {
char *name;
unsigned speed;
unsigned flight_time;
unsigned rest_time;
State state;
} Reindeer;

typedef enum {
rest,
flight,
} State;
>>
Messing with ruby for the first time

//I can understand the possible value in redefining the delimiter for strings, but when the fuck is that actually practical when you have non-escaped strings with single-quotes?

puts %Q=\nSeriously.. What the fuck?\n=
>>
>>51854370
Java, sorry dude
>>
>>51854335
null
>>
>>51854335
empty string
""
>>
Learnig c++ and found this little snippet online when learning about bit shift operators. Could anybody explain what the hells going on here?

 
x = ((value&0x00000400 ? -1 : 0) + (float)((value>>2)&0x0FF) / 256.0f);
>>
>>51854518
Value is bitmasked with 0x400, so it's either 2048 or 0 (true or false)

The ternary result is -1 if true, 0 if false.
Value is then bit shifted 2 times (multiplied by 4) and bitmasked with 0xFF meaning the last 8 bits will be the largest result... then some floating point mantissa shit that I don't care to look up.
>>
Am I doing this OOP thing correctly?
Reindeer *create_reindeer(const char *nme, unsigned spd, unsigned f_time, unsigned r_time)
{
/* create reindeer actor */
Reindeer *ptr = (Reindeer *) malloc(sizeof(Reindeer));
char *str = (char *) malloc(sizeof(char) * strlen(nme));
strcpy(str, nme);
ptr->name = str;
ptr->speed = spd;
ptr->flight_time = f_time;
ptr->rest_time = r_time;
return ptr;
}
>>
File: 1436227402539.jpg (73 KB, 567x450) Image search: [Google]
1436227402539.jpg
73 KB, 567x450
When did you reach satori and started doing memory magic with your C programs to do things you'd never be able to do in any other language?
>>
>>51854554
Needs to extend a generic Deer class that contains tail colors, and properties of belonging to Santa.

The deer class should also extend an empty "GenericAnimal" class that has no definition.
>>
>>51854554
>Casting void pointers
>sizeof(char)
>Using sizeof on type instead of variable
>>
>>51854324
Here's my code. I could shorten it more, but then it'd look unintelligible:

from re import search
data=open("Advent14.txt").read().split("\n")

seconds, nums, points, times, distance = 2503, [], [], [], []

for c,i in enumerate(data):
nums.append([])
nums[c]=search("(\d+).+?(\d+).+?(\d+)",i).groups()

points.append(0)
times.append([0,int(nums[c][1]),0])
distance.append(0)

for i in range(seconds):
for i in range(len(data)):
timeType=times[i][0]+1
if times[i][timeType]>0:
times[i][timeType]-=1

if timeType==1:
distance[i]+=int(nums[i][0])

if times[i][timeType]==0:
times[i][0]=1-times[i][0]
times[i][3-timeType]=int(nums[i][3-timeType])

maxD=max(distance)
for i in range(len(data)):
if distance[i]==maxD:
points[i]+=1

print max(distance)
print max(points)


nums is an array of reindeer information (km/s, how long it runs for, how long it rests for)

times is an array for decrementing (first index is 0 if running and 1 if resting, running time left, resting time left)

timeType is just the index for times, so it's 1 if running and 2 if resting, so I can do times[reindeer][1] to get the number of seconds that reindeer has left running, and times[reindeer][2] to get the number of seconds that reindeer has left resting

Following from that, 3-timeType gets the other index (2-resting if currently 1-running, and 1-running if currently 2-resting)

Everything else should be easy to understand. I could've used OOP, and it would have made it nicer to look at, and somewhat scalable if part 2 introduced more variables, though it's a little overkill for this particular challenge
>>
>>51854565
Like what?
>>
>>51854374
https://github.com/bitemyapp/learnhaskell

This is a nice guide.
>>
>>51854593
probably crap like flooding the CPU that floods memory with cache misses which eventually flip a bit, giving you root access.
>>
>>51854612
I'll check it out, thanks.
>>
>>51854580
>tfw someone else uses itertools properly, and it's shorter, clearer and readable
Python libraries are cheating

import re
import itertools
import collections

text = open('challenge_14.txt').read()
regex = r'(\w+) can fly (\d+) km/s for (\d+) seconds, but then must rest for (\d+) seconds.'
history = collections.defaultdict(list)
for who, speed, duration, rest in re.findall(regex, text):
steps = itertools.cycle([int(speed)]*int(duration) + [0]*int(rest))
history[who] = list(itertools.accumulate(next(steps) for _ in range(2503)))

by_dist = max(h[-1] for h in history.values())
print(by_dist)

scored = [i for a in zip(*history.values()) for i, v in enumerate(a) if v==max(a)]
by_points = max(collections.Counter(scored).values())
print(by_points)
>>
File: 1437005687877.jpg (83 KB, 396x385) Image search: [Google]
1437005687877.jpg
83 KB, 396x385
>>51854593
Like understanding you never need to store malloc sizes once you understand where malloc stores its meta data

Like breaking into memory you shouldn't be in

Like doing everything strange tricks that help with performance
>>
>>51854612
So I make it and it just gives me a pdf of the readme and a guide to Scala. Nice.
Thread replies: 255
Thread images: 19

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.