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

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 315
Thread images: 28

File: im_so_random.png (40KB, 727x233px) Image search: [Google]
im_so_random.png
40KB, 727x233px
Old thread >>57642567

What are you working on /g/?
>>
Rewriting the Linux kernel in Haskell
>>
>>57649745
Second for D.
>>
>>57649768
Kek
>>
>>57649745
>xkcd
y tho
>>
>>57649793
To get those (You)s
>>
File: ads.jpg (145KB, 670x424px)
ads.jpg
145KB, 670x424px
Who /JavaScript/ here?
>>
>>57649745
if(op.image.isXKCD() == true)
{
reply("Thank you for posting XKCD pictures");
}
>>
>>57649768
What a coincidence. I'm rewriting systemd in Haskell.
>>
Hello /g/uys, I'm new to programming and started with python, as I've heard its a good babby language to start with. I've been working on a web scraper for 4 chan, and I think I've finally got it worked out pretty well. the only thing i'm still having trouble with is the options menu, to decide what the user would like to do. I have a functionally menu, but I have no try/catch set up, and i have trouble using a while loop to return to the specific part of the menu the user fucked up on. this is the relevant code:
    def menu(self):
while True:
cmd = input(
'1 for board surface, 2 for a specific thread, '
'and 3 for every thread on a board, or q to exit: ')
if cmd == 'q':
break
self.board = input(
'What board would you like to scrape?: ')
self.max_pages = int(input(
'How many pages would you like to scrape?: '))
if cmd == '1':
self.search_board()
elif cmd == '2':
self.search_thread()
elif cmd == '3':
self.deepsearch_thread()
else:
print('Invalid choice, try again.')


and the full script: http://pastebin.com/nhEctmAq

If anyone would , be willing to critique in general I would really appreciate it, and if anyone has any resources specific to creating user input menus that covers thorough try/catch that would be awesome. Cheers!
>>
>>57649835
Why don't people use goto statements more often in C/C++?

>inb4 muh structured programming constructs
>>
File: im_with_her.png (44KB, 740x633px) Image search: [Google]
im_with_her.png
44KB, 740x633px
>>
>>57649853
> == true
First year undergraduate?
>>
>>57649853
if (some_condition) {
/* Do nothing */
}
else {
/* Whole code here */
}
>>
File: 1479920929764.jpg (65KB, 570x796px) Image search: [Google]
1479920929764.jpg
65KB, 570x796px
How are you keeping warm this coming winter?
Remember to keep your hands warm while typing for optimal performance!
>>
>>57649876
that kind of stuff is just off-putting and could easily backfire
>>
>>57649887
Kekk
>>
>>57649887
experienced (You) collector
>>
>>57649876
Is this real?
>>
>>57649909
it sure could
>>57649918
yes
>>
>>57649864
>I have no try/catch set up, and i have trouble using a while loop to return to the specific part of the menu the user fucked up on.
If I were writing it, I'd break it up each input "step" into its own function. Don't try to do it in all one loop. Each function can do error-handling in a nice, contained context.

Also, (assuming you're using python 2) use raw_input not input. input evaluates whatever you're inputting which can lead to unwanted/unsafe behavior.
>>
>>57649908

Crossdressing is wrong. God does not like it.
>>
>>57649887
Or a PhD teacher retard.
>>
>>57649908
>>
>>57649853
>if(op
> == true
Just stop forever, man, you're an eyesore and a general embarrassment. Maybe you should watch some anime so your peanut brain can attempt to retain some form of information.
>>
>>57649933
Nice bait, you're my favorite tripfag.
>>
>>57649908
w2c
>>
>>57649944
What's wrong with
if(op
>>
>>57649957
Just stop. Read a book. Watch anime.
>>
>>57649934
Not in software engineering, I presume.
>>
>>57649908
>How are you keeping warm this coming winter?
I turn up my thermostat and pay my gas bill because I am not a poorfag.
>>
Hey guys, I heard C/C plus plus was too outdated. Is java better?
>>
>>57649853
bruh your retarded. You dont need to compare it with true if its already a in an if.

if(op.image.isXKCD){
reply("retarded anon");
}

>>
>>57649876
anyone is free to support whoever he want
>>
>>57649934
Lel. You've never even seen a PhD, matey.
>>
>>57649987
You don't need those brackets aswell you fucking moron.
>>
>>57649990
and anyone is free to think xkcd is shit
>>
>>57649931
okay awesome, I'll try that. thanks. It's python 3, so I'm good to go for input(), but I'll keep it in mind. Also to you or anyone else, someone else suggested I use the official /g/ api, where can I find that/ what is it? sorry, still a noob.
>>
>>57649978
>c plus plus
>>57649990
anyone is free to behave embarassingly and be wrong.
>>
>>57649987
No, you're doing it wrong
if (op.image.isXKCD == false) {
/* Do nothing */
}
else {
reply("retarded anon");
}
>>
File: 1438314435385.png (179KB, 405x406px) Image search: [Google]
1438314435385.png
179KB, 405x406px
>>57650001
obv fucktard. im copying his syntax. Lel ur fkin stupid man
>>
>>57649978
Yes. Java is better than C++ in every way.
>>
>>57649956
aliexpress has cheap clothes of all kinds
>>
>>57650001
>omitting curly braces
sure is summer
>>
>>57649997
>>57649968
You guys would be surprised what kind of best practice shit some retards teach.


>falling for the bait
>>
>>57649978
No they're not outdated.
No Java is not better.
>>
>>57650023
>aliexpress has cheap clothes of all kinds
that's pretty vague
>>
>>57649978
java is an amazing language

C++ is good but takes more effort than java, and is only worth it if you need every last drop of performance for computer games and such

C is totally outdated for >99% of applications
>>
>>57650042
>C is totally outdated for >99% of applications
[citation needed]
>>
>>57650010
if not False != isXKCD(op.image):
pass
else if isXKCD(op.image) == True:
reply("thank you for supporting xkcd!")
else:
#This should not happen! XD
reply("lol ur dum")
>>
What's wrong with Tcl/Tk?

Why isn't it more widespread?

I remember aMSN as being a really good and quickly evolving piece of demosoftware.
>>
>>57649745
How do I give a fuck about programming?
>>
>>57650063
wear women's clothing
>>
I finally figured out how to add 2 positive integers together guys.
int add(int a, int b){
int temp2 = a | b;
int temp = a & b;
temp2 &= (temp^INT_MAX);
temp <<= 1;
while (temp & (a^b)){
temp2 &= (temp^INT_MAX);
temp &= (a^b);
temp <<= 1;
}
return temp | temp2;
}
>>
>>57650063
desire to create a program desu
>>
File: 1476309954105.png (483KB, 600x894px) Image search: [Google]
1476309954105.png
483KB, 600x894px
>>57650042
>>
>>57650061
Tcl is pretty nice actually.

It's not C-like enough to be appreciated here.
>>
$has_rows = (bool) db_query_range('SELECT 1 FROM {users} WHERE name = :name', 0, 1, array(":name" => $name))->fetchField();

This line is used in a bunch of places in my work's website codebase to see if a user exists.
>>
>>57649745

> posting american computer manga
>>
>>57649944
literally do not understand the problem with if(op

you are autistic
>>
>>57650098
I guess none of those functions do escaping so it will be fucked by injection soon.
>>
Be my rubber duck, /g/.

When I start Neovim, the following is executed:
tnoremap <A-h> <C-\><C-n>:silent let b:should_insert=1<CR><C-w>h
tnoremap <A-j> <C-\><C-n>:silent let b:should_insert=1<CR><C-w>j
tnoremap <A-k> <C-\><C-n>:silent let b:should_insert=1<CR><C-w>k
tnoremap <A-l> <C-\><C-n>:silent let b:should_insert=1<CR><C-w>l

This lets me leave a terminal window while being in insert mode. When I do so, b:should_insert is set to 1.

I have created an autocommand for the TermOpen event. This autocommand just calls the following function.
function! OnTermOpen()
noremap <buffer> <A-h> :silent let b:should_insert=0<CR><C-w>h
noremap <buffer> <A-j> :silent let b:should_insert=0<CR><C-w>j
noremap <buffer> <A-k> :silent let b:should_insert=0<CR><C-w>k
noremap <buffer> <A-l> :silent let b:should_insert=0<CR><C-w>l
endfunction

This enables me to leave a terminal window with alt+hjkl while in normal mode. When I do so, the variable b:should_insert is set to 0.

Now I have an autocommand for the BufEnter event on terminal files which does this.
if !exists("b:should_insert") || b:should_insert == 1
startinsert
endif


So far everything seems to make sense. Then, why would entering a new buffer opened by Denite make me go in insert mode? This doesn't make sense. The BufEnter term://* event shouldn't be called on buffers that do not contain a terminal.
>>
>>57650087
That's okay and all. But can you average two ints?
>>
Is they a better way to avoid a "Segmentation fault (core dumped)" for an empty vector?
So far this is how I'm doing it
class MyVec{
vector<long double> vec;
long double _minimum;
public:
Myvec() : vec{0}, _minimum(0){}


long double minimum(){
long double min = vec[0];
for(auto i = begin(vec); i != end(vec); ++i){
if(min > *i){
min = *i;
}
}
return _minimum = min;
}
};

int main(){
MyVec obj;
cout << obj << endl;
cout << obj.minimum() << endl;
return 0;
}
>>
>>57650037
just search "arm warmers", i already found some cute ones for $1.20 each.
>>
>>57650143
I want the specific ones in that pic.
>>
File: IMG_20161123_185516.jpg (187KB, 720x1026px) Image search: [Google]
IMG_20161123_185516.jpg
187KB, 720x1026px
>>57649876
>saw this
>went to explain xkcd to read the comments
>found one 4chan poster amidst all the intelligent discussion
>>
File: 6a0.jpg (23KB, 600x567px) Image search: [Google]
6a0.jpg
23KB, 600x567px
>>57650143
thats litterally the same thing as wearing jackets
>>
>>57650118
It's part of Drupal's PDO wrapper so no, that's not what's wrong with it.
>>
C++ Programming challenge

 
class Foo
{
public:

static void (Foo::*bar)();
};
 

Figure out how to assign and call bar.
>>
>>57650136
int c = (1+3)/2;

:^)
>>
>>57650161
jackets don't go up to your hands
gloves simply prevent you from typing
this is the best of both worlds
also, there's nothing stopping you from wearing a jacket and some arm warmers to keep your wrists warm.
>>
File: hmmm.jpg (21KB, 393x360px) Image search: [Google]
hmmm.jpg
21KB, 393x360px
Has any of you any experience with Odoo ?
>>
>>57650184
*can you write a function that averages two arbitrary ints
>>
>>57649835
TypeScript > JavaScript
>>
New to Python, trying to write a function to get the length of a string
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 )
>>
File: 1452234790855.jpg (8KB, 250x244px) Image search: [Google]
1452234790855.jpg
8KB, 250x244px
>>57650217
public static double avg(int a, int b){
return a/b;
}
>>
>>57650217
That one's old
int 
avg(int a, int b)
{
if ((a < 0) == (b < 0))
{
return a/2 + b/2 + (a%2 + b%2)/2;
}
return (a+b)/2;
}
>>
>>57650118
What? Have you ever worked with any DB API? That's exactly what the named binding prevents.
>>
>>57650250
wtf is that. Just do return len(str).
>>
C++ or C#?
>>
>>57650087
>>
>>57649835
>>57650249
clojurescript > *script
>>
>>57650277
C
>>
>>57650250
strlen = len

or if that's too simple.
def strlen(string):
index=0
while string[index]!='\0':
index++
return index
>>
>>57650262
failed, u get rounding error
>>
>>57650286
C# or C++?
>>
>>57650290
Give me a failing test case.
>>
>>57650281

My almonds are getting activated. Will Cmen ever recover?
>>
>>57650277
For what purpose? C++ is superior for shitposting on /g/, if that is what you were asking.

>>57650284
Shit performance. Why would you want an extra level of abstraction?
>>
>>57650300
15,16.
>>
>>57650326
For programming.
How is it superior for shitposting?
>>
>>57650298
C#
>>
>>57650281
>Bunch of superfluous input and error checks in the C but not ada
Would very easily count for the extra time
>>
>>57650250
def strlen(s, l=0):
try:
s[l]
except (IndexError, ):
return l

return strlen(s, l + 1)
>>
>>57650328
Um
15/2 = 7
16/2 = 8
15%2 = 1
16%2 = 0
(1+0)/2 = 0
Ans = 7+8+0 = 15

That's literally the expected answer
>>
>>57650334
Why?
>>
>>57650287
>
    while string[index]!='\0':

are you dumb
>>
>>57650348
the answer is 15.5
>>
>>57650136
double average(int a, int b){
int temp2 = a | b;
int temp = a & b;
temp2 &= (temp^INT_MAX);
temp <<= 1;
while (temp & (a^b)){
temp2 &= (temp^INT_MAX);
temp &= (a^b);
temp <<= 1;
}
if (((temp | temp2) & 1) == 0){ //If there isn't a 1 in the least significant bit, no rounding error
return double((temp | temp2) >> 1);
}
else{ //Rounding error
return double(temp | temp2) / 2; //Don't know how to get past the odd case without using an arithmetic operator.
}
}
>>
>>57650337
They're there implicitly
>>
>>57650136
avg(int a, int b) ??
>>
>>57650359
Ah, I thought you were talking about integer mean. You can just cast to double then and take average, what's the big deal?
>>
>>57650281
>ada
kek. the very definition of the over engineered programming language.
>>
>>57650371
its not a big deal. I just said it was a rounding error, thats all.
>>
What is the best programming language?
I use JS, is it good? Can you use it for everything? I'm a beginner :/
>>
>>57650388
racket
>>
>>57650388
It's good for you to learn and you can do lot of shit with it. You will know it in time whether it's ideal for the job at hand.
>>
C# or C++ guys?
>>
>>57650398
are all languages similar?
>>
>>57650250
What >>57650273 said, just use len(str).
>>
>>57650410
Are you the retard from yesterday?
>>
>>57650339
strlen('1'*10000000)

Try that.

>>57650355
Been a while since I did Python. Does Python not have a null character?
>>
>tfw too shit at writing CV to get an interview
kind of hard to fix when you dont know what you're doing wrong
>>
Are any of you people into competitive programming?
>>
>>57650410
I've yet to see a legitimate reason to use C# over C++
>>
>>57650331
>For programming.
How specific.

The only thing you can use C# for is MS and Java shitposting. C++ has a much bigger memebase than that.
>>
>>57650427
Kek I also remember him.
>>
>>57650438
no thats gay
>>
>>57650432
>Does Python not have a null character?
Yes, it's called None.
>>
>>57650456
no its not

>>57650462
>null character
>None
kill you'reself
>>
>>57650427
Nope.
>>57650443
>>57650453
So is it just a language to build shitposting programs?
>>
>>57650438
yes, i often compete on codingame where i am renowned as a master.

https://www.codingame.com/multiplayer/clashofcode
>>
>>57650443
better standard library
better tools
faster dev time
build and dependency management isn't a nightmare inducing experience

as for cons:
performance is way worse than C++
C# for linux is still wonky at best, outright broken at worst
>>
>>57650410
C++ or java
>>
>>57650475
Then you are some other reatard. Use the right tool for the right job. You have yet to explain what job you have in mind.
>>
File: 1455334261237.png (221KB, 1000x668px) Image search: [Google]
1455334261237.png
221KB, 1000x668px
>>57650472
>competitive programming
>>
>>57650379
Seems it was engineered just enough, anon
>>
>>57650432
>Try that.
obviously it's gonna choke but at least the method is implemented using recursion as the original method was meant to be

>>57650432
>Been a while since I did Python. Does Python not have a null character?
you can use null bytes/characters within strings but the strings are not null terminated (at least not on the abstraction level), don't know about the internal representation
>>
>>57650487
That looks like a nice website. Thanks anon.
Also do you have any tips/resources so I can go from being on the low-end of mediocre to high-end of mediocre?
>>
Working on my terminal emulator, day two of porting to macOS.

Progress is being made, sad realization that Cairo surface resizing is only supported on X11, must redesign some shit.
>>
>>57650438
I participated in a google code jam once, though I only realized it was going on when there was like 5 hours left of it. Still managed to complete almost 3 of the tasks, so I could probably have done all 4 quite easy if I'd known when it started.

But stuff like that, codewars, codeeval, etc. all feels so "artificial", like you're just writing code to solve this one problem that's never gonna occur in a real program and then once you've submitted the code practically just gets thrown away. The only part of it I really find enjoyable is trying to make the absolute cleanest solution by spending autistic amounts of time solving a simple problem, but at that point it's not really "competitive".
>>
>>57650492
Idk man.
>>57650499
Building an anime AI.
>>
>>57650500
I bet you can't even implement elementary operations on a BST and still call yourself a programmer.

>>57650537
That's nice. Yeah, to each his own. I really enjoy competitive programming, especially the thrill of getting ACCEPTED after hours of spending time to debug/improve the solution, or even coming up with a solution in the first place.
>>
>>57650552
C++. You are likely to run into performance limitations otherwise, when computing the best possible actions in real time.
>>
File: 1454053427572.jpg (48KB, 330x319px) Image search: [Google]
1454053427572.jpg
48KB, 330x319px
>>57650564
baby just took his first data structures class. Lel
>>
>>57650574
>>57650552
If you care about performance at all, use C or C++. Also, check to see if it compiles with -Ofast, and see what the problem is if it doesn't work (Ofast breaks standards, but I haven't ran into problems yet)
>>
Assuming my computer has all of the instruction sets (AMD FX 6300), is there any instruction that GCC isn't allowed to use/doesn't support when I compile with -march=native?
>>
>>5765057
>>57650615
Why even use C# then? Why does it even exist if it's a shitposting language?
>>
How do I improve this code?
data Struct a = EmptyShit
| Element Int a
deriving (Show, Eq)

data Tree a = Empty
| Node (Tree a) a (Tree a)
deriving (Show, Eq)

treeAppend :: Tree (Struct a) -> (Struct a) -> Tree (Struct a)
treeAppend (Empty) e = Node (Empty) e (Empty)
treeAppend tree (EmptyShit) = tree
treeAppend (Node l (Element rn dn) r) (Element rd dd)
| rd < rn = Node (treeAppend l (Element rd dd)) (Element rn dn) r
| otherwise = Node l (Element rn dn) (treeAppend r (Element rd dd))

It works, but looks like shit
>>
>>57650668
C# works as well, but i'm just more comfortable with C++
>>
>>57650674
What language is that?
>>
>>57650674
Rewrite it in a non-meme lnaguage
>>
>>57650615
-Ofast is just -O3 with -ffast-math, should be fine it you don't have strict requirements on float arithmetic (like if you have a certain order of operations to maximize accuracy) and you don't rely on infinity/nan
>>
>>57650687
It's Haskell masterrace.
>>57650689
Btw, I expected that response. And as response I must say "coding isn't the same as programming"
>>
>>57649745
Which is more efficient?
[{ "order": 1, "name": "Top News", "feed": "news.google.com/news?topic=h&output=rss" },
{ "order": 2, "name": "World", "feed": "news.google.com/news?topic=w&output=rss" }]


Order property inside a dict inside an array? What did they mean by this?
>>
>>57650687
That's Haskell aka the language that no one uses.
>>
>>57650674
What's the purpose of Struct? Why is it separate from Tree?
>>
>>57650723
what are you? front end developer?
>but muh html and css skillz
>>
>>57650723
Haskell has its uses. Easily the best language to shitpost with. C++ does not even come near.
>>
>>57650729
Not real purpose. The book said "make a tree of integers" and I did a tree of integers plus additional data. Think of it like a dict that can be searched fast
>>
>>57649944
easier readability, even if it's redundant to add the == true
>>
>>57650747
OK, and why are you allowing for EmptyShit? It seems weird since you already have Empty defined.
>>
File: yes.png (313KB, 1548x620px) Image search: [Google]
yes.png
313KB, 1548x620px
>>57650734
It's a niche toy language used exclusively for academic masturbation.
>>
>>57650765
Now that you say it, it's true, I don't need to handle that empty structure.
On the other hand I'm more interested about the function to append elements to the tree.
>>
>>57650766
>all those gay languages
shithub users are such numale faggots
>>
>>57650738
How exactly does one shitpost with a language?
>>
>>57650804
One way you can clean up treeAppend is by using as-patterns
treeAppend (Node l root@(Element rn dn) r) new@(Element rd dd)
| rd < rn = Node (treeAppend l new) root r
| otherwise = Node l root (treeAppend r new)

This way, you don't have to repeat (Element ...) over and over again
>>
File: 1474757199103.jpg (116KB, 1280x720px)
1474757199103.jpg
116KB, 1280x720px
>>57650766
>Perl has more active repositories than swift
>>
>>57650766
>exclusively for academic masturbation.
https://code.facebook.com/posts/745068642270222/fighting-spam-with-haskell/
>>
>>57650832
Imply it is somehow better than all other languages combined and parade the 2-3 useful features, while ignoring the 99 thousand problems it has.
>>
>>57650846
That data is from 2014, Swift is probably now a bit higher, and Haskell is likely to be surpassed by Clojure and Rust now.
>>
anyone has a /dpt/ discord invite for me, please?
>>
>>57650866
post dick and I'll decide whether you're worthy
>>
>>57650022
Go fuck yourself
>>
>>57650866
*unzips pants*
here we go
>>
>>57650866
literally nobody posts there
>>
>>57650875
I don't have one ;_;
>>
>>57650889
I post there. But I'm kind of a nobody..
>>
>>57650866
Registrations are now closed.
>>
hey, can anyone tell me why this isn't working?
in the combo box there is just one input of random letters and numbers

        private int[] days = new int[31];
private int[] months = new int[12];
private int[] years = new int[100];

public void calender() {
for (int i = 0; i < 31; i++){
days[i] = i;
}
for (int i = 0; i < 12; i++){
months[i] = i;
}
for (int i = 0; i < 100; i++){
years[i] = i;
}
}


contentPane.add( new JLabel( " Enter Date Of Birth" ) );
dob = new JPanel(new GridLayout(1,3));
dob.setBackground(new Color(174,185,189));
contentPane.add( dob );
JComboBox dayBox = new JComboBox( );
dayBox.setFont(new Font("Ariel", Font.PLAIN, 16));
dayBox.addItem(days);
JComboBox monthBox = new JComboBox( );
monthBox.setFont(new Font("Ariel", Font.PLAIN, 16));
monthBox.addItem(months);
JComboBox yearBox = new JComboBox( );
yearBox.setFont(new Font("Ariel", Font.PLAIN, 16));
yearBox.addItem(years);
dob.add(dayBox);
dob.add(monthBox);
dob.add(yearBox);

>>
>>57650674

>>57650804
-- pattern Leaf e = Tree Empty e Empty
-- pattern synonyms
singleton e = Tree Empty e Empty

treeAppend :: Ord a => Tree a -> a -> Tree a
treeAppend Empty e = singleton e
treeAppend (Node l x r) e
| x < e = Node (l `treeAppend` e) x r
| x >= e = Node l x (r `treeAppend` e)

-- Struct a -> Maybe (Int, a)

treeAddMaybe t Nothing = t
treeAddMaybe t (Just e) = t `treeAppend` e
>>
>>57650388
Js is a fucked up thing
>>
>>57650698
That's only on GCC. Clang has -fno-signed-zeros -freciprocal-math -ffp-contract=fast -menable-unsafe-fp-math -menable-no-nans -menable-no-infs
>>
>>57650924
ive called calendar method in my main aswell
>>
>>57650866
discord is such a shitty forced meme
>>
>>57649745
Easy stuff. Using youtube-dl to create a desktop application for downloading youtube videos.
No fucking idea what to create.
>>
>>57650929
Also you get Ord for free, but the behaviour differs if the ints are equal, in which case it compares the second element (while before it would simply go into the right node)
>>
File: elliot-hackerman.jpg (146KB, 640x640px) Image search: [Google]
elliot-hackerman.jpg
146KB, 640x640px
Hello coders and programmers?

How to become hacker?

Thank

PS: >pic related
>>
daily programming discord
https://discord.gg/EQ72h

centipedes only!
>>
>>57650438
In my country's national team :P
>>
>>57650966
>>>/v/
>>
I finished reading Learn You a Haskell for Great Good!
The book wasn't as good as I was told. The basics were properly explained, but the more advanced stuff wasn't as consistent as the rest.
What struck me is the inconsistent function naming. Sometimes a function gets suffixed like fold|foldl|foldr|foldM and in some occasions it gets prefixed like getContents|hGetContents. There's also some legacy stuff floating around that snaps you in the ass.
I guess I'll be doing some basic exercises to get more used to the syntax and the standard library before starting a proper project. For my project, I need some way to store data persistently. Is there a good library for that (ideally something like SQLite)? An ORM would be nice, but is not required.
>>
>>57650978
Holy shit seriously? I'm trying for ACM ICPC this year, are you going there?
>>
>>57650933
gcc is basically the same except for -freciprocal-math

default is -ffp-contract=fast and -ffast-math sets -fno-math-errno, -funsafe-math-optimizations, -ffinite-math-only, -fno-rounding-math, -fno-signaling-nans and -fcx-limited-range
>>
>>57650999
actually -funsafe-math-optimizations sets -fno-signed-zeros, -fno-trapping-math, -fassociative-math and -freciprocal-math
>>
I'm trying to optimize a tight for loop by prefetching the data into the cache through __builtin_prefetch. How well does this work, and how can I go about prefetching large chunks of data sequentially (what it the fetched length so I can re-run it to get more data)?
>>
>>57650978
is this like that fake-ass esports crap?
sitting at your computer is not a competitive sport
>>
>>57650929

Whoops, Tree should be Node.

Oh, and then there's the much cleaner, and much more generic
treeAddMaybe = foldl treeAppend

if you understand it (it takes 2 args)

and you can do
type Struct a = Maybe (Int, a)

if you want
>>
Has anyone here read TAOCP end to end? I've been hearing about it quite a lot lately. Is it really worth it or just a meme book?
>>
File: triggered (1).jpg (16KB, 320x371px) Image search: [Google]
triggered (1).jpg
16KB, 320x371px
>>57651015
>>
>>57651020
it's a reference book, don't read it end-to-end. also, the math level required is quite high (sophomore at the very minimum)
>>
>>57651043
I have the required math level. But, is it worth it?
>>
>>57651062
does it worth it to read wikipedia end to end?
>>
File: 1479923936659.jpg (57KB, 604x453px) Image search: [Google]
1479923936659.jpg
57KB, 604x453px
>>57651015
cyka blyat
>>
File: example.jpg (305KB, 1363x768px) Image search: [Google]
example.jpg
305KB, 1363x768px
Can someone tell me the way to modify each line on a .csv file the way I want in Java ?
I've done a view of each line (wich represent different contacts).But I don't know how to modify that file so I can for example modify on a particular line, a particular field.
Here's how the file looks.
>>
>>57650841
that's cleaner, thanks
>>
>>57651071
holy fug
>>
>>57651084
Take a look at this http://opencsv.sourceforge.net/
I've used it in one of my projects before, works just fine.
>>
File: 1479928583439.png (30KB, 657x527px) Image search: [Google]
1479928583439.png
30KB, 657x527px
>company is forcing me to learn Perl
What the fuck is this shit. It's almost as bad as PHP.
>>
>>57650754
>easier readability
kek
>>
>>57651117
you better do it, because the other options are to quit your job or put a pair of bobs and make blowjobs
>>
What's a good way to learn Java I/O? Streams and the whole system of how it's meant to work is confusing.
For instance, I'm making a text based quiz, and i want to be able to save the state of the current round so it can be loaded when the user bootsit back up. I can't think of how i could do this with I/O. Any help?
>>
>>57651174
https://docs.oracle.com/javase/tutorial/essential/io/
>>
>>57650929
That code looks good. I guess I didn't went too far, just to learn how to make those abstractions. Thanks you.
>>
>>57650754
>easier readability
isTrue() == true

more readable than
isTrue()


I've discussed this with a large team of highly qualified software engineers and we've all come to the conclusion that your shit's all retarded and you a shit.
>>
>>57651117
Just be glad they didn't fire you and give your job to Pajeet who grew up on Perl
>>
>>57651084
why are those java and C# students so obsessed about "contact lists"? I mean, doesn't even exists other interesting data to use? what are you studing for? for secretary?
>>
>>57651222
I thought Pajeet was a designated Java SE programmer.
>>
>>57651284
No, that's what italians exists for
>>
>>57651242
It's the colleges that like like contact lists, and they are common in enterprise and webshit feilds that they like herding out masses of code monkeys into.
>>
>>57651113
Fuck, I wish I'd have asked earlier. Thanks m8.

>>57651242
Well it's not for the programing class. It's for the accounting one. The teacher is asking us to program a little shitty app, only god knows why, that allows you to modify and exported file from OpenERP (Odoo) and to import it if modified. It's a pure waste of time.
>>
>>57651304
>hey, where is the sales by date databases for machine learning algorithms?
>I don't know, but here I have a contact list, maybe we could merge them
>>
>>57651284
Indians are designated at a young age. Some are designated Java, others C#, and yet others Perl/PHP/Ruby/whatever
>>
>>57650098
>SELECT 1
kek
>>
What's the difference between '$' and '.' in Haskell?
>>
>>57651420
f $ x = f x
(f . g) x = f (g x)

basically they're completely different
>>
>>57651420
a . b creates a new function that takes some input, passes it to b, then passes the output to a

a $ some long shit here
is like writing
a (some long shit here)
>>
>>57651420
>>57651450
but they're similar in 1 situation:
f (g x)
you can avoid parentheses by using $
f $ g x
or you can compose
(f . g) x
or both, which is even longer than using parentheses
f . g $ x

if you've got something like
f (g (h (m (n x))))
(f . g . h . m . n) x
f . g . h . m $ x
f $ (g . h . m) x
f . g $ h . m $ x
f $ g (h (m $ n x)))
etc
>>
>>57651477
whoops, there should be an n in some of those examples, but you get the point

$ is mostly used to alter precedence
f $ x + 3 = f (x + 3)
f x + 3 = (f x) + 3

if you're working with do blocks this is really useful

forever $ do
.. some really long block of code ..

much nicer than

forever (do
.. some really long block of code ..
)
>>
>>57651508
also there's a proposal called ArgumentDo that removes the need for $ before do blocks, so you could just

forever do { ... }

apparently for some reason it's not got very far
>>
>>57649745
Fucking fedora ass faggot! Fuck off back to the Redpill subreddits!
>>
>>57651475
So
a $ b = a(b)
and
 (a . b)(c) = (a(b(c))) 
?
>>
>>57651588
Yeah, although the second example would typically be written
a . b $ c
>>
https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=637
How many of you follow secure coding standards?
>>
Does anybody here have a copy of Physically Based Rendering 3rd ed? Is there a better book for learning about ray tracing?
>>
>>57651618
> https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=146440565

I guess it's impossible to average two integers in C++
>>
File: unfakeable.jpg (30KB, 512x473px) Image search: [Google]
unfakeable.jpg
30KB, 512x473px
Thinking of learning Ruby.
Thoughts?
>>
>>57651707
Don't
>>
>>57651707
See >>57651792
>>
If linux is so free, why redhat costs money?
>>
>>57651674
int a = rand();
int b = rand();

int average = a>>1 + b>>1 + (a&b&1);

prove me wrong
>>
>>57651832
because redhat corp is free to charge for their version
>>
>>57651845
>those red lines crossing it out
Even 4chan knows it's wrong
>>
>>57651832
Think free as in free speech, not free beer.
>>
>>57651707
see >>57651798
>>
I just finished this. Given an array of positive integers, going from left to right, find the maximum sum of these integers. If you choose one integer, you can't choose the one immediately after it. You can skip more than one block in a row.

So this returns that maximum sum in O(n).

public static int maxGain(int [] blocks)
{
// Create an array to use
int [] array = new int[blocks.length + 1];

// Set the first element to 0, then fill the rest of the new array with the blocks given, in reverse order
array[0] = 0;
for(int i = 1; i <= blocks.length; i++)
{
array[i] = blocks[blocks.length - i];
}

// For loop: sets the array[i] to the maximum of either array[i-2]+array[i] or array[i-1]
for(int i = 2; i <= blocks.length; i++)
{
array[i] = Math.max((array[i-2] + array[i]), (array[i-1]));
}

// Returns the last element in the array, which is the solution
return array[blocks.length];
}
>>
>>57651832
CentOS, you fucking poorfag
>>
>>57651832
because big companies feel uncomfortable when their software comes with NO WARRANTY and no avenue to sue anyone if the software fucks up and costs them money.

redhat fills this gap nicely by charging you money and giving you support and consultancy services just like microsoft or IBM do
>>
>>57651792
>>57651798
>>57651864
Why?
>>
How do I delete an entry from an ArrayList in Java?
I want to not only delete the value, but remove it completely from the list, so that the list is 1 value shorter.

// I'm using an ArrayList
ArrayList<Integer> particle = new ArrayList<Integer>();

// Some code is here

// I get a value of 10
System.out.println(particle.size());

// I want to fully remove the third entry
particle.remove(3);

// I also get a value of 10
System.out.println(particle.size());

// This doesn't help
particle.trimToSize();
// I still get a value of 10
System.out.println(particle.size());
>>
>>57651887
It's shit
>>
>>57651845
Right shift for negative integers may not give you the result that you want. It's implementation dependent.
Your program is literally undefined behaviour.
>>
>>57651908
>>57651887
He's right it is.
>>
>>57651931
int average = a/2 + b/2 + (a&b&1);

Happy?
>>
>>57651963
Won't work for -3 and -3 :^)
>>
>>57651901
What happens if you do particle.remove((int) 3);
>>
File: 445.png (71KB, 400x400px) Image search: [Google]
445.png
71KB, 400x400px
>>57651908
>>57651935
But why?
>>
>>57651875
Nice. What will happen if we allow negative integers?
>>
File: computerstate.jpg (77KB, 1920x1080px) Image search: [Google]
computerstate.jpg
77KB, 1920x1080px
>>57651931
>implementation dependent.
>undefined behavior.
pick one

>>57651674
int average (const int x, const int y) 
{
if ((x < 0) ^ (y < 0))
return (x + y) / 2;
const int xh = x / 2;
const int yh = y / 2;
const int xhr = x % 2;
const int yhr = y % 2;
return xh + yh + (xhr & yhr);
}
>>
>>57652011
It's dynamically typed. Which makes it automatically garbage.
>>
>>57652021
I meant that different implementations can choose to implement it however they want. So that's why in the standard, it's undefined behaviour.
>>
>>57650437
show CV, lets do a peer review
>>
>>57652021
So if x = -3, y = -3
It won't pass the first if condition, so
xh = -1
yh = -1
xhr = -1
yhr = -1
return -1 + -1 + (-1 & -1) = -2 + 1 = -1
Answer should be -3
0/10
>>
>>57652023
Which do you recommend me to learn instead?
>>
>>57652042
wrong. the standard itself makes a difference between implemented defined behaviors(J.3) and undefined behaviors(J.2).
>>
>>57652021
>>57651963
>>57651845
Ada doesn't have this problem
>>
>>57652088
Oh ok, thanks.
>>
>>57651994
Unfortunately nothing

I've made a crappy work around
currentParticleCount -= value;

So I don't need particle.size() anymore

I feel dirty, but oh well, i've spent enough time on this.

Thanks for the help
>>
>>57652097
If an Ada compiler can be written in C than C can do it too
>>
>>57652085
depends. What do you know? What do you want to do?
>>
>>57652085
C, C++, Go.
>>
>>57652020
It would probably still work the same, since it takes the max of two integers. But I'd have to test it out to make sure.
>>
>>57652085
Haskell
>>
>>57651875
>>57652020
>dynamic programming
Pretty cool; a month ago I wouldn't have known how to solve that in O(n).
>>
>>57652112
It can, have fun not averaging two ints in just two lines.
>>
>>57652129
I think that if
arr[i] < 0
then we should take the max of
Max(arr[i-2], arr[i-1]). Thoughts?
>>
>>57650052
>if False !=
everything about this makes me want to shoot myself
>>
>>57652085
This guy can't stop being right >>57652139
>>
int average = (int) ((double) (a+b) / ((double) 2)) 

Literally just try to prove me wrong
>>
I'm an idiot learning Python. My tutorial wants me to make a function taking a tuple, as in:
def f( (x, y) ):

Python3 is upset by this, but Python2 is fine.

I know I probably shouldn't care, but I've looked and can't even find any mention that tuple behaviour changed. Is there an actual reason this doesn't work?
>>
If linux is so well made, why are there kernel panics?
>>
>>57652200
You can't be sure that double contains all int.
>>
>>57652160
Sounds about right. Until the negative ends up in the arr[i-2] position, then you'd have to take the max of arr[i] and arr[i-1].
>>
>>57652232
You're holding it wrong
>>
>>57652200
The C standard literally doesn't say anywhere that double contains strictly more bits than int, and that too enough to contain the overflow.
>>
>>57652074
(-1 & -1) evaluates to -1
>>
>>57652237
>>57652260
int average = (int) ((__float128) (a+b) / ((__float128) 2)) 
>>
>>57652112
Not true
>>
>>57652299
Have fun wasting all your CPU clock cycles with those expensive operations.

>>57652284
Ah yes, my bad. I'm so used to using & for just extracting a single bit that I forgot it would take the and of all the bits.
>>
>>57652299
>__float128
It's not a requirement in the standard. It's just a GCC extension.
>>
>>57652345
>implying neets on a Keynesian cereal appreciation hotel will ever neet to change their compilers from gcc to something else
>>
File: sorandom.png (82KB, 727x233px) Image search: [Google]
sorandom.png
82KB, 727x233px
>>
>>57652368
>Keynesian cereal appreciation hotel
I just registered to say:

Neat.
>>
>>57652378
>fedora
sums up xkcd
>>
>>57652435
That's a trilby you fucking moron.
>>
>>57652299
You can't be sure that __float128 contains all ints.
>>
int average(int a,int b) {
return (((long) a) + b) / 2;
}


This is the only sane answer.
>>
>>57652459
See this >>57652237 >>57652260
Replace double with long
>>
>>57652456
>that's not a fedora that's a shiny fedora
t. fedora
>>
File: 1477096319695.jpg (17KB, 320x320px) Image search: [Google]
1477096319695.jpg
17KB, 320x320px
>>57652459
Pleb.
int average(int a, int b) {
return (a >> 1) + (b >> 1);
}
>>
>>57652489
(5, 3)

NEXT
>>
>>57651707
It's fine. No shittier than Python or Perl.
>>
>>57652489
>average of 3 and 3 is 2
anon, I...
>>
I know C and Java. What should I learn next?
>>
File: 1473620059103.png (209KB, 453x435px) Image search: [Google]
1473620059103.png
209KB, 453x435px
>>57652515
>>57652525
Looks fine to me. If you wanted precision, you should have used reals.
>>
>>57652530
Master C and Java
>>
>>57652471
int average(int a,int b)
{
_Static_assert(sizeof(long) > sizeof(int), "Size of long equals size of int");
return (((long) a) + b) / 2;
}
>>
>>57652538
> Average of 1 and 1 is 0
> 1 = 0
> precision
> should have used reals
>>
It jst werks.
(defun average (a b)
"Return the average of A and B."
(/ (+ a b) 2))
>>
>>57652546
Your code literally admits defeat that it won't work in all cases. How do you feel anon?
>>
>>57652554
It's always within 2+ or 2- of the answer. Not everyone needs autist precision.
>>
>>57652116
>What do you know?
I don't know shit tbqh.
>What do you want to do?
Web applications.
>>
>>57652576
>Measuring precision in absolute terms
> 0 vs 1
> Literally infinite error
>>
I have a function that returns a long double, but I'm getting a warning "floating constant exceeds rang of 'double'" when I input "1.18973e+4932" I know I can us a suffix "1.18973e+4932L" but I want to avoid using the suffix.
>>
>>57652571
it does check an implementation defined behavior which is what the standard asks for the code being considered standard proof.
>>
>>57652626
If that makes you feel better :^)
>>
If we're gonna be paranoid about maxint, how about we be paranoid in a language where it's pointless?
avg :: Num t => t -> t -> t
avg a b
| a >= b = a-((a-b)/2)
| otherwise = avg b a
>>
>>57652589
learn C# and javascript
>>
>casting to floating point
>c is a mistale
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Command_Line; use Ada.Command_Line;

procedure Average is
type Decimanl is delta 0.5 range Float(Integer'First)..Float(Integer'Last) with Small=>0.5;
A : Integer := Integer'Value(Argument(1));
B : Integer := Integer'Value(Argument(2));
C : Integer;
begin
C := Integer(Decimanl(A)/2 + Decimanl(B)/2);
Put_Line(Integer'Image(C));
end Average;
>>
NEW THREAD >>57652635
NEW THREAD >>57652635
NEW THREAD >>57652635
NEW THREAD >>57652635
>>
>>57652644
oh wait shit I forgot about the negative case.
avg :: Num t => t -> t -> t
avg a b
| (abs a) >= (abs b) = a-((a-b)/2)
| otherwise = avg b a
>>
>>57649660
>left-pad
http://www.haneycodes.net/npm-left-pad-have-we-forgotten-how-to-program/
No I had not. This reinforces my belief that people who don't write libraries themselves arent real programmers. Because this is not JS exclusive. Maybe the extreme case is but you find that for string processing in C++ people actually use the C++ standard library despite its many flaws rather than writing the very very basic thing you actually need.

Same with <algorithm> and plenty of other junk. Sure, it's fine if you're just doing something quick where you don't really care too much about the outcome but this sneaks in into production code.

You find that development leads at respectable companies have to ban its use. This is a real fucking issue. They really have forgotten how to program.
>>
>>57653772
>C++ standard library despite its many flaws
>respectable companies have to ban its use
Why?
>>
>>57650001

>not using curly braces every chance you get
>not knowing the scope of your variables

kek
Thread posts: 315
Thread images: 28


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.