[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/
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: ss1.png (108 KB, 960x827) Image search: [Google]
ss1.png
108 KB, 960x827
Daily programming thread.

https://codeshare.io/ju9Cl
>>
File: logo.png (6 KB, 200x200) Image search: [Google]
logo.png
6 KB, 200x200
>>52400261
lo/g/os has been reactivated.
>>
>>52400854
that's stupid

the only acceptable use case is in mathematical libraries as
>>52400815
rightly points out.

in any other case operator overloading is stupid. look at the strings in c++ for an example of this.
>>
>>52400911
>found the newfag
shouldn't you be in school or something?
>>
>>52400911
No. If a piece of code works for any monoid, it should be able to use regular operators in its implementation. If you require a Ring, then you also get +, *, -, 1 and 0. Add Field, you get division. It doesn't matter if they're numbers or not as they obey the required laws. The term "number" itself is quite ambiguous (complex numbers? bignums? vectors? matrices?).
>>
>>52400261
You guys don't mind helping out a complete newbie, right?

#include <iostream>
using namespace std;

int main () {
long i = 1000000000;

while (i>0) {
if(i==1){
cout << "The count is at: " << i << "\n";
}
else {
cout << "The count is at: " << i << cout.flush() << "\r";
}
i-=99;
}
}


This is meant to keep output of a loop on one line, and truncate unused characters (when a new line is shorter than an old one). Obviously, it doesn't work. Doesn't even count down properly. I can't see my obvious mistake though.
>>
Why'd you create a new thread when the old thread is only on 108 replies?

>>52398999
>>52398999
>>
>>52401024
what the fuck am I looking at?
>>
>>52401040
Stupid bullshit, clearly. I explained what I'm trying to do in the post, though.
>>
>>52401024
Add some whitespace like
        if(i==1){
cout << "The count is at: " << i << "\n";
}
else {
cout << "The count is at: " << i << cout.flush() << " \r";
}
>>
>>52401075
I don't have a slight clue as to what you are attempting to do
>>
>>52401024
#include <iostream>

int main () {
long i = 1000000000;

while(i > 0) {
std::cout << "The count is at: " << i << std::endl;

i -= 99;
}
}
>>
>>52401024
you might want to learn html first
>>
>>52401091
I think he wants a loop that counts from 10000000 to 1 in steps of 99, but idk what he means by truncating unused characters.
>>
>>52401141
Yeah that's what it looked like , >>52401125 is what he is looking for I think
>>
We're all in here:

>>52398999
>>52398999
>>52398999
>>52398999
>>
>>52401125
>>52401024
>This is meant to keep output of a loop on one line, and truncate unused characters (when a new line is shorter than an old one)
nvm i didn't read this part
>>
Anyone here ever used the wikiMedia API with javascript?

This shit is hard to grok for a layman pleb like myself.
>>
>>52401091
>>52401141
>>52401174

Come on. I literally wrote exactly what I'm trying to do. The counter isn't important, I only made it huge so that I could have time to see what it's doing, and I'm only decrementing it by 99 because it's not a factor of the huge number I put on i, so when I saw a 0 on the end I could be sure it was because it wasn't being truncated when I want it to be.
>>
Why are there two threads?

The image wars aren't starting again, are they?
>>
>>52401294
do you want it to erase the previous number so that the console output is

The count is at: 1000000000


and then it gets replaced by:

The count is at: 999999901


and so on?
>>
>>52401338
No.

If I just use \r, this will happen:

string one = Michael
string two = Paul

cout << one << "\r";
cout << two;

output: Paulael


What I would WANT it say is
Paul


Hence my attempt at using cout.flush(), but I believe I'm misunderstanding how that works. I know I can count the characters on a line and hack it together that way, but that seems stupid and I'm sure there's a standard library function that will just clear the current line and move the cursor to the beginning of the same line, but I'm pretty new at this so I don't know exactly what I need to be looking for.

Whatever bugs there are with the countdown itself are completely unimportant to me. I could fix them, but I don't care to because that's not what I'm testing right now.
>>
>>52401440
cout << one << endl;
>>
>>52401038
stop shilling you're faggot thread.
>>
>>52401440
if you're wanting to tweak outputs anon, you're probably better off avoiding streams as a beginner. (cout is an output stream type).

using printf() is probably a better way to twiddle stuff until you get it just the way you want it.
>>
>>52402217
On the same line for fucks sake. ON THE SAME LINE. I don't want to end the line, I want to REPLACE the line.

I have to believe I'm being baited. Fuck it, I'm just going to use \r then stream out blankspace at the bottom of every loop. If there's a standard library method for doing this that I'm supposed to use, I'll find it later.
>>
>>52402326
I don't see how printf would help. Does it automatically clear the line if not explicitly told to go to the next line when it's done? I mean in the case where you use another printf after it (as would happen in a loop).
>>
>>52402340
//drake.c
#include <stdio.h>
printf( "stop being a faggot\n" );
>>
>>52402472
>\n
Yup. I'm hooked.
>>
this is the legit thread
>>
>>52404031
>>
Is C really better than C++, or is it just a meme?
>>
>>52402340
You're literally retarded. There is absolutely no legitimate reason why anybody would want to do what you're doing, whatever the fuck it is.
>>
>>52406662
All languages fall before the great language that is Javascrpit.
>>
>>52400261
> printf on unicode
>>
I feel like I'm getting burnt out on software. All of this programming just seems so pointless and I can never finish what I start. What do I do, /dpt/?
>>
>>52401024
tfw, java gets it done in half the lines
>>
CEENA
>>
>>52407341
>writing code that only works properly on a cistemdicks computer
Kill yourself.
>>
Ups, zombie cena broke the code
>>
>>52406662
it's a meme. almost no one uses C any more outside of operating systems, embedded systems and device drivers. C++ is like C but with more features so the only real disadvantage of C++ would be that there are lots of different features to choose from and a lot of technicalities which can be overwhelming to a beginner.
>>
>>52408403
> not knowing c
everything on linux is written in c for a reason.
>>
>>52408403
>herpaderpadoo I only know python so C is a meem xdddddd
>>
>>52488888
>>
>>52409173
C is almost as much of a meme as python for most modern applications
>>
What's wrong with nim, /dpt/?
>>
>C++
http://harmful.cat-v.org/software/c++/I_did_it_for_you_all
>>
Is there a preferred way to handle tabs in C? Should they be actual tabs or spaces? And should they be 2 space, 4 spaces, 8 spaces, etc...?
>>
>>52410264
>inb4 some script kiddie falls for this
>>
>>52408403
What should I use instead of C if I want to write a compiler?

>>52410323
Tabs for indentation, spaces for formatting.
>>
>>52410323
Personally, I prefer to treat tabs as 2 spaces, but I like my code to be as compact as possible (without sacrificing readability) so I can see more at a time without scrolling.
>>
>>52410364
> What should I use instead of C if I want to write a compiler?
LLVM uses C++, gcc has started using C++ but they're not in any particular hurry to replace existing C code for the sake of it.

But you can use any language which can read and write files (i.e. practically any language). C or C++ are commonly used for performance reasons, although it's fairly common for other compiled languages to use a compiler written in that language (the primary Java and Haskell compilers are written in those languages, as are those for most Common Lisp implementations).
>>
>>52410323
Using spaces is more reliable.

You used to be able to take it for granted that tab stops would be every 8 columns. Then software started letting you configure tab stops, so now you can't reliably use them at all for anything that might one day need to be read on a system other than your own.

Just using tabs for indentation doesn't work if you need to align a group of comments which span lines with differing indentation levels.
>>
dude weed lmao
>>
I have a ruby on rails question

I'm trying to model a database for my website and I'm trying to conceptualize how one would go about structuring a table that has a ManyToMany relationship with itself. I'm very new to programming and web development so explaining it in in laymen terms as best as possible is preferred. No need for specific code, just theory behind how one would structure such a database. Here's an example of what I'm trying to do and the best way I can explain it... using cats!

Let's say I have a table that lists cats and the relationship between itself is a representation of their mating pattern. Cats will mate with many other cats so each cat is a OneToMany relationship with a bunch of other cats. The initial thought would be to separate the cats into two tables of Male and Female and solve this issue classically with an intermediate table holding keys, however, this doesn't allow data for homosexual cats or bisexual cats. So how does one represent the mating details of these cats structurally in a database?
>>
I need a C project. I'm in a slump and I can't get out. Everything seems too hard or too trivial.
>>
>>52411178

Couldn't you have a mate column in your cat table where the value in that column would be the _id of another cat in the table?
>>
>>52411284
time for a rogue-like
>>
Ignore the trips, the code is at: >>52393000

>spend time setting up a dynamic array lua entity system in C
>seems to work pretty good
>add SDL to engine
>only notice one entity on screen
>moves extremely fast (as many times as that entity should be on the level, say, 5)
>console still tells me there are 5

I don't seem to be having any memory issues at the time being, but for all the entities to converge is weird.

I think I may have found the issue though, the tables inside the entity table. For some reason those values are the same across all entities while variables just in the entity table itself aren't. Is this something easily fixable?

tl;dr: metatable works, but table in table isn't
>>
File: sweet, sweet victory.webm (2 MB, 1280x720) Image search: [Google]
sweet, sweet victory.webm
2 MB, 1280x720
I didn't write a line of code but it's related and I'm super stoked that I solved it so I'll post it here.

I got my C.H.I.P. in the mail today and wanted to do a little project to try it out, so I decided to try controlling my Bluetooth-enabled LED bulb with it. The cheap chinese manufacturers didn't provide and documentation, and the only stuff I could find online about this was a slightly different model (colorific rather than ledmagical bulb; yes, their bluetooth interface is actually different)

It was a huge fucking pain in the ass without a bluetooth sniffer like the guy who wrote the guide for the colorific had, until I realized android has its own bluetooth packet sniffer built in, post 4.4.

After I realized that, the problem I'd been banging my head against the wall on disappeared in 2 minutes. Pretty silly, and the end result isn't exactly anything worthwhile, but still satisfying.

Next step is to do a silly toy hack with it, like make it change color based on the stock market or something.

This is the most basic bitch shit but it makes me happy.

webm related.
>>
>New to programming, learning Py

Can anyone explain htf the any() function works?

I know that the following code works

def vowel_det(text):
vowels = ["a", "e", "i", "o", "u"]
has_vowels = any(letter in text for letter in vowels)
if has_vowels:
return "Its got vowels"
else:
return "no vowels in there"

I know how it works because I've seen it used before, but I don't completely understand why it works. The x in y for x in z construction I have a very slight grasp on but still don't completely understand.


>inb4
I know I'm a faggot or whatever for asking, but I just thought I'd ask since i'm here. Any help is greatly appreciated
>>
File: 1452662339465.jpg (257 KB, 1200x1679) Image search: [Google]
1452662339465.jpg
257 KB, 1200x1679
Rate my C struct vtable implementation.

http://pastebin.com/juSPVEyC
>>
>>52406688
No legitimate reason huh? Go fuck yourself, idiot. If you can't think of a reason why someone might want to monitor the iterative outputs of a loop on one line rather than having it race down and fill up a console window, then just stick with HTML bucko.
>>
>>52411353
>New to programming
>learning python
Stop that, the heavy abstraction in python ensures that you never will know what your code actually does or how it works.
>>
How do I read/write a unsigned int using fgetc/fputc in binary file mode in c++?
>>
>>52411421
You'll have to use something like conio or ncurses, depending upon your system.
>>
>>52411353
Let's break it down:

>letter in text
get a list of letters in the text. So, if the text is "sup, /g/", our list is: s,u,p,,, ,/,g,/

>letter in vowels
same thing, except you already described vowels as a list to begin with

>letter in text for letter in vowels
we've got a for loop. we're gonna go over vowels one by one. For each letter in vowels, we're gonna go over each letter in text.

the for operator takes whatever's on the left of it and compares it to whatever's on the right, cross-product style. So if the list on the left has 5 elements and the list on the right has 10 elements, it'll make 50 comparisons.

This is returned as an iterable; basically just another form of list. If one were to display that iterable (and I totally recommend you trying printing it) it'd look something like this:

false
false
false
false
true
false

any takes an iterable, and returns true if any member of the iterable is true.
>>
>>52411323
Do you have any guides or tips about bluetooth packet sniffing? I received a shitty Android remote controlled car for Christmas and I want to try to write something to control it from my PC.
>>
>>52411469
>tips about bluetooth packet sniffing?
This was my first experience with the process.

sniffing packets in android 4.4+ is actually really easy, although the total traffic volume of a RC car might be enough to be a problem to sort through by hand.

See:
http://stackoverflow.com/questions/23877761/sniffing-logging-your-own-android-bluetooth-traffic

but also see:
http://stackoverflow.com/questions/28445552/bluetooth-hci-snoop-log-not-generated

because that first stackexchange fucking lies about where the log gets saved.
>>
>>52411353
any() runs over an iterator (what's the in parenthesis is not a function argument, but a generator comprehension) and if any of the elements is true any() is true.

The generator comprehension goes over the list 'vowels' and if the vowel is the string returns true.
>>
>>52411443
Yea, I've found that out elsewhere. I'm just going to do something like this

stuff = "use your imagination!";
blanker = " ";
i = 1000;

while(i > 0){

cout << stuff << "\r";
cout << blanker << "\r";
i--;
}


That should do what I need it to do. It's inelegant, but I'm nowhere near far along enough to be dealing with crap like ncurses right now.
>>
>>52411486
p.s. anon: control it from your pc? are you some kind of fucking scrub? strap your phone to it and make it an autonomous vehicle.

Or at least strap your phone to it and make it a first-person racer, if you're too lazy to make it autonomous.
>>
>>52411387
locon is breddy gud
>>
>>52410323
tabs with the same width as 4 spaces
>>
I don't know if this should go here or the stupid questions thread, but whatever.

I recently started the learnrubythehard way exercises, and I'm kinda stuck trying to figure out the purpose of a few things for exercise 17
http://learnrubythehardway.org/book/ex17.html

1. The string in the 15th line
out_file = open(to_file, 'w')

2. What's the actual purpose for the .close function if the program can still run?
>>
>>52411515
http://stackoverflow.com/a/4795782
>>
>>52411501
This isn't exactly a complex problem. Either keep track of what you change or do what you're doing and keep track of the character width.

http://pastebin.com/Au9dBn1M
>>
>>52411501
ncurses is fairly simple to understand conceptually. It turns your terminal into a MxN character grid. So something like
mvprintw(x, y, "[email protected]");
>>
>>52411515
1. it's an option. w is write. r is read. rw would be read write (dunno if it's supported by that, but probably is)

2. .close just closes those files, not the program. It's not really necessary in any modern system but it's good practice.
>>
>>52411486
Thanks
If I get stuck I can still try to peek inside the apk but I would like to get some experience in RE unknown protocols.

>>52411507
The car weighs like 50g, I doubt it would even move with a phone strapped to it.

My plan is to put a led on it and try to write or draw stuff with long exposures.
>>
>>52411435
I mean, I'm already knee deep in python and would like to at least try to learn it. I bought a couple RPi's and have a bunch of projects I want to try

>>52411468
Thanks dude. So the any() function worked in my original sample because the for operator compares in this instance. Got it. I was under the impression that for only worked in loops like

>for x in var:

as in "for each variable in the list 'var', do something that I will define in the next line".

That was what screwed me, i think. That and any() will just return true when any value inside is true.

Also an 'iterable' is a list of booleans?

>>52411498
Thanks dude. I honestly appreciate the help for a scrub like myself haha
>>
>Messing with pointers in C
>Slow my computer to a halt
>>
>>52411557
>If I get stuck I can still try to peek inside the apk but I would like to get some experience in RE unknown protocols.
I did that. I spent an hour banging my head against the wall of com.a.b.g.a.java. I don't recommend it.
>>
>>52411559
>Also an 'iterable' is a list of booleans?
It's a list of anything. In this case the syntax 'letter in text' returns true if the letter is in the text, false otherwise. So the iterable is a list of booleans.
>>
>>52411559
Honestly, if you want to learn how to program you should start with something lower level, or at least something that doesn't have dynamic typing - That shit is murder for new programmers. Enjoy having to learn all about types when you venture out of python later
>>
>>52401024
You have to use blank spaces. There's no other way. That's just how text mode works. I've done this before it's useful for not spamming your console. Create a method that stores the length of the last printed string and does your output for you.
>>
>>52411598
>Enjoy having to learn all about types when you venture out of python later
Python has types... you just don't have to specify them. If you don't know anything about a topic, don't opine.
>>
>>52411559
an iterable is a list (or, more accurate, a list is an iterable)

iterable means literally what it says; "able to iterate", or go through one-by-one.

A very simple example of an iterable would be a list.

The python 2.7 glossary has this to say about iterables:
>An object capable of returning its members one at a time. Examples of iterables include all sequence types (such as list, str, and tuple) and some non-sequence types like dict and file and objects of any classes you define with an __iter__() or __getitem__() method. Iterables can be used in a for loop and in many other places where a sequence is needed (zip(), map(), ...). When an iterable object is passed as an argument to the built-in function iter(), it returns an iterator for the object. This iterator is good for one pass over the set of values. When using iterables, it is usually not necessary to call iter() or deal with iterator objects yourself. The for statement does that automatically for you, creating a temporary unnamed variable to hold the iterator for the duration of the loop. See also iterator, sequence, and generator.

as for that "for", I was not aware of that use previously. I would discourage using it, just because a lot of people are gonna have to stop and look at it and wonder what in the heck it is, exactly, before they understand the code. You'd be better off (in readability terms) doing the comparison in a short for loop, and any performance difference would likely be minimal.
>>
>>52411598
I may be biased because I started with Java, and I'd have a different opinion if I started with Python, but Python is a great language and probably what I'd teach someone in if asked to teach.
>>
>>52411598
this

>>52411610
it hides them as much as possible
>>
>>52411598
Main reason I'm doing python, again, is for the RPi.

I would love to look at some other languages that beginners could grasp easier though, just for shits and giggles. Any suggestions?

I figure if I start off with a 'harder' language that learning others will be easier when I get to that point.

>>52411615
Ok, got it. Thanks

I imagine I'll start to use better and more readable coding techniques as I mature, as I plan on doing this for the next couple years, just for now I'm doing what free python books and free online courses are teaching me until I can take an actual coding class next quarter as an elective(my major has absolutely nothing to do with computer science)
>>
>>52411610
Python does a great job of hiding that fact though. Except when you fuck up, but if you don't know anything about types so you're fucked to fix it.
I wouldn't recommend python to a beginner either. Build your programming skills on a strong base, not on the most convenient one.
If you don't know anything about a topic, don't opine.
>>
>>52411598
>Enjoy having to learn all about types
https://docs.python.org/2/library/functions.html#type
>>
>>52411656
>(my major has absolutely nothing to do with computer science)
you're doing the smart thing, anon.

H1B curryniggers are destroying the industry, and when the industry goes there too goes every other decent job requiring a cs degree.
>>
Pondering ways to implicitly convey the concept of indirect references to my chatbot. The less hardcoding, the better.
>>
>>52411610
Of course it has types you fucking idiot, the point is exactly that you don't have to specify them which means new programmers don't learn about them. Do you honestly think the average python programmer would be able to use a statically typed language?
>>
static strong typing is the only sensible thing no matter if you're a beginner or a professional

approved languages list:
>C++
>Java
>C#
>D
>Nim
>>
>>52411696
>which means new programmers don't learn about them
Now that's just fucking retarded. Do you honestly think that?
>>
File: 1431166250325.jpg (71 KB, 648x752) Image search: [Google]
1431166250325.jpg
71 KB, 648x752
>>52411700
>Nim
>>
>>52411700
>programming in the statically typed jew
>>
>>52411700
Python beginner guy here

Java is next on my list
>>
>>52411761
good
>>
>>52411752
>static typing
>jewed

Daily reminder that dynamic typing is not programming, it's coding
>>
>>52411710
Nim is a good language
>>
>>52411778
no good ide support
no intellisense
hate the syntax

nim is almost a good language
>>
>>52411657
>If you don't know anything about a topic, don't opine.
Then why did you?
Teaching a dynamic language doesn't mean types aren't taught. Look at literally ANY intro to programming in python. Knowing types are necessary to know what operations you can perform on them. If you don't the difference between a number and string you can't do diddly shit. And knowing the difference between the ADTs is necessary for their use.

You sound like you've never learn a single dynamically typed language.
>>
>>52411761
I'd really recommend against it, but clearly I'm in the minority here.

I think the main this is it depends on what you want to do.
>>
>>52411778
It's full of good ideas but its creator has no idea where to go with it and seems to change his mind on crucial things every couple of months, breaking everything again and again.
>>
>>52411783
That's not the fault of the language itself though, excluding syntax
>>
>>52411706
Yes, in my work I encounter a lot of python "programmers" and honestly the concept of statically typed languages genuinely confuses them, they have no idea how to use different types.
>>
>>52411303
does nobody here know lua?
>>
>>52411806
>What you want to do

I want to
>Fuck around with an RPi
>Make simple android apps
>learn to problem solve and then have those problems solve themselves
>Mod video games if possible

Basically I just want to have some fun with programming. I'm not doing this for my profession, but I think this would be a cool skill to have. I'm probably going to be lurking this thread often from now on, just to see what I can learn.
>>
>>52411832
int((bool)something.toString())
>>
>>52411856
>make simple android apps
>java or interop with java
kill yourself now and save yourself the pain
i have this for a course module
>>
>>52411856
I became a much better programmer and had a lot of fun (most of the time) doing 3 out of 4 of those things. Then I did #2 later. Would recommend.
>>
>>52411832
Well I started on C, learned Go and hated it. Then Lua, Python, Haskell, and C++ (and hated it). In that order and I can tell you unless the type system helps, like in Haskell, I don't ever want to deal with it again if I don't have to.

>>52411853
Yo. I know that shit inside and out. What do you need to know?
>>
>>52411876
maybe in a garbage course it sucks and android sucks a bit but making apps/games isn't so bad
>>
>>52411891
>Java isn't shit
Get the fuck out
>>
Any suggestions for which C++ book I should read? I'm currently thinking of reading C++ for everyone 2nd edition.
>>
File: 1336871370563.jpg (23 KB, 288x499) Image search: [Google]
1336871370563.jpg
23 KB, 288x499
>>52411853
function entityMT:import( objtype ) 
local newObj = table.shallow_copy( _G[objtype] );
self.__index = self;
return setmetatable(newObj, self);
end

Here's your error. I'll let you figure it out further.
Also,
>;
pic related
>>
>>52411934
>>
If your Windows program requires an install, it's objectively shit.
>>
>>52411963
>If your program requires an install, it's objectively shit.
fixed senpai
>>
If your program requires disk space, it's objectively shit.
>>
>>52411973
this desu
>>
>>52411934
Do you already know a language?
>Accelerated C++
Beginner, but not dumb?
>C++ Primer (not plus)
Total dummy beginner
>Don't do C++
>>
If your program doesn't run in O(1), it's objectively shit.
>>
>>52411905
>java is shit
nice meme
>>
>>52411963
This
I fucking hate it when people decide their program needs to be installed when it absolutely does not need to, and then the uninstaller doesn't even clean it up properly so you have to manually delete a bunch of files and registry keys
>>
>>52412005
if it runs in O(1) it's not very interesting
>>
File: xTutor1.jpg (95 KB, 500x492) Image search: [Google]
xTutor1.jpg
95 KB, 500x492
I often wonder whether I am a computer scientist at heart. I have difficulty with a lot of programming but I generally just work through it. Will SICP show me whether I'm a real computer scientist?
>>
>>52411953
it should be copying all the contents of that table

as for the semi-colon, bad habit, it does nothing though

>>52411881
I may not know the right vocabulary or how to explain it correctly, but a metatable as an entity should give each entity a set of variables? I'm having it so variables that are tables are the same values across all entities.
>>
File: 1444519185838.jpg (122 KB, 425x516) Image search: [Google]
1444519185838.jpg
122 KB, 425x516
Post githubs/bitbuckets/gitlabs.
>>
>>52412005
Daily reminder that if your algorithm isn't at least O(n!(n^2)(fib n)) it doesn't do any real work
>>
>>52412061
How do you define being a computer scientist at heart?
>>
>>52412128
Easily thinking in abstract concepts, having a creative sense for problem solving. Wanting to understand problems and their solutions on a comprehensive level.
>>
anyone do this? https://hackerone.com
>>
Is pic related a good way to learn C still? Or is there a better way?

Also, should I learn C before I learn Rust or dive further into C#?
>>
>>52412195
>>
>>52412193
I think you forget where you are, anon.
>>
>>52412066
>it does nothing though
Yes, I know.

>but a metatable as an entity should give each entity a set of variables?
Inheritance?
> I'm having it so variables that are tables are the same values across all entities.
Like have the same fields? Or the same values?

I think what you are trying to do is implement interfaces, where objects of different classes are made to implement the same methods.

Sorry about the late response, my bunny was altered and I wanted to make sure it wasn't a mouse or rat.
>>
>>52412242
>Inheritance?
instance variables is probably what you meant. You want every object of a particular class to have the same fields defined. Luckily you don't need to define fields before using them in Lua, unless you want them filled with default values. So the copy really isn't necessary.

>altered
alerted, jej.
>>
>>52412151
Hm, well what I can say is, especially as a beginner, slogging through the relatively steep initial learning curve programming has can make you feel inadequate. I've been there. Even as people develop and become skilled programmers some retain this feeling/mindset - if you haven't heard it before, it's called "impostor syndrome".

Without knowing you I can't say from experience what kind of initial talent you might have for programming, but I can say it generally correlates with mathematical/scientific ability (even if said ability isn't taken to its full potential).

An interesting insight I read about once was a test students took before a CS course designed to predict success in the CS program. They were basically asked simple programming questions immediately, before ever having been taught a single thing about programming in the class.

What they found wasn't that *right* answers correlated the most with success in the CS program - it turned out that forming a consistent mental model as a guess for how programming worked, even if the model was wrong, was what really mattered. So if someone wrote wrong answers, but the same type of wrong answer consistently on the test, they generally fared better in the course than someone who made a mix of mistakes, or even a mix of right and wrong.

Anyway, I thought you might be interested.
>>
>>52412242
>>52412257

to test, I commented out the offset table from my entity, and the program crashed because it didn't know what that table was, so I had to add:

entity[#entity].offset = {}


i'd prefer not to do it that way though
>>
>>52411700
What about C, F#, Golang, or Rust?
>>
Can you guys help me out? I'm trying to break apart my for loops into separate functions. My initial thoughts were to pass int i by value in the functions, but it didn't work.

#include <iostream>
#include <string.h>

using namespace std;

int main()
{
char array[10];
int arraySize = strlen(array);

for (int i = 0; i < arraySize; i++)
{
for (int j = i + 1; j < arraySize; j++)
{
if (array[i] == array[j])
{
arraySize=arraySize-1;
for (int k = j; k < arraySize; k++)
array[k] = array[k + 1];
array[arraySize] = '\0';
}
}
}
>>
Can I put initializer lists in C structs?
>>
>>52412210
Why?
>>
>>52412325
Why?
>>
File: image.jpg (113 KB, 560x477) Image search: [Google]
image.jpg
113 KB, 560x477
I know this is a really stupid question, but I'm trying to weigh my options here. Working on a small application that takes the dates of winning lottery numbers and manipulates them, in Java. For the purposes of comparison, I will be iterating through them.

What's the best way to go about this, considering the file is 2000 lines long? My first thought is to load it into a LinkedHashMap<Date,Integer[]> but I think this would be too much memory usage.

My other thought is to just parse it line by line whenever I need to do something with it, but it troubles me needing to parse something over and over again. Perhaps the memory it saves is worth it?

How would you approach this problem in Java? Thanks in advance, pic unrelated
>>
>>52412345
If you're using Java you already don't care about memory usage. Also even if each line were 1000 characters long the memory would only be about 2MB. Just load the whole file into memory.
>>
>>52412286
That is quite an interesting piece. To be honest I think I may be well suited to be a writer; I have no trouble with writing though I am slow at it. It always takes me quite a long time to solve problems in Calculus though I generally am correct and grasp the concepts well. I lack in the purely algebraic portions of Calculus, making simple arithmetic mistakes and find it difficult to keep the "thread" of the solution in my head when solving a problem, especially if I can't visualize it. I have a lot of difficulty in science classes because it is difficult for me to follow the lab instructions properly step by step. That being said I really enjoy mathematics even though I am lacking in arithmetic and some abstract concepts that cannot be easily visualized. I enjoy programming the most when I can find a solution that is both elegant and functional, though I still have trouble understanding pointers or even reading Booleans well. I have been programming on and off from around age 14, but often it's difficult for me to keep the concepts in my head or to come up with an interesting problem to solve. Just a rant but it basically sums up the basis for my doubts in my "destiny" as a programmer, haha. Thanks for your reply.
>>
>>52412345
>2000 entries in a dictionary

oh no
what is going to happen to us
those 10 kilobytes are going to destroy everything in existence
>>
>>52412345
The fact that your program uses java already means it uses too much memory, 2000 dictionary entries isn't going to make a difference
>>
>>52412325
What is this supposed to do?
>>
>>52412216
what's that supposed to mean? I know the meme, but still.
>>
>>52412518
I was being kind of a dick but I just meant I didn't expect anyone here to accomplish anything like that
>>
>>52411435
Stop this meme already, there is heavy documentation about how python's data structures are implemented, how they're represented in memory and the cost associated with operations thereof.

>implying learning how a language actually handles these things isn't part of learning the language itself
>>
>>52412560
>no pointers
>>
>>52411303
objTest = { 
ID,
offset = {
x,
y
},
physics = {
xs,
ys
},
hitbox = {
x,
y,
w,
h
},
grounded = false,
dir = 1
}

Yeah this code does nothing.
offset = { 
x,
y
},

This makes a list of x and y, which are nil because they are not defined. You don't specify fields in Lua until you use them.

Additionally, doing a shallow copy of this won't work. 'hitbox' or any other table field in each copy will point to the same table, because tables are accessed by reference. So you are just filling each entity with garbage on every update.

Before you press on with this game thing, stop and learn Lua on it's own. Hacking at shit to just get shit done will leave you with a finished project many times longer than it should take you, without any real knowledge of what you've done. Don't be project-oriented when it comes to programming, it's very theoretical.
>>
>>52412603
Additionally,

function entityMT:import( objtype ) 
local newObj = table.shallow_copy( _G[objtype] );
self.__index = self;
return setmetatable(newObj, self);
end

>self.__index = self;
>return setmetatable(newObj, self);
make every entity's metatable entityMT. Which is not want you want to do.
>>
def potato(tomato):
tomato = 2 + 2
>>
Vim is actually kind of fun to program in once you learn the basics and get the right plugins.
>>
>>52412603
>stop and learn Lua on it's own.
I understand lua, just how I want to use it isn't working.

so what you are saying then is nothing is copying?

>>52412616
Then what do I want to do? I was doing what (at the time) /g/ recommended.
>>
>>52412631
I never got vim and emacs. Tutorials teach you the most basic stuff among basic stuff, like they literally teach you to write things, and they it's like Good Luck, Have Fun! Why learn and get used to wining in those things when I already am very well used to modern-styled editors and IDEs?
>>
Just wrote a program for clipping & converting video into webm. Really simple and not very noteworthy in the least but I wish I had done it sooner.
All those missed shit posting opportunities in live event threads.
>>
File: 1451751832808.png (17 KB, 418x359) Image search: [Google]
1451751832808.png
17 KB, 418x359
#include <iostream>
#define public
#define static
#define void int
#define main(x) main()

struct F {
void println(const char* s) {
std::cout << s << std::endl;
}
};
struct S {
F out;
} System;

public static void main(String[] args) {
System.out.println("Hello World");
}
>>
>>52411284
OpenGL spinnan cubez
>>
>>52412634
>nothing is copying?
This is the equivalent of the statement you wrote.
objTest.offset = {}
objTest.physics = {}
objTest.hitbox = {}
objTest.grounded = false
objTest.dir = 1
    offset = { 
x,
y
},

This is a list creation, unless there is an equals sign it's not a map. This would be correct
    offset = { 
x = nil,
y = nil
},

However that code still does nothing, x and y were nil beforehand.

You can solve this by making your new() method instantiate all fields with a non-nil value. Copying won't work unless you give non-nil defaults, like you did with grounded, for every field.

>Then what do I want to do?
Assuming you do what I said and write defaults...
function entityMT:import( objtype )
return table.deep_copy(_G[objtype])
end

function table.deep_copy(t)
local cpy = {}
for k, v in pairs(t) do
if type(v) == "table" then
cpy[k] = table.deep_copy(t)
else
cpy[k] = v
end
end
return setmetatable(cpy, getmetatable(t))
end

Note deep copy is HELLA SLOW. You should just use the new() constructor to set all the fields and metatable.
>>
anyone got that webm of the guy "hacking" but in actuality hes just smacking the keyboard. Theres a few of these so any one of them would be appreciated
>>
>>52412104
You first senpai
>>
>>52412761
nvm /g/uys found it on wsg.
sorry for bothering you's
>>
>>52412668
so any one of 50 webm4retards clones?

I actually have my own shitty fork, AMA.
>>
>>52412761
I have a small collection
>>
>>52412786
Can you record your screen then immediately cut/edit before saving?
>>
>>52412104
github.com/vinheim3
>>
>>52412802
that's pretty nice.

desu mine's a fork from an ancient version and I should probably move to a more recent one.
>>
File: 5c9H6DO.webm (791 KB, 320x180) Image search: [Google]
5c9H6DO.webm
791 KB, 320x180
>>52412761
>>
>>52412438
>>52412436
>>52412368

Haha, ok. I just finished developing what I could, but for some reason, the LinkedHashMap isn't in order anymore. I looked at the object, and it seems like a lot of the numbers are missing. Is there something built into java to kill parts of large objects or something?

Code class: http://pastebin.com/YNhygpZ7
Text file: http://pastebin.com/iD8jm7f8
>>
>>52412721
so set defaults and/or set them in the new() function?

got it

deep_copy worked 2/7 times, with the other three tries crashing my program, so i'll keep that noted.
>>
File: git.png (324 KB, 1383x1050) Image search: [Google]
git.png
324 KB, 1383x1050
Does anybody know how to get git-lfs to work?
I've installed it (or initialized it or whatever) and I go into my repo and do git lfs track path/to/file and then I git add, git commit, and git push, and then it still complains to me that the file is large and that I should use git lfs.
git lfs ls-files gives no output.
>>
>>52412912
Shit. change the 't' in the recursive call to a 'v'. Then it shouldn't crash.
The better solution is put everything in new. It will be faster and remove any corner cases copying might not cover.
>>
>>52412898
>built into java to kill parts of large objects or something?
Not while they are still in use no.
Too lazy to look at your code though.
>>
>>52412937
thanks, it seems to be working correctly now.

i'll play around with this some more, there are some other lua things I need to take care of that I think I can handle on my own (for now) and just some overall cleaning up.

i kind of want to stuff everything into the table so it looks nicer syntax-wise, but i don't think lua works that way with functions.
>>
>>52412898
>I looked at the object, and it seems like a lot of the numbers are missing.
You sure you are parsing the file correctly?
>>
>>52413000

While parsing, I printed the LinkedHashMap values. They seem to be perfect at that stage, but towards the end when I check all the values, it seems to be incomplete.
>>
Not sure what to call it but I want to make a desktop buddy or "shimeji". Anyone know any resources that would help?
>>
>>52412029
>registry keys
no you don't. There's no benefit to deleting those keys other than tidiness if you browse a lot at your local registry's library
>>
>>52413162
>Letting your registry get cluttered
I don't like broken registry keys cluttering my registry
>>
>>52413167
>>52413167
They don't do anything and contrary to somewhat popular belief they have no effect on performance.
Personally I don't peruse the registry enough to care.
>>
>>52413196
I often need to find stuff in my registry so it is counterproductive to let broken keys that serve no purpose clutter it
>>
>>52413203
Well to be fair you sound like an unusual case
>>
>>52412318
>C
not relevant for most modern applications
>F#
meme
>Golang
top meh. also overly pedantic about unused functions
>Rust
disgusting syntax, SJW community, mozilla
>>
>>52411700
>D
>Nim
>no Python
other than that, i agree
>>
>>52413321
>2016
>not knowing c
are you poor?
>>
>tfw you start to learn programming in C and realize you horribly you were programming in C++
I think beginners should really get into programming languages that focus on a smaller set of paradigms before moving onto very multi-paradigm languages, so they don't inevitably end up writing clusterfucked code. Personally, C and Haskell are good beginner choices, side by side
>>
>>52413321
You don't use C to write software, but it is still essential knowledge as it is the basis for most modern programming languages
>>
I've been trying to do this http://play.elevatorsaga.com/ for some practice but i don't think i have the right skillset for it. I get up to challenge 3 but i know i fluked my way there. Are there any steps i can complete that will increase my skill level? sort of like training.
>>
https://codeshare.io/4chan
>>
>>52413321
Why is Rust SJW community?
>>
>>52413427
>so they don't inevitably end up writing clusterfucked code.
i teached programming a couple of years back, this WILL happen regardless of language choice
its the same reason a good programmer can pick up a new language and still write good code in it with only a couple of days experience, its more about learning to think like a programmer than learning any particular paradigm or language
>>
>>52413532
>teached
don't think you were a particular good teacher lmao
>>
>>52413437
>You don't use C to write software, but it is still essential knowledge as it is the basis for most modern programming languages
this is the dumbest shit i've read all week
any C-based language will teach you ALMOST everything you would have learned from learning C and more, while also being relevant in todays industry
the exception would be proper memory handling, but C++ is honestly a better teacher for that
>>
>>52413583
Really? After all the malloc you have to do in C?
>>
>>52413574
>what are non-english speaking country
>>
>>52413620
memes and irrelevant
>>
>>52413620
countries*
>>
I want to write a little script that backs up a certain folder into a USB's respective folder. I would want it to check date modified so see if the two files are the same and be able to move around things like dropbox. Just wondering if there was already a program that does this.

I was planning to write this on Python could someone give me a list of functions that would be required?
>>
>>52411700
C and by extension C++ are not strongly typed languages. In fact, they're quite weakly typed
consider:
#include <math.h> //double sqrt(double x)

int main()
{
int i = 100;
int j = sqrt(i); //two implicit casts take place
return 0;
}

compiles just fine in C and C++

whereas in D, a strongly typed language
import std.math; //double sqrt(double x)
import std.conv; //conversions

void main()
{
int i = 100;
int j = to!int(sqrt(to!double(i))); //two explicit conversions are required
}
>>
>>52413651
wrong board faggot
>>
>>52413651
there are probably plenty of free programs to do things like that
>>
>>52413658
yet another failure of D
>>
>>52407062
>thatsthejoke.jpg
>>
>>52413658
it's all relative
>>
>>52413801
Yes, and C/C++ are pretty much the weakest statically typed languages out there
>>
File: 1450080254118.jpg (659 KB, 1167x936) Image search: [Google]
1450080254118.jpg
659 KB, 1167x936
It might be shit, but you have no excuses NOT to learn JavaScript in this day and age, /dpt/.
>>
C:
#include <stdio.h>
#include <math.h>

int oclock(double t)
{
double r = t * (double) M_PI / 6.0;
printf("(%f, %f)\n", sin(r), cos(r));
return 0;
}

int main()
{
oclock(12.0);
oclock(6.0);
oclock(3.0);
oclock(9.0);
oclock(1.5);
oclock(2.0);
return 0;
}

(-0.000000, 1.000000)
(0.000000, -1.000000)
(1.000000, 0.000000)
(-1.000000, -0.000000)
(0.707107, 0.707107)
(0.866025, 0.500000)


Python:
#!/bin/python

import math

def oclock(t):
r = t * math.pi / 6
print("(" + str(math.sin(r)), str(math.cos(r)) + ")")

oclock(12.0)
oclock(6.0)
oclock(3.0)
oclock(9.0)
oclock(1.5)
oclock(2.0)

(-2.4492935982947064e-16 1.0)
(1.2246467991473532e-16 -1.0)
(1.0 6.123233995736766e-17)
(-1.0 -1.8369701987210297e-16)
(0.7071067811865475 0.7071067811865476)
(0.8660254037844386 0.5000000000000001)


Why is the Python code giving wrong results for some of them?
>>
>>52413856
outside of web dev there is no use for js and even then most website shouldn't be using js fucking kill yourself webcuck
>>
>>52413856
Yeah, but thankfully it's a meme language so it's easy as all hell to learn.
>>
File: 1450605220312.jpg (281 KB, 1280x1024) Image search: [Google]
1450605220312.jpg
281 KB, 1280x1024
>>52413864
You're using the web now, you stupid retard.

If you don't want to cool stuff in people's browsers, that's fine, you can just limit yourself to a desktop environment.
>>
(mane (it (das)))

https://www.kickstarter.com/projects/637581271/the-3l-project

> kickstarter
>>
>>52413713
implicit casting is one of the most common sources of bugs in modern development. only a fool would save a few keystrokes at the mercy of the huge unwritten complexity beneath.
>>
>>52413864
>even then most website shouldn't be using js
you're an idiot
it's a painfully shitty language, still doesn't mean it doesn't make any webdev stuff 10000x easier
>>
>>52413858
my guess: degrees
>>
>>52413905
>implicit casting is one of the most common sources of bugs in modern development.
calling bullshit on this unelss you can provide a source
>>
>>52413920
That doesn't help me at all.
>>
>>52413905
>one of the most common sources of bugs
bullshit

but regardless, you can still do purely strong typing in C++
>>
>>52413925
wait no it's also wrong never mind
print the value of r in both cases to see what's going on
>>
>>52413890
>Lisp
Into the garbage lol.
>>
>>52413934
[@arch ~]$ ./a.out 
r = 6.283185, P = (-0.000000, 1.000000)
r = 3.141593, P = (0.000000, -1.000000)
r = 1.570796, P = (1.000000, 0.000000)
r = 4.712389, P = (-1.000000, -0.000000)
r = 0.785398, P = (0.707107, 0.707107)
r = 1.047198, P = (0.866025, 0.500000)
[@arch ~]$ ./main.py
r = 6.283185307179586, P = (-2.4492935982947064e-16, 1.0)
r = 3.141592653589793, P = (1.2246467991473532e-16, -1.0)
r = 1.5707963267948966, P = (1.0, 6.123233995736766e-17)
r = 4.71238898038469, P = (-1.0, -1.8369701987210297e-16)
r = 0.7853981633974483, P = (0.7071067811865475, 0.7071067811865476)
r = 1.0471975511965976, P = (0.8660254037844386, 0.5000000000000001)


Looks good to me, looks like the problem is occuring in Pythons math functions.
>>
>>52413658
In D the cast from an integer to a floating point type is implicit. The only reason it's required is because "sqrt" has two versions, one accepting a float and one accepting a real => the implicit cast would be ambiguous.
>>
>>52413936
Into the bin, you stupid American.
>>
>>52413981
I'm Australian though.
>>
>>52413888
KILL YOURSELF BUTTFAGGOT

try running anything webgl even with a high end computer it runs like ASS
>>
>>52413936
>shit taste
apply yourself
>>
>>52413985
Who the fuck says 'garbage' in australia?

are you from Melbmerica or some shit?
>>
>>52413975
wait python's is just more precise
-0.000000000000000249929, 1.0 is basically the same as -0.000000, 1.000000
python's answers are all reasonably close to correct, just with some rounding errors accumulating over the different operations. C's chops off all the rounding errors by rounding way lower when it comes to output by calculating in doubles and printing in floats

printf with %e and see what happens
>>
>>52414029
>2016
>using python
do you suck dicks?
>>
>>52413858

printf is making it pretty for you by default.

>f
>converts floating-point number to the decimal notation in the style [-]ddd.ddd.
>Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is 6. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes.

http://en.cppreference.com/w/c/io/fprintf
>>
>>52412151
>thinking in abstract concepts
I would have thought computer scientists are more likely to think logically.
>>
>the last few days outlook.com has finally started to keep my 'invisible' setting on skype like anyone with a brain realizes that it should (actually the cancerous shit should be able to be turned off altogether)
>start to get some hope in humanity
>check my email today
>it sets itself to 'available'
REEEEEEEEEEEEEEEE FUCKING KILL YOURSELVES WEB RETARDS
>>
>>52414029
[@arch ~]$ ./a.out 
r = 6.283185, P = (-2.449294e-16, 1.000000e+00)
r = 3.141593, P = (1.224647e-16, -1.000000e+00)
r = 1.570796, P = (1.000000e+00, 6.123234e-17)
r = 4.712389, P = (-1.000000e+00, -1.836970e-16)
r = 0.785398, P = (7.071068e-01, 7.071068e-01)
r = 1.047198, P = (8.660254e-01, 5.000000e-01)

Ahh okay makes sense, I didn't notice the e-16 in the Python code.
How to get Python to print floats like %f does?
>>
>>52413977
yes but it also converts from float/double/real to int as per the return type, which is not allowed as an implicit conversion
>>
>>52414048
they're trying to reach out to you and get you to become a social human being
>>
What's the difference between a float and a double?

Aren't they the same thing?
>>
>>52414034
I don't use python
>>52414053
>How to get Python to print floats like %f does?
who the fuck even knows?
but of course, dynamic typing is more productive :^)
>>
>>52414055
I didn't say it was.
>>
File: laughing-girls.jpg (29 KB, 400x266) Image search: [Google]
laughing-girls.jpg
29 KB, 400x266
>there are people in this thread RIGHT NOW who still use statically typed languages
>>
>>52414067
Dynamic typing is cancer.
>>
>>52414066
>What's the difference between a int and a long long int?
>Aren't they the same thing?
>>
>>52414053
https://www.google.com/search?q=python+float+formatting
>>
>>52414066
float = single precision, double = double float = double precision

float is 4 bytes, double is 8 (probably)
>>
>>52414075
I too hate finding errors before running every single code path of the programs I write.
>>
>>52414066
precision

a double is double precision
>>
>>52414066
a double uses twice the amount of bits that a float does, hence the name.
a double can express a floating point value with more precision.
>>
>>52414075

How better to implement dynamically typed languages than in a language which allows the user to explicitly state how large each chunk of memory is in a structure and how it is to be interpreted?
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.