[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: 26
File: functional programming.jpg (64 KB, 440x389) Image search: [Google]
functional programming.jpg
64 KB, 440x389
PRIME FIZZBUZZ EDITION
[ f(x) | x <- [1,100] ] where f(x) = 
| "Fizz", prime(x) ∧ (x % 3 = 0)
| "Buzz", prime(x) ∧ (x % 5 = 0)
| "FizzBuzz", prime(x) ∧ (x % 15 = 0)
| string(x), otherwise


>i don't understand
Don't call us, we'll call you

Last thread: >>54827174
>>
You forgot the "What are you working on /g/? "
Here I'll do it for you.
What are you working on /g/?
>>
Guise look LOOK!

I can learn ALL of the C++ language watching this YT Tutroial!!!1

https://www.youtube.com/watch?v=Rub-JsjMhWY
>>
File: asdasd.gif (2 MB, 245x251) Image search: [Google]
asdasd.gif
2 MB, 245x251
>>54832945

>print if x is prime and divisible by 3 5 or 15
>prime and divisible by
>prime
>divisible
>>
>>54832945
#!/usr/bin/env sh
for i in $(seq 1 100); do
if [ $((i % 15)) -eq 0 ]; then
printf 'FizzBuzz '
elif [ $((i % 3)) -eq 0 ]; then
printf 'Fizz '
elif [ $((i % 5)) -eq 0 ]; then
printf 'Buzz '
else
printf '%s ' "$i"
fi
done

Am I doing it right?
>>
>>54833021
>using namespace std;
dropped
>>
Sixth for Python is the best
>>
>>54833034
>he likes to write everything by hand
>>
>>54833022
Try actually reading that code
>>
>>54833045
>uses std

there's a reason it is called STD you know.
>>
>>54833045
don't put a (using namespace _) in the global namespace
>>
>>54833048

Λ means "and" you faglord.
>>
>>54833022 >>54833048 >>54833064

No helping each other.
>>
how did i do guys?

#include <stdio.h>

int main()
{
int i = 1;

counter:
while (1)
{
printf("%d, ", i++);
if(i > 100) goto exit;
if(i % 3 == 0) goto fizzer;
if(i % 5 == 0) goto buzzer;
}

fizzer:
while (1)
{
printf("Fizz");
if(i++ % 5 == 0) goto buzzer;
printf(", ");
if(i > 100) goto exit;
if(i % 5 == 0) goto buzzer;
if(i % 5 && i % 3) goto counter;
}

buzzer:
while (1)
{
printf("Buzz, ");
if(++i > 100) goto exit;
if(i % 3 == 0) goto fizzer;
if(i % 5 && i % 3) goto counter;
}

exit:
return 0;
}
>>
>>54833030 >>54833094

Please read the problem before attempting to solve it.
>>
>>54833064
If by prime you mean
isprime
then you are correct, but if you do you should learn basic function naming, otherwise I will continue on the assumption that prime(n) returns the n-th prime, which will always evaluate to true (in most languages).
>>
>>54833094
goto always triggers my autism.
>>
>>54833094
Enterprise/10
>>
What was the worst place that called you to work for them?

Mine was some "IT company" working with Microsoft Sharepoint, and people called themselves .NET developers.
>>
File: 26041546.gif (397 KB, 1092x417) Image search: [Google]
26041546.gif
397 KB, 1092x417
Is there a sticky somewhere?

I'm learning C++
Watching thenewbostons tutorials, starting to lose me at video 45. Any complimentary literature?
>>
>>54833030
>
    if [ $((i % 15)) -eq 0 ]; then

Not sure but I guess this isn't even needed. One could just append the buzz. Correct me if wrong.
>>
>>54833094

magnificent
>>
learning regex and shit desu
>>
Ruby or Python? Can't decide but I want to try something more comfy than C.
>>
File: Traffic.gif (8 KB, 306x301) Image search: [Google]
Traffic.gif
8 KB, 306x301
>tfw this happens in your program
>>
>>54833163
Sometimes I love it when this happens.

A good way to learn shortcuts, glitches also nice for databending when it happens to media processing.
>>
File: 1443131813754.jpg (92 KB, 333x500) Image search: [Google]
1443131813754.jpg
92 KB, 333x500
>>54833163
>.gif
>doesn't move
>>
>>54833195
It does move, they're just in gridlock.
>>
>>54833161
Tqbh ruby is more of a structured language than python

there isn't even a switch/pattern match in python!
>>
File: 1440115199471.jpg (28 KB, 480x360) Image search: [Google]
1440115199471.jpg
28 KB, 480x360
>>54833177
Sort of related: How to create such glitches?
Language doesn't matter.
>>
>>54833152
If you're going to learn sed, read this:
http://www.grymoire.com/Unix/sed.html
It's a god's gift.
>>
>>54833152
also this: http://www.grymoire.com/Unix/Regular.html
>>
>>54833118
prime(x) = x is prime
>>
>>54833310
>>54833297
ty
>>
>>54833260
easy, don't clear the drawing buffer.
>>
>>54833260
Turn off compositing on your window manager or whatever. Don't ever update your buffer.
>>
>>54833130
If you add in "liver health", this gif is a representation of my life.
>>
>>54833195
>thinks gifs have to have more than one frame
This is a technology board, please leave.
>>
>>54833397
>Don't ever update your buffer.
what ?
>>
>>54833130

Video tutorials suck for learning a language desu

I recommend C++ Primer or any of Bjarne's books.
>>
how to git gud
>>
>>54833478
The image buffer.
>>
>>54833397
You *have to update* the buffer, you just *don't clear* it so the old pixels remain as is.
>>
>>54832945
>
[1,100]

What does this part produce, OP? And in general what lang is that?
>>
File: Capture+_2016-05-31-06-53-38.png (11 KB, 590x95) Image search: [Google]
Capture+_2016-05-31-06-53-38.png
11 KB, 590x95
>>54833566
If only I knew T_T
>>
>>54833566
Learn Haskell and reach satori
>>
>>54833679
It's Haskell with list comprehension
>>
>>54833679
Probably a range enumartor between [1, 100]. Just like range() generator in Python or D's range aggregator expression 1..100. And that's Haskell if I'm not mistaken.
>>
>>54833712
WTF? This is definitely not Haskell, do actually look at it. Plus my problem is that in Haskell,
[1,100]
produces a list with two elements, in order 1 and 100. Are you OP? If so can you explain yourself?
>>
>>54833737
Again, definitely not an enumerator in Haskell. So either it's not an enumerator or it's not Haskell.
>>
>>54833152
a bit late but i use this for testing regex i dont know regexr.com
>>
>>54833152
>basic substitute one word for another
>I'm learning regex guys!
>>
>>54833781
I just looked it up out of curiosity and there are what seems to be ranges in Haskell.

http://learnyouahaskell.com/starting-out#texas-ranges
>>
>>54832945
http://joelgrus.com/2016/05/23/fizz-buzz-in-tensorflow/
>>
>>54832945
>[1,100]

Why not [1...] senpai?
>>
>>54833783
That site is great. Don't forget to check out the favorites or whatever they call it. People put up all kinds of neat stuff.
>>
>>54833781
>>54833864

To add onto this, I'm not saying the OP is using ranges because those are indeed list comprehensions as you stated before so I stand corrected, I just wanted to point out that there are ranges in Haskell.
>>
>>54833022
>I can't read haskell code
>>
>>54833864
But, but, but...
>>54833923
Ok, agreed. Still my ongoing quest for wtf is this lang (must be a non-whitespacey ML now that I think about it), but thanks.

>>54833898
Right, why?
>>
File: 20160317_193145.jpg (412 KB, 600x747) Image search: [Google]
20160317_193145.jpg
412 KB, 600x747
>>54833963
IT IS NOT HASKELL FFS read the thread
>>
>>54833575
if you don't update the buffer, the image just froze, nothing happens. do you know what you are talking about ?
>>
>language discussion
Why are you all faggots who don't write software? If you're interested in (existing) languages you're clearly only in it to write masturbatory code.

Right now C (alternatively a small subset of C++) is one of the only languages capable of writing actual software.
>>
>>54832945
>>54832996
>What are you working on /g/
An alternative implementation of a CMIS server to replace our Alfresco installtions which suck.
>>
>>54834073
>the old sickly one lang to rule them all meme
Get the hell back in Mordor, 0/10
>>
File: out.webm (2 MB, 1920x1080) Image search: [Google]
out.webm
2 MB, 1920x1080
>>54834039
Isn't this what you're talking about?
I just took some glfw test code of mine, added an infinite loop before the rendering loop, and turned off my compositor.
>>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <memory>
#include <string>
#include <utility>
#include <vector>

struct Rule
{
std::vector<uint32_t> divs;
std::string word;

Rule(std::initializer_list<uint32_t> divs, const std::string &word)
: divs{divs}
, word{word}
{
}

bool applies(uint32_t i) const
{
for(const auto &div: divs)
{
if((i % div) != 0)
return false;
}

return true;
}
};

struct Range
{
uint32_t from;
uint32_t to;
std::function<void(uint32_t)> cb;

Range(uint32_t from, uint32_t to, const std::function<void(uint32_t)> &cb)
: from{from}
, to{to}
, cb{cb}
{
}

void run()
{
for(decltype(from) i = from; i <= to; ++i)
cb(i);
}
};

struct FizzBuzz
{
std::vector<std::unique_ptr<Rule>> rules;

void add(std::initializer_list<uint32_t> divs, const std::string &word)
{
rules.push_back(std::make_unique<Rule>(divs, word));
}

void run(std::initializer_list<uint32_t> range)
{
if(range.size() != 2)
return;

(Range{*range.begin(), *(range.begin() + 1), [this] (uint32_t i) {
bool applied = false;
for(const auto &rule: this->rules)
{
applied = false;
if(rule->applies(i))
{
fprintf(stdout, "%s\n", rule->word.c_str());
applied = true;
break;
}
}

if(!applied)
fprintf(stdout, "%d\n", i);
}}).run();
}
};

int main(int, const char **)
{
FizzBuzz f{};
f.add({3, 5}, "FizzBuzz");
f.add({3}, "Fizz");
f.add({5}, "Buzz");
f.run({1, 15});

return 0;
}
>>
print_string:
pusha
mov ah, 0x0e

compare:
mov al, [bx]
cmp al, 0
je end
int 0x10
add bx, 0x1
jmp compare

end:
popa
ret


print_string:
pusha
mov ah, 0x0e

compare:
cmp bx, 0
je end
mov al, [bx]
int 0x10
add bx, 0x1
jmp compare

end:
popa
ret


Anyone know why the top one works but the bottom doesn't?
>>
>>54834562
because they do different things
>>
>>54833161

I'm a Ruby fan personally

How's my Ruby FizzBuzz guise?

(1..100).each do |i|
s = ""
s << "Fizz" if (i % 3 == 0)
s << "Buzz" if (i % 5 == 0)
puts (s.empty? ? i : s)
end


Or there's my one line version but people never comment on it, maybe because it looks like a bit of a clusterfuck

(1..100).each {|i| puts (s = "#{'Fizz' if (i % 3 == 0)}#{'Buzz' if (i % 5 == 0)}").empty? ? i : s  }
>>
File: why_c_is_shit.png (154 KB, 1354x347) Image search: [Google]
why_c_is_shit.png
154 KB, 1354x347
>>54832945
How correct is this?
>pic related
>>
>>54834616
Pretty correct. C is obsolete in this day and age and only used in legacy projects.
>>
>>54834616
it's true
look at recent updates in language, they are becoming more ``functional"

soon it will be immutable by default and have more monads
>>
iota(1, 21).map!(a => a.predSwitch!("a % b == 0")(15, "FizzBuzz", 3, "Fizz", 5, "Buzz", a.to!string)).writeln;


>smug Andrei Alexandrescu.jpg
>>
>>54834616
>Tries to criticise C
>Brings up C++
wat?
>>
>>54834659
The arguments against both are the same; tons of little gotchas that make the language a pain in the dick to work with.
>>
>>54834666
C and C++ are completely different languages.
It makes absolutely no sense to lump them together.
>>
>>54834670
Read what I wrote; specifically, both have many little things that can trip you up.

I'm not saying the languages are similar.

I'm saying they both have a particular annoying quality that is solved by higher-level languages.
>>
>>54834688
>both have many little things that can trip you up
You can say that about literally ANY language. No language is perfect at anything.
>I'm saying they both have a particular annoying quality that is solved by higher-level languages.
Which comes with its own costs. Every high level language isn't even close to filling C's niche.
>>
>>54834600
s = ""


vs

s = Array.new


?
>>
>>54834616
not really true, but it's hard to do *good* code these days.

true

true

I'm not quite sure, but the zero terminated stuff is problematic in qutie a few situations

C++ is a world on its own
>>
>>54834712
>anything
"everything" I mean
>>
>>54834721
>the zero terminated stuff is problematic in qutie a few situations
such as?
>>
Hey /g/ rate my string sort
string_length = None
def strlen( string ):
global string_length
if string_length == None:
string_length = 0
try:
string[ string_length ]
string_length += 1
except IndexError:
string_length -= 1
string_length_to_return = string_length
string_length = None
return string_length_to_return
return strlen( string )
>>
>>54834616
It is too vague, and makes many claims without anything to back them up.

For example, but not limited to:
>C is anti-efficient
>Not cleaner than assembly
>"""Many""" gotchas and traps
>Not fast.
>Complains about a petty program entrypoint spec. Misuse the term "calling convention"
>Again, vague claims this time about C++
>Vague claims about his langage of choice (probably Go or Rust or D), attacks the community, and again vague claims about C++

That's a hell of a long post to basically say nothing.
>>
>>54833702
He said git gud, not turn into a massive useless faggot.
>>
>>54834770
Absolute trash
>>
>>54834770
enterprise/10
>>
>>54834770
def strlen( string, string_length=None ):
if string_length == None:
string_length = 0
try:
string[ string_length ]
string_length += 1
except IndexError:
string_length -= 1
string_length_to_return = string_length
string_length = None
return string_length_to_return
return strlen( string, string_length )


No need for the global.
>>
>when the IRC starts speaking in Portuguese

Fuck.

I didn't want to talk about programming anyway.
>>
>>54834809
Still absolute trash
>>
>>54834580
Yes evidently.
>>
>>54833094
I'd say this is Pajeet-tier but it's not C# or Java so at least you have that going for you
>>
>>54834713
Well you wouldn't use Array.new because when you print that, it will print each element to a different line, and you want "FizzBuzz" on the same line.

You could use
s = String.new
but that's literally no different to
s = ""


If you want to avoid either of those you could just do this:

(1..100).each do |i|
s = "#{'Fizz' if (i % 3 == 0)}#{'Buzz' if (i % 5 == 0)}"
puts (s.empty? ? i : s)
end
>>
>>54834770
>>54834809
(defn string-length [s]
(cond (empty? s) 0
:else (+ 1 (string-length (rest s)))))


stringLength [] = 0
stringLength (x:xs) = 1 + stringLength xs
>>
File: let_it_take_me.jpg (205 KB, 776x1054) Image search: [Google]
let_it_take_me.jpg
205 KB, 776x1054
>>54834809
>>54834770
>>54834917

I don't know what to say.
>>
>>54834979
Does Python have functional constructs? If so, implement it in those.
>>
How many languages can we implement this in?

std::string::size_type strlen(const std::string &str, std::string::size_type n = -1)
{
if(n == -1)
n = 0;

n = n + 1;

try {
str.at(n);
} catch (std::out_of_range const &) {
return n - 1;
}

return strlen(str, n + 1);
}
>>
>>54834979
By all means, please post about your shortcomings on this Chinese cartoon website, stranger.
>>
>>54832996
Thought I'd take Lua for a spin.
>>
>>54834770
>string sort
>strlen
>>
>>54832945
i really, really like that image
>>
>>54835144
Save it, it's all yours :)
>>
>>54835155
>>54835144
>>>/b/
>>
>>54832945
 
1 ]=> (define (perform2x f x) (f (f x x) x))

;Value: perform2x

1 ]=> (perform2x + 3)

;Value: 9

1 ]=> (perform2x + 6)

;Value: 18

1 ]=> (perform2x * 2)

;Value: 8


lisp makes me feel like an arcane sorcerer even though i doubt i'll ever use high order procedures on intense mathematical problems like the wizard book has in its examples
>>
someone needs to make a programming version of this with OOP vs FP
>bloated OOP encapsulation vs advanced type system
>>
File: has_u_red_it.jpg (3 MB, 2448x3264) Image search: [Google]
has_u_red_it.jpg
3 MB, 2448x3264
>>54835258
Feel free to be the change you wish to see in the world.
>>
>>54835258
have you noticed that OOP is POO backwardz?
>>
>>54835285
Have you noticed that functional programming is shitty and unintuitive in most applications?
>>
>>54835314
> unintuitive
Compare the above code samples for finding the length of a string, in Python, then Haskell.

Haskell is clear as fuck.
>>
>>54835344
>for finding the length of a string
Yes, let's compare languages based on one trivial task.

Retard.
>>
>javafriends want to ban THIS
 
1 ]=> (define (f9) (lambda (x) (+ x 5)))

;Value: f9

1 ]=> (f9 3)

;The procedure #[compound-procedure 13 f9] has been called with 1 argument; it requires exactly 0 arguments.
;To continue, call RESTART with an option number:
; (RESTART 1) => Return to read-eval-print level 1.

2 error> 1

;Value: 1

2 error> ((f9) 3)

;Value: 8

2 error>
>>
>>54833094
Production ready
>>
>>54835314
it's really not. you make low level tools and combine tools to make more complex tools. the top level ends up as being as elegant and abstract as you want it to be
>>
File: 1464694237246.png (218 KB, 716x362) Image search: [Google]
1464694237246.png
218 KB, 716x362
>>54835344
>Compare the above code samples for finding the length of a string, in Python, then Haskell.
?
print(len(str))
>>
>>54835416
The point was to replicate the originally written function, not use built-ins that can already achieve it.
>>
>>54835442
i think you chose a shitty way to make your point m8
def strlen(s):
i = 0
for c in s:
i += 1
return i
>>
Is anybody here particularly handy with SQL?

I'm trying to build a lightweight online tabletop system and have a bit of a design quandary.

Any given game will have to have token information stored for it. All that information I already have mapped pretty easily.
However: How should I actually tie that stuff together?
The way I'm storing token info is just to have a general "token" table, with a GUID to tie into a token image table, and everything else would just be some light strings and ints.

But I'm not sure how to...tie that into a table of games? Should the games table just be a GUID for the individual game and ownership/membership of it, and then have a column in the token table to tie them into their respective game?

If that didn't make sense: A game has any given number of tokens. The token information is currently going to be stored in it's own table. I need a way to tie tokens to a game without having a trillion billions records in the game table. Also, I have no idea if having a general token table like I described will cause an issue.
>>
>>54835442
Why is it even a point of comparison between the two languages?

Every modern language has built-in functionality for that.

Haskell has a built-in, too, right?
>>
Why are we having TWO threads for fizzbuzz?
>>
>>54835519
That does not do the same thing that the original function does.

>>54835529
>Every modern language has built-in functionality for that.
Well ask that retard that wrote the original function instead of doing len(string).
>>
>>54835520
A foreign key, maybe?
>>
>>54835555
Yeah that's what I'm leaning towards, but it's mostly the "this will generate enormous tables over time" thing.
I guess thinking about it, the token table would be the problem area since for every game that is made a dozen token records or more will be made. But I don't think there's a better way to split that up?
>>
>>54835520
create a "Game" table and add a foreign key to your tokens

>inb4 muh performance
DBs are built for this shit
>>
>>54835354
The triviality emphasises how shit Python is when compared to Haskell, retard.
>>
>>54835547
yes it does
>>
>>54835520
Think about identifiers.

Does a token have a particular game it belongs to?

When you say game, are you referring to a type of game, or the game itself? (Checkers, or MyGame1547 which is a Checkers game)

You could have something like the following:
>Games
Game name, information about the game type, created by, date modified, etc.
>Sessions
Session name, information about the session
>Players
Info about each player
>PlayerSessions
A tie-in table that allows a many-to-many between players and sessions
>Tokens
All tokens go here, with information about only the token itself
>GameTokens
Many-to-many for games and tokens
>SessionTokens
Many-to-many for sessions and tokens.

This would get you flexibility to have a single token with custom properties belong to many games, say a custom character in a DND game.
>>
>>54835587
You should be concerned with performance only if you expect to have billions of records.

Do you?

If you do, make a simple prototype now, and go back to it later IF it's an issue (it won't probably)
>>
>>54835614
this
speed isn't a problem until it's a problem
i know it sounds like bullshit, but its actually pretty good advice
>>
>>54835344
>>54835416
>>54835442
>>54835519
>>54835547
>>54835610
guiz it was bait

>>54835610
Actually it doesn't, the original returns len(string) - 1
>>
>>54835529
Haskell's built-in for string length, or any length:
length
>>
>>54835663
Early optimization is root of much evil, amirite?
>>
>>54832945
>ever checking prime(x) ∧ (x % 15 = 0)
>checking 3 and 5 on every iteration instead of just printing them at the start
retard
>>
>>54834616
what's he even complaining about? about the performance of C? what's a better alternative then?
>>
>>54834562
because the bottom one never ends
bx will never be 0 and cmp bx,0 will always fail
(don't know whether intentional)
>>
>>54835695
if you honestly believe that guy is better off thinking about the speed of his never to be released personal practice game instead of learning more useful shit like how to manage and release a large scale project complete with documentation and testing, you're a fucking idiot
but whatever, go fix the stack alignment and cache misses of your fizzbuzz program

>>54835666
no it doesn't
>>
>>54833909
Good site use it all the time.
>>
>>54835787
you can do both you fucking retard
>>
>>54835787
I was agreeing, actually.
But I'm always up for some eFighting.

>faggot
>>
>>54835520
>>54835787
>>54835812
especially database shit can be INSANELY inefficient and end up costing you gorillions in hosting expenses
>>
>>54835787
>no it doesn't
which 'original' function are we talking about here?
>>
>>54835822
Reminds me of that time someone was using a SQL abstraction library and they ended up generating like 400,000 unique connections all doing a small query.

That would be a fun bill at the end of the month, depending on if your usage plan has a per request rate.
>>
>>54835819
>I was agreeing, actually.
oh

>>54835822
yeah you're right
usually tha happens because of A LOT of unnesessary queries and duplicate information and not so much because of design flaws though
>>
>>54835822
>especially database shit can be INSANELY inefficient
only if you're a literal retard
>>
Not sure where to post it but
Is it possible to know the pages in a file that i want to print? I'm using windows and printing through cmd
>>
>>54836045
what command are you using tho?
you should refer to the docs of that command, probably
>>
So I wrote a simple threaded function manager that enqueues tasks in a safe manner (using locking/signaling mechanism) and always executes these functions that are enqueued one by one, is it safe to assume that if those functions fire and access the same data, there's no need for mutexes inside of them because the manager already guaranteed only one will execute at a time?
>>
>>54836092
yes
>>
>>54836092
uh
is there even a point using multiple threads if you're gonna execute them synchronously anyways?
or did i read your post wrong?
>>
>>54836073
print "file"
with ShellExecuteA
>>
>>54836114
Just two threads (main thread & manager thread), the manager will execute the logic synchronously but the enqueued functions will come from an asynchronous socket. It's for a simple multiplayer game based on async networking.
>>
>>54835778
Thanks for the reply.

It was unintentional. I didn't realise that the
cmp bx, 0
was comparing the address and not the value at the address.
>>
>>54836218
is this for osdev?
>>
Anybody send help
I found this
>http://morf.lv/modules.php?name=tutorials&lasit=21

And sometimes it crashes "SIGSEV" and i have no idea why i had this before and it was when i tried to send/write data in a closed/disconnected qtcpSocket
>>
>>54836233
Yeah just starting
>>
>>54836274
what resources are you using?
>>
>>54836329
I know about OSDev and the various other tutorials, but I like how slow this one is so I'm using it for now https://www.cs.bham.ac.uk/~exr/lectures/opsys/10_11/lectures/os-dev.pdf
>>
>>54836357
i actually used that too
>>
What is the area in industry/academic circles in which functional reigns over imperative?
>>
File: 1444700676915.jpg (823 KB, 1920x1080) Image search: [Google]
1444700676915.jpg
823 KB, 1920x1080
/dpt/-chan, daisuki~

>>54835778
>bx will never be 0
>add bx, 0x1
This should make bx overflow to zero when its value equals 65535

>>54833163
diamonds ?
>>
>>54836390
fedora-tipping
>>
File: 6489.jpg (497 KB, 2560x1440) Image search: [Google]
6489.jpg
497 KB, 2560x1440
>>54836390
PLT
>>
>>54836427
aka leeching government funds to talk about endofunctors
>>
>>54836387
Yeah lots of well worded explanation.
>>
>>54836390
none?
>>
I've only ever made some basic web applications (mostly project management/task assignment stuff). I'm looking at making a basic desktop application that will effectively be a time clock.

Here's what I want it to do:

Have a list of employees that you can add/remove
Allow each employee to clock in and clock out multiple times a day
At the end of the week generate a report for each employee that shows each day and a total number of hours at the end of the week

I know how I can implement the features but what I'm not sure about is the structure. I'm not sure what classes I should use. Should there be an employee class, a timeclock class, and a report class or should all of the functionality be consolidated to one or two classes?

I wind up with analysis paralysis when I try to think of how to organize things like this and then I never start coding. I know how I'd do it as a website but I'd prefer this to be a desktop application that I can learn the basics of C# through.

Thanks for any and all help.
>>
>>54836483
>Have a list of employees that you can add/remove
employee class

>Allow each employee to clock in and clock out multiple times a day
timeclock class
>At the end of the week generate a report for each employee that shows each day and a total number of hours at the end of the week
report class or a generateReport method of the timeclock class
>>
>>54836427
Why is it so smug?
Also why the fuck can i see its eyebrows on top of the hair
>>
Have any of you guys learnt programming completely online (No lynda or any other paid course bullshit) and are now good at it? Is a professor mandatory for learning a language?
>>
>>54836607
the thing barely even looks human with those freaking animu eyes
>>
>>54836616
a professor is hardly any help at all, going to a school just slows you down and is only for getting the degree and maybe networking, it's better to self-learn programming
>>
>>54836607
to make the character's emotions more obvious to the reader. zelda wind waker did the same with great success.
>>
>>54836681
>the reader
autists and children that is
>>
>>54836607
>Why is it so smug?

There is high demand for smug anime grills.
>>
>>54836647
>it's better to self-learn programming
You still need to practice working with other people who are experienced, or you'll end up doing something in a horribly inefficient way for a long time.

Best case scenario is to learn enough for an entry-level position and learn as much as you can on the job.
>>
I just love that whenever someone criticizes OOP, people immediately jump and assume that they must be a "functional programmer", and then rattle off the same, incorrect, knee-jerk "le FP no side effects useless" and things like that.
>>
>>54836920
Noted.
>>
>>54836920

People's criticisms of OOP are usually substance-free. Moreover, the people who posit these non-arguments typically are functional or procedural programmers. I don't recall one of the OOP-haters preferring any paradigm aside from those two.
>>
int width, height;
bool gotwidth = false;
bool gotheight = false;

FILE* f = fopen("size.txt", "r");
int pos = 0;
char linebuffer[256];
char c;
while ((c = fgetc(f)) != EOF)
{
if (c != '\n')
{
linebuffer[pos] = c;
pos += 1;
}
else
{
char* string;
pos = 0;
strncpy(string, linebuffer, pos);
string[pos] = '\0';
if (!gotwidth)
{
width = atoi(string);
gotwidth = true;
}
if (!gotheight)
{
height = atoi(string);
gotheight = true;
}
}
}
fclose(f);


This causes a crash, but I can't see what's wrong with it. Any C gurus want to give it a look?
>>
>>54836976
>People's criticisms of OOP are usually substance-free.
Not really. It's easy to show that OOP is a failure, in that encapsulation doesn't control state very well. It's also easy to show that inheritance-based code reuse isn't nearly as powerful as composition-based code reuse, and that the restrictions OOP imposes on your data are typically not conducive to performance.
The common response is the wholly unsubstantiated "b-but you can't write big programs without OOP" and/or to immediately change the subject.

>Moreover, the people who posit these non-arguments typically are functional or procedural programmers.
That doesn't matter. You can't defend OOP by attacking FP, or anything else for that matter. They're not somehow polar opposites, where anything you say about one is negated for the other.
>>
>>54837088
>It's easy to show that OOP is a failure

By all means, do so. I'm not suggesting that OOP is the be-all end-all programming paradigm, but it's hardly as bad as its detractors suggest.
>>
>>54837065
Do you check if the file successfully opened? f will be null in that case.
>>
>>54836920
This is just you people (honestly think you do seem like a coordinated shit posting group right now) pretending that's the case. I've been opposed OOP for years without people assuming I'm in favor of FP to any large extent.
>>
>>54837142
>I've been opposed OOP for years without people assuming I'm in favor of FP to any large extent.

But truthfully, you are. You are a functional programmer.
>>
Yo for real the fuck is std and cout
>>
>>54837065
Why not something like this?
int width = 0, height = 0;
FILE *file = fopen("size.txt", "r");
if(!file) return;

char buffer[256];
fread(file, buffer, sizeof(buffer));
fclose(file);

sscanf(buffer, "%d %d", &width, &height);


I don't know C so you might need to adjust sscanf/fread calls but you get the gist.
>>
>>54837124
the file opens fine, i just checked

damn c is confusing
>>
>>54837119
OOP Is as bad as you make it. Pure OOP is pure garbage. A little OOP doesn't really matter. (and frankly a little OOP could easily be regarded as no OOP because it's a rather absolute paradigm).
OOP does nothing to assist the programmer though. You usually find that what people like about OOP is that it's the first time they've structured their programming in some way. It's also very common for it to be the first real libraries people use so they feel powerful perhaps.

What people tend to like about OOP isn't really about OOP most of the time. Polymorphism is one of those things I feel people confuse with OOP all the time. When people say that large software projects are impossible without OOP they usually mean they can't build large software without polymorphism.

Not all the time obviously. But often.
>>
>>54837156
I haven't used a functional programming languages. I'm an IP programmer to the core. I think that FP could be OK. The promises are appealing and the idea is way more solid than OOP. But I haven't really tried it so I can't say much about it.
>>
>>54837203
What's the intent there?
It's pretty hard to tell but it seems to me all you're doing us reading a file and extracting some ints
Wouldn't it be simpler for you to read the file and then extract the ints?
>>
>>54837119
The "point" of OOP is that you can control complexity by breaking things up into smaller components and hiding the inner workings of these components from one another by forcing them to communicate through "messages". This doesn't work, because without some other system in place, you have no guarantees about what OTHER objects are doing to a particular object. Now, OOP works against you because of how easy it is to hide away objects' dependencies on one another, especially if you're working in a team with the way OOP is usually taught (which is where OOP programmers say the strength of OOP lies, no?)
>>
>>54837203
>>54837203
char* string;
pos = 0;
strncpy(string, linebuffer, pos);

Read how strncpy works. You're declaring `string`, but not allocating or assigning it anything. Then you try to copy 0 characters to a place that doesn't exist, using an uninitialized pointer.
>>
>>54837249

What is your favorite lang?
>>
>>54837276
>you have no guarantees about what OTHER objects are doing to a particular object

lol @ you
>>
>>54837292
If you're making fun of the fact that I like to have the compiler work with me to provide guarantees, why would you ever use something like OOP, which posits to do this?

No matter whether you like to juggle everything in your own head or put it in your code and have the compiler check it for you, OOP does not accomplish what it's intended to do.
>>
>>54837291
A small subset of C++.
Really it'd be dumb to consider it my favorite language. It's what I have to live with. Arguably I could move to D or whatever. But I just feel they don't offer enough to be worth the move. Maybe I'm wrong though. I keep saying I should look into it but I don't.
>>
>>54837270
That is what I'm doing. Is there a better and much easier way of doing this?
>>
>>54837310
I making fun of the fact that you think you can't guarantee what's going to happen to an object.
>>
File: 7phuJaq6.jpg (42 KB, 512x512) Image search: [Google]
7phuJaq6.jpg
42 KB, 512x512
>>54837318

Do it for him.
>>
>>54837323
Not just OOP, you can't. If you put another system in place like linear types, then why even bother using OOP in the first place?
>>
Being that you're coming from a subset of C++, you should read two articles on the D wiki:

D for C programmers
D for C++ programmers

They cover most of the feature differences.
>>
>>54837335
I have no clue as to what you mean by 'not just OOP'.

I like to use OOP/sane programming practices, or as I've taken to calling it, OOP + Sane Programming Practices.
>>
>>54837362
Alright, then, how does OOP help guarantee what will or will not happen to an object by some external force?
>>
>>54837321
Read the entire file into a buffer.
Read the entire buffer for the values you want and save them in some way.
Work with the ints.
If only to just get to ignore the fuzziness with files and just work with extracting ints from a stings.

I think maybe your problem is that atoi is rather picky. To me it looks like you're having two ints (presumably space separated) on the same line and want to take them one at a time.
>>54837196
This does pretty much what I'd do. Except this doesn't do it per line. As I assume is your intent.
>>
>>54837368
You said that you have no guarantees about what is being done to objects.

You can design your program with OOP principles and guarantee object behavior.

I'm not entirely sure what your argument is here.
>>
>>54837379
>You can design your program with OOP principles and guarantee object behavior.
Who's talking about substance-free arguments, again?
>>
File: 1442196753224.jpg (613 KB, 3000x3000) Image search: [Google]
1442196753224.jpg
613 KB, 3000x3000
>>54833062
>using namespaces
>not writing everything yourself from scratch and just naming it in a failsafe way
please refrain from posting every again
>>
>>54837368

An object with no public fields or methods will not have its state changed by 'external force'.
>>
>>54837340
I'l check it out.
First thing tomorrow! Assuming nothing important comes up.
>>
>>54837391
So every object in your program should have no public interface?
>>
>>54837374
>Read the entire file into a buffer.
Do it line per line as the unix elders did, don't listen to this guy.
>>
am I doing it right
for i in xrange(1,100):
FIZZ = not bool(i%3)
BUZZ = not bool(i%5)
if FIZZ and BUZZ: print "FizzBuzz,",
if FIZZ: print "Fizz,",
if BUZZ: print "Buzz,",
else: print str(i) + ",",
>>
>>54837405

If you want to prevent any sort of sudden state change, sure. Of course, that also makes it useless, but that's what you wanted.
>>
>>54837421
So...you agree with me.
>>
>>54837405
the exposed interface is just some high-level functionality like setTripCode() and shitpost(), nothing that will break your program
>>
>>54837400
Not bad at all. I'd go for
i%3 == 0
instead of
not bool(i%3)
, it's less convoluted and better conveys your intent.

No wait there's a bug, you need elif on line 4 and 5, see why? And also you never output a newline which is strange
>>
>>54837405
https://www.youtube.com/watch?v=QM1iUe6IofM
This is OOP.
I think the first YouTube comment (for me anyway, by SGresponse) is a very nice summary of the video and OOP programmers. I agree that there's not that many people defending OOP.
>>
File: mofo.png (18 KB, 444x241) Image search: [Google]
mofo.png
18 KB, 444x241
>>54837447
meant for hypocritical tripfag >>54837418

son of a bitch
>>
>>54837431
Nah he's just conceding that you're an idiot
>>
>>54837438
I don't think you understand the issue. setTripCode() clearly modifies the object's state. What if you're using the object from one thread and, from another thread, setTripCode() is called on it? You either have to make sure that this will never happen, put mutexes on everything, which is inefficient, or attempt to solve these bugs as they happen.

OOP has fixed nothing.

>>54837471
I'm an idiot how?
>>
>>54837452
TL;DW

>why does OOP dominate the instrustry?
>why does OOP not work?
durr
>>
>>54837447
>>54837465
I'm sorry, I forgot to take my trip off from over at /flag/tism on /int/
I'd rather not clog a terminal with newlines
Using an elif is moreover just an aesthetics thing, three ifs work just as well as one if and two elifs
>>
>>54837479
any non-trivial program has state for fuck's sake kill yourself idiot
>>
>>54837493
Exactly.
>>
>>54837487
>Using an elif is moreover just an aesthetics thing, three ifs work just as well as one if and two elifs
Oops, fuck me, I'm wrong. joj
>>
>>54837479
>I'm an idiot how?

You're asking for a way to eliminate state change in a paradigm that it designed for state change. If this is bothersome, use functional programming.
>>
>>54837481
Someone else here. I persist in my secret enlightened opinion that OOP is just such a fluid dogma that it either is ridiculously convoluted or takes up credit for things that it didn't make work. But no one cares, and we need this to separate the plebeian masses from those who really understand what's going on, and when they get to the control room, just don't change anything because it's in fact perfectly working even though it cunningly pretends like it doesn't.
>>
>>54837481
Because it's not OOP when it works. And it's not dominating the industry because most don't do OOP.
>tl;dw
Why even argue on 4chan if you can't even watch a video? Clearly no interest in furthering your understanding them.
>>
>>54837493
and if you pass around objects to different threads you use mutexes in those parts, not in the object itself
>>
>>54837509
I'm not asking to eliminate state change, I'm asking to CONTROL it. OOP claims to do this (as a significant part of controlling complexity), but it doesn't. OOP is designed to write programs that have unchecked state mutation everywhere? Sounds pretty awful to me.

Haskell in particular (not FP in general, though) controls state change by eliminating it, yes. I much prefer that state change is allowed, but controlled through linearity.

>>54837537
Same outcome.
>>
>>54837533
you're just trying to redefine the term 'OOP', just accept what OOP could mean to someone who can think in shades other than black and white
>>
How the fuck do I functional algorithm
Like really, it pisses me off, got a 10/10 on my C++ exam, but a fucking 2/10 on my fucking functional algorithm exam, why the fuck do they need some fucking sentences in a fucking program

So who got a nice online lesson ?
>>
that's oddly satisfying


>inb4 "kek@memes" how dumb xDDD
>>
File: bananaman.jpg (232 KB, 1536x1158) Image search: [Google]
bananaman.jpg
232 KB, 1536x1158
>>54837487
>>54837508
Yep, I see you understand what you're doing. Congratulations, you passed the Python FizzBuzz trial, here's your Codemonkey diploma. No offence for the tripstuff, I hereby grant you pardon for this faux pas. (Yeah don't take it too seriously when you get called a mofo on 4chin, obviously. But you knew that, soo)
>>
>>54837537
>you use mutexes
>in those 'parts' not in the objects
OK? So you're telling me you're not doing OOP anymore. What you should be saying is that you should have a manager class which stores the state you need. How you're gonna pass messages in that structure starts getting tricky after a while but it can work.
>>
>>54837546
you are controlling the state for fuck's sake, that's what the setter methods are for, you set the state in a controlled manner and the object is designed to work properly no matter its current state
>>
>>54837568
see >>54837552

the mutexes are in the threaded OBJECTS

kill yourself
>>
>>54837572
Except when you throw threads into the mix, and you have to lock everything behind a mutex instead of ensuring that only one thing can ever mutate a given piece of state at a time. Or not do that, and keep it all in your head, which may work for personal projects but never for a team.
>>
>>54837564
>Terminator
>~/Desktop
>Bash
How new are you
>>
>>54837590
any non-trivial multithreaded program requires a mutex or memory barrier of some sort KILL YOURSELF RETARD
>>
>>54837599
I'm waiting.
>>
>>54837593
I hate LXTerminal, wanted to get rid of it. Personally I could give less of a fuck.
Is working on Desktop haram or something?
I have a zsh config, I'm just to lazy to change it. :^)
>>
>>54837606
fuck off and die smug tard
>>
>>54837590

It's a good thing that procedural programming has eliminated the need for mutexes when using threads.

oh, wait..
>>
>>54837614
I'm smug for asking you to substantiate your argument?

>>54837616
Never said it did. I said linear types do, which are usable in any "paradigm".
>>
>>54837552
>shades other than black and white
OK so you'd consider it functional programming if you do imperative stuff all over the place?
Why can't you accept that you don't follow a paradigm dogmatically?
Because if your program is at odds with the idea of OOP it's not an OOP program. It may have sections of the program which encapsulates the state properly and passes messages like a real OOP program. But just because you have that doesn't make the entire program OOP. It's just that one bit.
I have pure functions in almost any program I write. I'd never call my program written under a functional programming paradigm because my max(a, b) is a pure function. That'd be dumb. And if that's' redefining' a paradigm then maybe consider just how many different programming paradigms exist in a single program and if these labels would make any sense to use in that case.

If your break out of the FP scheme your language starts being an IP program.
If you break out of the OOP scheme your program stops being OOP.
>>
File: captainbanana.jpg (204 KB, 520x520) Image search: [Google]
captainbanana.jpg
204 KB, 520x520
>>54837616
Ok, so basically both of you are arguing something orthogonal to the issue of OOP versus non-OOP, right? Maybe either we move on to another topic, or one of you actually presents an argument which makes this relevant to the issue?
>>
>>54837564
needs bigger titlebar
>>
>>54837630
>if it's not 100.0% what i personally deem as "OOP" it's not OOP
literally black and white thinking

and you're doing the same as what you're accusing OOP of doing, you're trying to relabel everything as whatever is your favorite paradigm

kill yourself
>>
for i in range(1, 100):
if i%3 == 0 and i%5 == 0:
print("FizzBuzz")
elif i%3 == 0:
print("Fizz")
elif i%5 == 0:
print("Buzz")
else: print(i)
>>
>>54837656

I'm not here to actually argue the matter, all I said earlier was that OOP detractors are poopyheads.
>>
>>54837656
>the issue of OOP versus non-OOP
That isn't the issue. I'm saying OOP is useless, in isolation.
>>
>>54837678
>I'm saying OOP is useless, in isolation.

Sure, but only because multi-paradigm is GOAT.
>>
>>54837695
What I mean is that OOP is useless, and there's no practicality to having it included with other paradigm(s).
>>
>>54837630
Point to a 100% OOP program then, it'll be intersting. If you don't, that's OK, I'll just argue that OOP is a fuzzy dogma in which everyone picks what best suits them and the problem they have at hand, and that in fact it shouldn't be considered a thing by itself, but rather a blob. Or maybe we keep the secret?
>>
>>54837678
you're just talking shit

>>54837715
kill yourself
>>
>>54837723
Great arguments.
Thread replies: 255
Thread images: 26

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.