/dpt/ - Daily Programming Thread

Old thread What are you working on Sup Forums?

Other urls found in this thread:

pastebin.com/nhEctmAq
twitter.com/SFWRedditGifs

Rewriting the Linux kernel in Haskell

Second for D.

Kek

>xkcd
y tho

To get those (You)s

Who /JavaScript/ here?

if(op.image.isXKCD() == true)
{
reply("Thank you for posting XKCD pictures");
}

What a coincidence. I'm rewriting systemd in Haskell.

Hello Sup Forumsuys, 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: 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!

Why don't people use goto statements more often in C/C++?

>inb4 muh structured programming constructs

...

> == true
First year undergraduate?

if (some_condition) {
/* Do nothing */
}
else {
/* Whole code here */
}

How are you keeping warm this coming winter?
Remember to keep your hands warm while typing for optimal performance!

that kind of stuff is just off-putting and could easily backfire

Kekk

experienced (You) collector

Is this real?

it sure could
yes

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

Crossdressing is wrong. God does not like it.

Or a PhD teacher retard.

...

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

Nice bait, you're my favorite tripfag.

w2c

What's wrong with if(op

Just stop. Read a book. Watch anime.

Not in software engineering, I presume.

>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?

bruh your retarded. You dont need to compare it with true if its already a in an if.

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

anyone is free to support whoever he want

Lel. You've never even seen a PhD, matey.

You don't need those brackets aswell you fucking moron.

and anyone is free to think xkcd is shit

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 Sup Forums api, where can I find that/ what is it? sorry, still a noob.

>c plus plus
anyone is free to behave embarassingly and be wrong.

No, you're doing it wrong
if (op.image.isXKCD == false) {
/* Do nothing */
}
else {
reply("retarded user");
}

obv fucktard. im copying his syntax. Lel ur fkin stupid man

Yes. Java is better than C++ in every way.

aliexpress has cheap clothes of all kinds

>omitting curly braces
sure is summer

You guys would be surprised what kind of best practice shit some retards teach.


>falling for the bait

No they're not outdated.
No Java is not better.

>aliexpress has cheap clothes of all kinds
that's pretty vague

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

>C is totally outdated for >99% of applications
[citation needed]

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.

How do I give a fuck about programming?

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

desire to create a program desu

...

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.

> posting american computer manga

literally do not understand the problem with if(op

you are autistic

I guess none of those functions do escaping so it will be fucked by injection soon.

Be my rubber duck, Sup Forums.

When I start Neovim, the following is executed:
tnoremap :silent let b:should_insert=1h
tnoremap :silent let b:should_insert=1j
tnoremap :silent let b:should_insert=1k
tnoremap :silent let b:should_insert=1l
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 :silent let b:should_insert=0h
noremap :silent let b:should_insert=0j
noremap :silent let b:should_insert=0k
noremap :silent let b:should_insert=0l
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.

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

just search "arm warmers", i already found some cute ones for $1.20 each.

I want the specific ones in that pic.

>saw this
>went to explain xkcd to read the comments
>found one Sup Forums poster amidst all the intelligent discussion

thats litterally the same thing as wearing jackets

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.

int c = (1+3)/2;

:^)

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.

Has any of you any experience with Odoo ?

*can you write a function that averages two arbitrary ints

...

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 )

public static double avg(int a, int b){
return a/b;
}

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;
}

What? Have you ever worked with any DB API? That's exactly what the named binding prevents.

wtf is that. Just do return len(str).

C++ or C#?

...

clojurescript > *script

C

strlen = len

or if that's too simple.
def strlen(string):
index=0
while string[index]!='\0':
index++
return index

failed, u get rounding error

C# or C++?

Give me a failing test case.

My almonds are getting activated. Will Cmen ever recover?

For what purpose? C++ is superior for shitposting on Sup Forums, if that is what you were asking.

Shit performance. Why would you want an extra level of abstraction?

15,16.

For programming.
How is it superior for shitposting?

C#

>Bunch of superfluous input and error checks in the C but not ada
Would very easily count for the extra time

def strlen(s, l=0):
try:
s[l]
except (IndexError, ):
return l

return strlen(s, l + 1)

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

Why?

> while string[index]!='\0':
are you dumb

the answer is 15.5