/dpt/ - Daily Programming Thread

old thread: What are you working on, Sup Forums?

Other urls found in this thread:

education.github.com/pack
ddili.org/ders/d.en/alias.html
google.com/search?q=sin(50)
forbes.com/sites/suparnadutt/2017/09/20/this-startup-created-a-new-programming-language-now-used-by-the-worlds-biggest-companies/#1a431a017de2
twitter.com/SFWRedditGifs

fuck opengl

POLL:
have you ever used your programming skills for black-hat activity?

was it for fun? malicious? revenge? etc?

Absolutely not. I'm not even a greyhat like most programmers. I only write programs that are proven to have a neutral or positive effect on humanity as a whole.
Begone sinner.

There's something I've been wondering about C:
Does the C standard give strict or obvious guidelines on how to avoid memory leaks and/or introducing buffer-overflow-type exploits into your code?
I'm not trying to get political, I just want to know if it does or not because I'm considering using it for a project and it matters whether it's stated explicitly to ensure programmers at least get told to not do stupid crap.

>What are you working on, Sup Forums?

Exploring the deepest, darkest corners of Racket. Doing Advent of Code 2017.

Can anyone recommend a good resource to get into algorithms with java? Not art of programming level detail, but more practical. Thank you.

Can someone help me with this, I keep getting the wrong numbers back and I'm not understanding why. What am i doing wrong here?

> What are you working on, Sup Forums?

Creating a fun little app in Flucro (Clojure/Clojurescript).

are you sure you are not confusing degree with radian?

back in the day, on AOL, i did some stuff for fun. one was a little exploit that would usually overflow the reader's RAM and cause a shut down.

but i'm a good boy now, thanks for asking, NSA/CIA/FBI

c++ is the greatest language of all time

>Using your skills for evil
You disgust me

No, that isn't the business of the C standard.

The C standard defines what happens to code when you've compiled it. Along with that isn't defined.
You don't use C if your goal is memory safety. You have other reasons.

>Does the C standard give strict or obvious guidelines on how to avoid memory leaks and/or introducing buffer-overflow-type exploits into your code?
Check return of malloc
Free what you have allocated
Use string function only on proper strings(character arrays ending with '\0')
When you design API that takes buffer, also take the length of the buffer as parameter

It's not so much that memory safety is my goal, it's just that it's one of those nice-to-haves and it feels weird to not have it in the age of Rust etc.
If it doesn't have it in the standard that's fine but then let me put it another way, is it explicitly obvious how to write C code that won't have memory leaks/bugs/etc?

Well the book says to assume the variables are stored as radians, but I don't understand what that means. Sorry I'm shit at math

Nth for C#

If it was, we wouldn't still be getting those things.

>is it explicitly obvious how to write C code that won't have memory leaks/bugs/etc?
I'm not any of the guys you're responding to, but yes.

>every malloc should be paired with a free
>allocator/owner is responsible for cleanup
>always use the counted variants of string functions when reading user input, e.g. strncmp over strcmp, strncat instead of strcat etc

>is it explicitly obvious how to write C code that won't have memory leaks
No
C++ attempts to solve that with smart pointers and RAII

>how do you write C that doesn't have leaks/issues
Carefully or with experience. You can restrict yourself to using an API to do array manipulation and have it do bounds checking.

Thanks guise. If this was already made clear somewhere, sorry to get you to repeat it. I've never really asked you guise much before.
Interesting thread, nice to see you folks know your shit about C.

Learn how to use code blocks, stupid wincuck.

Hi /dpt/, this is only tangentially relevant but you guys are always helpful. I'm doing some work which requires me to have a cloud-based project which accesses a database. I need a site which can host a MySQL server for free and accept requests on port 3307. It doesn't have to be big as it's just a demo. I've tried db4free.net but I'm having some compatibility issues. Most of the other sites I could find just by searching look incredibly dodgy. Could you give me a rec?

I find this talk about memory management in C to be absolutely risible. Why are you dynamically managing memory to begin with?

Take a lesson from embedded systems, real time systems, or old guard video games folks and just don't do it. I think you'll find that your programs run much faster, are easier to write, debug, and test, and that you didn't actually need dynamic memory to begin with.

not fooling me nsa

amazon

/wdg/ will probably be more helpful

>Why are you dynamically managing memory to begin with?
Because sometimes you're creating an API for other people to use, and you don't know in advance exactly how much memory is needed and/or allocating everything is expensive as fuck in terms of memory footprint.

same same same as before

Do you have a student email? If so you get all this shit for free:

education.github.com/pack

>Done with Programming cert
>Professor tries to convince me to get an A.S degree that just uselessness generals and web dev/mobile shit classes
>le employer wont hire you
Should I take the bait? He's Indian I'm sure he knows what he's talking about.

is it possible to develop for android on an old pc? android studio is too bloated

I'm literally doing output and input right now, does it really matter

Just rent a cheap kimsufi server. It’s not free but you can use it as VPS for whatever you want. I use mine to host my website, email, or whatever projects I’m working on.

I like my API's to have their memory considerations handled with dependency injection. I hate it when they start allocating memory behind my back. It's never fun to unfuck a libraries memory leak when the problem is nested down 6 levels of indirection.

I'm doing freelance work and have been waiting on some login credentials for a client running Windows Server 2012. They finally got back to me with credentials for an FTP server... I need to set up a MySQL database for them. I was expecting like SSH or remote desktop credentials... how the fuck do I set up a database over ftp...

No, not really. Top of the line android phones these days are probably more powerful than your own PC.

Your best chance of "lightweight android development" is something like React Native and some Android emulator.

Sometimes that shit in unavoidable, like with data trees for example. Unless you somehow plan to implement a stack data tree with fucked up recursive algorithms, dynamic handling would be simpler

>phones these days are probably more powerful than your own PC.
kek. thats actually true

Viola Jones

It's only unavoidable if you want arbitrary recursive depth.

should I create a github that doesn't have my name associated with it?

No, don't move the fucking goalpost. You said "no dynamic allocation what so ever".

>methods are virtual by default
>have to add override keyword everytime
>however, thanks to name-hiding, they are not visible
>reveal them with aliases
>this affects member variables too
OOP in D is C-A-N-C-E-R.

So what you're trying to say is that dynamic handling is the commie's means of programming who wants to appeal to and unify everyone? I might agree with you.

Yes. Use create-react-native-app (you can install using npm) to write native Android or iOS apps right away, you don’t need to go through a separate build process for each one. You do not need Xcode or Android studio, just use whatever text editor you like (you'll be writing javaScript). CRNA uses the Expo framework which sets everything up for you.

You can run your app on an emulator or if you have a smartphone download the expo app and run your app on your phone (pic related).

>this is valid C
const const const const char const const const const * const const const const str = "const";

What problem is D even trying to solve? Most obsolete language I can think of.

Amazon free ec2(?) instance

You have to keep in mind that D was invented while C++ was still in it's pre-03 days.

[Many] of D's improvements appear to be small, but the aggregate is large enough that once you write a project
in D, you'll find it pretty hard to go back to another language.

Often, programming teams will resort to a hybrid approach, where they will mix Python and C++, trying to get
the productivity of Python and the performance of C++. The frequency of this approach indicates that there
is a large unmet need in the programming language department.

D intends to fill that need. It combines the ability to do low-level manipulation of the machine with the
latest technologies in building reliable, maintainable, portable, high-level code. D has moved well ahead of
any other language in its abilities to support and integrate multiple paradigms like imperative, OOP, and
generic programming.

-- Walter Bright

Yeah good luck actually maintaining those guidelines within your codebase.

What actually is this?

It's hard, but not impossible.

Example?

My point is that it's very mistake-prone.
It's simply not viable, and even kernel developers fuck it up.

>My point is that it's very mistake-prone.
I agree.

>It's simply not viable, and even kernel developers fuck it up.
I agree. I prefer C++ smart pointers to C-style memory management every day.

But you should still try to follow those practices when you are forced to write C.

of which?

I guess the last three points

>But you should still try to follow those practices when you are forced to write C.
Because you're forced to.

You could ignore all practices and just have memory leak everywhere though.

ddili.org/ders/d.en/alias.html
" Revealing hidden names of superclasses"

I'm making a little personal project game engine thing in Java with JavaFX.
People laugh at me for trying to make a game in Java but they never give me concise reasons why, just "minecraft did it but they had LOTS OF PROBLEMS!"
I just want to
>program in a language I'm most intimate with
>write something portable
>not deal with manual memory management
>have high level APIs like JavaFX so it's easier for my tiny brain
Why is Java frowned upon, Sup Forums?

>Why is Java frowned upon, Sup Forums?
Because I can't easily write a kernel in it or use it to write high performance code.

>use it to write high performance code.
Akka and other low latency JVM implementations are frequently used in HFT systems though

because when you're low IQ or uneducated on a particular subject, criticizing that subject is an easy way to trick other low IQ or uneducated people into believing that you are actually high IQ and knowledgeable, and not just another idiot

Deciding to finally learn MySQL, been putting it off for months.

However I'm wondering how you would go about making a function that:
>takes 3 arguments, where 1 is a primary key of a table (int), 7 the other 2 are dates.
>It then returns an int which is the sales that individual made between the 2 dates in the parameters.
>If the id does not exist then the function will return -1 or if the dates are invalid then the function should return -2.

Also why is MySQL never talked about here?

Thanks in advance

What's the correct regex to use for splitting words in text by spaces and all punctuation EXCEPT for apostrophes?

So for the sentence: "This, is John's hat."
You would get "this", "is", "john's", and "hat"

>you'll find it pretty hard to go back to another language
If by another language you mean old C++.
D is a deprecated language.

Come back when you can finally split std::string

[^\w']+
matches anything that isnt a word character or an apostraphe

>Why is Java frowned upon, Sup Forums?
Because it's popular.

Also it's a pretty ugly language by modern standards. It has only grown as a language by the strictest necessities and its age and misguided initial design decisions are really starting to show now that people are getting familiar with more modern languages which are built with modern IDEs and design practices in mind, making them much more compact without being impenetrable.

kek

What program is this?

>he thinks C++ is the worst of its problems.
D has been deprecated by C++ as a modern aid for legacy codebases and by Rust as a modern language.
Enjoy writing code that becomes legacy before you type it.

>he thinks C++ is the worst of its problems.
What exactly do you mean?

Because it's NOT Kotlin.

Thanks, looks like it works! For some reason my compiler is forcing \\ instead of \.

Same reason HTML isn't talked about. It's not a programming language, it's an accessory to programming. You can do some scripts in SQL, but these are meant to streamline the data propagation process; if you're using the scripting capabilities of SQL to replace a general-purpose programming/scripting, you're being silly.

As for your question, obviously we can't answer without knowing what your tables look like, but it should be something like
SELECT * FROM Sales WHERE personId = @inputId AND saleDate BETWEEN @date1 AND @date2

The whole "should return -1 if this or -2 if that" should not be handled at the SQL level as per my comment above. Some other language should call the above code only after first checking if the id and the dates are valid.

can someone pls help me with this :(

google.com/search?q=sin(50)

With what?

I used to netsend rude messages in high school computer class.

my fucking shit

'96 the hs library had a few PCs and it was my first LAN playing Doom, Age of Empires

but i'd send others unwanted messages via MS Access - no one figured out how to stop them, but it pissed everyone off to be interrupted mid-game

I'm currently disassembing Pokémon OR to find the exact damage formula. What a pain in the ass.

Sauce?

Maybe you should divide 2 Pis our of your diet. It might help you with your shits, but it might require doing a 360 on your outlook.

convert your degrees to radians.

#define PI 3.14159265358979323846

double r = angle * PI / 180.0;
x = sin(r);


also get a math book, you should know basic math.

Well I am taking a math class this coming semester, just trying to relearn c++ right now. The math caught me off guard

Uh oh

looks like Julia is the future

forbes.com/sites/suparnadutt/2017/09/20/this-startup-created-a-new-programming-language-now-used-by-the-worlds-biggest-companies/#1a431a017de2

it's a virtual memory editor. it can attach to a PID and search for/edit variables in that process's memory

so basically cheat engine?

Can we get a new language

C*

I want C# but C like pointers

yeah basically. started out as a learning project for me. it does have some extra features though and can be used very simply in a non interactive mode for editing known mem locations

Declare a type parameter of kind * and nobody cares except gophers. Declare a type parameter of kind * -> * and everybody loses their minds

add a signature scan feature
I had a lot of fun writing one and coming up with ways to make it faster and more efficient

>add a signature scan feature
what do you mean by this?
right now i'm working on a state saver that can backup all of a program's variables and restore them. it's working pretty well but sometimes crashes programs. i'm trying to find a way to determine which variables would be harmful to revert to a backup.