/dpt/ - Daily Programming thread

Python edition

What are you working on, /dpt/?

node *previous =

Attached: snek.gif (400x480, 124K)

Other urls found in this thread:

en.cppreference.com/w/
cplusplus.com/reference/
en.cppreference.com/w/
twitter.com/AnonBabble

C++ is the best!

Attached: sakura_nene.jpg (1280x720, 111K)

What resources are there for someone whose gotten into coding recently? What foundational knowledge will I need? (e.g. Data Structures & Algorithms)

Should I stick with Python? And what's the difference between the variants of C?

What do you mean variants?

C / C# / C++

These are separate languages. C++ started as "C with classes" but rapidly diverged into its own thing entirely. C# is a Java clone more than having anything to do with C.

Honestly, I love python, but learn C first if you're sure you're motivated to learn programming.

There is a strong case for learning C as your first language because it teaches you a memory model (a memory model that doesn't map 1-to-1 to the hardware, mind you) that you have to be aware of and work around. This makes your understanding of fundamental computer science concepts stronger. Think of it like learning to drive manual transmission before you drive an automatic. You're going to understand a lot more about your engine and the various gears if you learn to drive manual first, right?

However, if you have trouble with motivation and finishing things, learn Python first. Because it's very easy to build cool stuff with python and quickly, which will keep you engaged and wanting to learn more.

how to into "data driven" programming/design in sepples
it seems like a good idea but the tedium of writing that much serialization code triggers the fuck outta me
did recently learn about x-macros though, is that actually the way to go?
the FUD around macros doesn't actually scare me

Sorry if this post is long but I need to sort my thoughts and some advice.
I am currently an intern at a place with clinical equipment. I got asked to write some code that reads data from said equipment's serial port and generates a CSV or Excel file of the data.
My issue is that someone on contract with the company asked me to share the code I've been writing with him. He's writing a hospital management system and needs it for the lab section.
Sorry if this sounds like a trivial issue but I don't see how I'm going to benefit since I'm not being offered anything in return and he's technically not a direct employee of the company I work for. Maybe I could give him the code I started with which is pretty much the basis of everything and let him figure it out?
I told my fellow intern and he mentioned open source but I still feel like this is most definitely not the same thing.

Serialization code isn't hard to write, it's just simple boilerplate
Use generic data formats like JSON, parse it into maps/arrays and then assign your data from there
Too bad C++ doesn't have reflection capabilities

>Serialization code isn't hard to write, it's just simple boilerplate
do you know what the word "tedium" means
>Too bad C++ doesn't have reflection capabilities
genuinely seriously considering working on (source) code generation tools to get around that
fuck the committee
be faster you cunts

why is python 3 so bad?
print is one of the most used statements so why not to boost productivity by requiring to write two additional chars every damn time

Attached: 1479742979992.jpg (427x356, 22K)

How do you write indices in python?
For example this:
1*10^-6

Yeah I'm probably underestimating it because I use a language with reflection, I don't know how C++ programmers cope

First for Python!

Just use pycharm. Makes it much more efficient

as far as i have seen, with lots of complaining and hodge-podge still very boilerplate-y reflection libraries
something like a general purpose simple version of qt's meta object compiler would be a godsend

Metaclasses soon™ (not really)

just lrn2type, python 3 is objectively better, range has far saner behavior than xrange (and more features) and the integer division in Python 2 was shit.

I love C

1*10**-6

Did you mean this?
If so, that would translate to ```1 * (10**-6)```.

Attached: 1523463118002.png (714x356, 78K)

Is cplusplus.com shit?

What's a good C++ reference (but not a pure reference, something with examples) for this absolute unit of a language?

Attached: 1545333118072.jpg (869x1200, 147K)

en.cppreference.com/w/
cplusplus.com/reference/

can recommend cppreference. it's up to date, accurate and sometimes has examples

cplusplus.com is garbage

>is cplusplus.com shit
not sure about the quality of the information on it but its site structure is really horrid
en.cppreference.com/w/
examples wise it's not that detailed but it does have some

How do I format code here when asking a question? With markdown?

Hashlife implementation in C. Can't get the hashtable right though...

no
you put it in code blocks

use m8

[/code] except switch the tags

well that didn't work
basically "code" without quoutes in brackets to open and "/code" in brackets to close
>deleting your fuckups
shamefuly

truly spoken like someone who does not understand what the print statement is. typical pythoner.

what's the name of the IDE functionality where where you type a function name and open parentheses it tells you what variables the function is expecting?

javascript
let arr = ["I", "study", "JavaScript"];

arr.splice(1, 1); // from index 1 remove 1 element

alert( arr ); // ["I", "JavaScript"]

I'm not sure about that specific feature but it lies under the umbrella of "Code Completion."

This is only possible on Jow Forums?

Anyone use vscode for C#? Any good extensions that work with it for things like automatic refactoring and formatting of code? I'm currently only using the official C# extension and trying to move away from VS2017

When I write C++ code:
int x = n/2;
return find(x);


Reading C++ code others wrote:
#ifndef ___INST_BAT_CURR__
___VARERR__ args...
_dec_line_no___ = void(*)sup(0x4f);
/* This line is only here because the program crashes without it and don't know why */
_VAR = ___FINAL

that's not C++, that's just C, too much macro spam, not enough template metaprogramming

Hi! I'm not very good at programming and have had to learn during down time at my job. I also have to do most of my coding on my work phone because I can't afford a laptop. I just wrote my first rock paper scissors code though. I know my formatting is weird and I'm sure it could be streamlined but I'm still proud of it. What do you guys think?

Attached: SmartSelect_20190318-120802_Pydroid 3.jpg (1060x1330, 468K)

Here's the output.

Attached: SmartSelect_20190319-041206_Pydroid 3.jpg (1053x276, 70K)

Apart from the horrible product names .NET is awesome. It's all the features I ever wanted when it comes to application development. No longer have to feel so filthy doing javascript, python, and java workarounds and I also don't have to melt my brain trying to figure out how some C/C++ preprocessor calls are working.

i have a online interview to be an amazon intern that i need to do by friday but the only languages i can take it in are c++, java, and c but i havent touched any of them in at least a year and it's finals week. Wat do?

Such innocence and optimism. He's cute. Can we keep him Jow Forums?

print >> f, "\t".join(map(str, ['foo', bar, buz])) # Python 2
print('foo', bar, buz, file=f, sep="\t") # Python 3

Truly a more concise language.

since I am also going for a similar position at Amazon, hopefully you do nothing and fail.

>can't afford a laptop
>writes on phone
>writes out every case explicitly
that's adorable. I'm not sure where you're from, but you should be able to get a used laptop and install linux for less than $200 (USD). This would be suitable for learning to code at a basic level.

just use ruby

I love .net core, framework pissed me of with their bloated shit, but I still prefer that to other languages that feel incomplete if you know .net.

This. I also use cppreference as my goto C reference.

is this Programmers Anonymous?

Cool stuff. One of the main things you want to go for is code reusability. You don't want to be doing the same thing over and over again. Right off bat you have print("tie try again*) 3 times, when you could just as easily have had if userHand == computerHand: print('tie')
Usually huge if blocks like that are considered tacky, if not inefficient. Try nesting your if statements too.

thanks, worked perfectly

Reusability wasn't the word I was looking for. You don't to be too redundant when it can be avoided.

Yes, but no one wants to hear about your sob stories and inability to stay sober. Code only.

what's the difference?

Why not Go?

go was literally created for people too dumb to program
it serves its purpose but if you can actually program there's no point in using
also its mascot is evokes feelings of rage and hamster murder

What about geeksforgeeks? I know they're Indians but do they teach bad practices?

I feel like there's only a few good online C++ references and the majority of the quality resources are in books. Which sucks because using several pdfs as a reference kinda blows.

Attached: 1509840649631.jpg (1063x1063, 126K)

pid_t childPid; /* Used in parent after successful fork() to record PID of child */switch (childPid = fork()) {case -1: /* fork() failed */ /* Handle error */case 0: /* Child of successful fork() comes here */ /* Perform actions specific to child */default: /* Parent comes here after successful fork() */ /* Perform actions specific to parent */}

What brand of laptop would you suggest? I hear people on here talking about thinkpads a lot but it's kind of hard to tell if they're joking. As for Linux I have a story.

I was able to successfully install Ubuntu on my SSD after some trial and error. It worked well but when I mentioned I wanted to get into cyber security someone suggested using Kali. I installed it and was able to deal with the learning curve up until the point where I couldn't get packet tracer working on it. No packet tracer means no homework means no degree. So I tried going back to ubuntu. I formatted the drive and tried installing it. Somehow during the process I irreversibly corrupted 2 micro sd cards and a flash drive. Eventually during one of the installations something goes wrong so I cancel it....then it boots into the login screen despite the installation not finishing. Alright fine. So I do my stuff, eventually I reset it and it boots into a GNU GRUB interface. I was unable to get it to launch from there so I try and reinstall it. Now here's the weird part. I formatted the SSD it was on and took out the usb I was booting it from. Somehow I still can boot into GNU GRUB though. Even after 3 formats it can still boot into GRUB. At this point I'm out of usable storage mediums to install a distro from and am too scared of the magic uneraseable GRUB prompt to try again.

Sorry for getting off topic. I just wanted to share that.

Ahh! Good idea with merging the tie outputs! I'll also try and redo it with nested if statements. Thanks for the help!

is python slow Jow Forums? If I decide to learn python, and supposedly get good at optimizing my shit, will my programs still be slow because python is slow?

>I feel like there's only a few good online C++ references
yes
blogs are good though
isocpp has a list of them
>the majority of the quality resources are in books
yes and no, there's plenty of shit books

Unless you work solo, you will have to utilise retarded programmers to some extent.

Use it like C wrapper

i know, and that's why i said it serves its purpose
frankly it's fucking amazing that it exists

I don't know why you keep bringing that up. That's a terrible way to use a language.
Nobody wants to write hundreds of lines of annoying glue code for no reason.

stupid frogposter

Yes, Python is ass slow and this is part of the core Python philosophy of expressiveness over performance. Step one of optimising any Python program is rewriting it (at least partially) in a language that actually cares about speed and memory usage.

I never tried it. It's on my bucket list but C# with .NET is just more familiar.

Am I wrong or is LLVM documentation kind of lacking? There's really no semantic description of the language (as in the big picture), and I also can't find the documentation for the IR code generation API, just some guides.

Ah, Okay. I misunderstood what you meant by its purpose. I'd add that working with retards includes using any library a retard has ever touched. Go actually makes reading others' code a breeze compared to less restricted languages.

Well, it's always gonna be slower than a native binary because of being interpreted and the GIL. You don't use Python for performance-critical code unless you want to spend time converting to Cython desu. But it can still be fast enough depending on what you're doing. Also, a lot of libraries are fast as fuck (see: Numpy) cause they're all vectorized in C anyways.

It's strengths are in scripting, being a glue language, rapid prototyping, research, easy portability and some light data science (if you're into that kinda thing). It's got its uses.

In Rust ™, this is just #[derive(Serialize)]

Rust macros are one of the only actual features worth using the language for over sepples.

This. If Rust did not have the limited BC, I would use the fuck out of its traits and macros.

Don't share your code ever. It's a common practice to not share your own because people will just use it for their own gains.

The if can be a lot shorter, using 0,1,2 for the hands instead of 1,2,3, and let
d = (userhand - computerhand + 3) % 3

then the if becomes:
if d == 1: computer wins
Else if d==2: user wins
Else tie.

If you are an intern at the company the code belongs to the company and giving it to someone who isn't an employee like a contractor could get you fired. Ask your boss and if he says no you have an excuse not to.

you are not wrong

Ruby is great. I really have no idea why Python is more popular. The only thing I like more in Python is the module system.

so I just made this

Attached: python_2019-03-19_12-38-17.png (642x492, 287K)

No.

Attached: 0_1.jpg (1440x810, 206K)

Yeah I don't publish most of my repos anymore. It's great that github has free private repos now, ai don't have to use shit like bitbucket anymore

I only use cppreference.com. Anyone who complains that it's too dense to read is probably too stupid to program.

Nope

Attached: 1552995669300.jpg (1440x810, 230K)

Nice.
>pulling random images from /b/

python may have shitty whitespace garbage at least has some level on consistency
in ruby you don't even need parameters or a return keyword but you can have them, which makes anything people write an absolutely unreadable mess
it's a fucking horrible language

>don't even need parameters or a return keyword
*to use parameters or a return
seriously what the fuck

>tfw you make a nice loading bar, but your program became so optimised it only shows up for half a second

Attached: 1545692036495.jpg (284x284, 16K)

whichever board you want

Attached: sublime_text_2019-03-19_13-08-11.png (555x373, 19K)

just add sleep(random(x, y)) every now and then, you can also later release an update where you remove the random sleeps and claim to have improved the performance and people will love you

A variant of premature optimization.

You unironically should make it show up for longer by introducing artificial delays. If it's too fast people might think it didn't actually work. This is not a joke, there's actual research behind it that I can't find at the moment.

Keep it as a reusable component. It'll come in handy again :)

def multiple_of(*factors)
proc do |number|
factors.all? do |factor|
number.modulo(factor).zero?
end
end
end

(1..100).each do |number|
puts case number
when multiple_of(3, 5) then 'FizzBuzz'
when multiple_of(3) then 'Fizz'
when multiple_of(5) then 'Buzz'
else number
end
end

Ruby is nice, not inconsistent at all. The returned value is the last expression evaluated.

>The returned value is the last expression evaluated.
that is not a good thing

It is. There should be no statements in a language, only expressions. Makes it easy to build things on top of other things, like I did with the value of the entire case expression as the parameter of puts. Helps avoid repeating stuff needlessly. It's really consistent and intuitive. Lisp works like this.

It's fucking perfect, how is it not?

no matter how much it makes functional programmers seethe, computers are not stateless
there are some times when you cannot return anything