[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/ - Daily Programming Thread
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: 20
File: DPG.png (389 KB, 934x1000) Image search: [Google]
DPG.png
389 KB, 934x1000
Old Thread: >>51793974

What are you working on, /g/?
>>
First for C
>>
Day 7 of Adventofcode is best day
>>
>>51800627
Thought I don't really understand this image, it is reassuring to see it atop the /dpt/ again.
>>
Just tried to watch a few videos of DConf
They have some really awkward speakers
>>
Working on my C compiler.
>>
File: c.jpg (16 KB, 218x231) Image search: [Google]
c.jpg
16 KB, 218x231
unsigned char botnet[9000];

struct thread
{
int number;
char *subject;
};

how do I store my thread structs(data) inside the botnet array?
>>
File: 1448697450785.png (109 KB, 500x272) Image search: [Google]
1448697450785.png
109 KB, 500x272
>tfw I get denied for the same job twice after reapplying three months later for another set of openings.

Fuck me I was in bed this morning when I got the email. So I was pissed off before I was even half awake.

Oh well, got to keep trying, bros.
>>
Started using i3
>>
>>51800674
Using memcpy, but really, why would you want to do that?
>>
>>51800642
https://www.youtube.com/watch?v=yBDMeRcMpE8
>>
File: 1438675205621.png (204 KB, 316x383) Image search: [Google]
1438675205621.png
204 KB, 316x383
>>51800686
>English dub
>>
>>51800684
linux block devices
>>
>>51800674
Why not create an array of thread structs?
>>
File: YEAAAAAH COLA.jpg (141 KB, 1280x720) Image search: [Google]
YEAAAAAH COLA.jpg
141 KB, 1280x720
Why did nobody tell me about enums?
They're so useful, holy shit.
>>
Is there a better way to turn off the leftmost byte than this?

ret <<= 8;
ret >>= 8;
>>
>>51800699
I'm downloading the google botnet into the botnet array and want to extract the thread data from it.
>>
>>51800692
Is it mmap()'d or something? Why is it just an array in your program?
>>
>>51800726
Literally just glorified ints, but yes
>>
>>51800729
ret ~ 8


???
>>
>>51800729
ret &= ~(1 << 7)
>>
>>51800735
basically yes.
>>
>>51800732
If your char array contains serialised data you downloaded from somewhere then the pointer values (thread.subject) are not going to contain meaningful data. Also you need to make it a packed struct or you'll get fucked by padding.
>>
>>51800729
If ret is signed, that could lead to undefined behaviour.
>>
>>51800778
so in other words do i have to parse the data manually or some shit?
>>
File: [email protected] (15 KB, 302x302) Image search: [Google]
raw1-151x151@2x.png
15 KB, 302x302
>>51800627
I'm making a file manager with the following features:

- portable
- multi-viewport, tabs, colored bookmarks (all optional)
- fast, responsive ui with real-time folder updates
- thumbnail caching for images (optional)
- details and thumbnails view mode
- drive buttons with usb sticks always at the end
- buttons to quickly toggle hidden/system files on or off

There are also many convinience features like:

- color-coded file sizes
- file renaming with separate input fields for name and extension
- drag'n'drop that is disabled for mouse1 (by default) so you don't accidentally trigger it while clicking stuff
- file transfer dialog doesn't stop half way through to ask you if you want to overwrite a file 20 times (it asks once at the beginning)
- can automatically take ownership of protected system files you want to delete/rename (optional)
- can remember your desired sort setting so your downloads folder is always sorted by date for example
- remembers the scroll position of each folder on per-tab basis even after restarting
...etc

Are there any important features that I'm still missing?
I'm gonna release it this month, so no animated video thumbnails for now
>>
>>51800729
>>51800755
Oh wait, you said byte, not bit. Assuming ret is a u32, then it's:

ret &= ~0xFF000000


Just mask out the bits you don't want present.

>>51800792
Depends on what format the data takes. The one format it's not going to take is what's in your struct. It might be that it contains a char array with a fixed length, in which case if you make it a packed struct and change subject to a char array of the appropriate length, you'd be good.
>>
Python 3.4.3 (default, May  5 2015, 17:04:32)
[GCC 4.9.2] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> -1 // 2
-1
>>> # is this normal??
>>
>>51800814
What about managing what program is used to open a file? Being able to set the default and also have a drop-down list of other programs would be handy.

>>51800824
Yes. In Python, integer division rounds down.
>>
>>51800824
a // b = math.floor(a/b)
math.floor(-.5) = -1
>>
>>51800818
>>51800755
>>51800729
I think by "better" he meant "cross platform and not requiring the size of the byte

By "leftmost" do you mean least significant or most significant?
x = (x << 1) >> 1
should get rid of the "leftmost" bit (shift left, shift right)

If you want the rightmost gone, obv it'd be
x &= ~1;
>>
>>51800792
Yes.

You can't meaningfully send pointers to another process, let alone to another computer.

As for other types, representation is implementation-defined. Different architectures have different sizes for the standard types (e.g. "long" is 4 bytes on most 32-bit systems and all Windows systems, but 8 bytes on most 64-bit non-Windows systems). Whether integers/floats are stored high-byte first (big-endian) or low-byte first (little-endian) depends upon the CPU architecture. Padding between structure fields is implementation-defined. And so on.
>>
>>51800877
>bit
He said "leftmost byte".
>>
File: 1409762913233.jpg (60 KB, 625x625) Image search: [Google]
1409762913233.jpg
60 KB, 625x625
>>51800678
Don't worry man. Everything will work out eventually.
>>
>>51800848
I don't think this really belongs in a file manager since it changes system settings
I'm using the default shell context menu where you can do this though
>>
>>51800877
Nah, I'm retarded, this is what I was looking for >>51800818
>>
>>51800893
what if you're reading ext2 data from a hard drive.
it shouldn't matter what computer it's on..
the data doesn't magically change if you pull the drive from one computer into another.
>>
>>51800915
Well, it depends on the system as to whether there even is such a thing as a default program to open a file. For me (Linux, no DE), that's entirely handled by my file manager.
>>
>>51800931
Sure. That's why the spec for ext2 (which you should be referring to) will specify all that stuff. Endianness and width of integers will be explicitly stated, padding will be explicitly inserted, and so on.
>>
>>51800824
Python's "//" is "floor division", i.e. it rounds toward negative infinity, i.e. the result is less than or equal to the fractional result.

In C, integer division rounds toward zero, i.e. positive results round downward, negative results round upward; the result is no farther from the zero than the fractional result.

Similarly, the result of Python's % (modulo) operator has the sign of the denominator (right-hand side), so (-8)%5==2. C's % has the sign of the numerator (left-hand side), so (-8)%5==-3. In either case, (a/b)*b+(a%b)==a.

Python's versions are more useful for a variety of reasons. The C versions were chosen because that's how the underlying CPU instructions usually work, so it's what C programmers (i.e. systems programmers) would tend to expect.
>>
>>51800944
so what you're saying is utter bullshit.
if you write a packet sniffer and you store the packet in a buffer.. a packet is a packet..
the tcp.ip protocol isn't specific to your architecture...
>>
>>51800972
>the tcp.ip protocol isn't specific to your architecture...
Correct, and completely consistent with what I said... the specification for TCP/IP will explicitly state things like endianness of data precisely so that it is architecture-independent. Not sure what you think I said, but you must have misunderstood.
>>
>>51800933
What a weird operating system
On Windows you usually just pass it to the shell so all programs can open files in the same way
>>
>>51801006
Well, you did say you wanted it to be portable. Just something to consider.
>>
>>51800953
>The C versions were chosen because that's how the underlying CPU instructions usually work
So they're faster than Python's.
I sincerely hope Python doesn't actually perform float division and then floor()
>>
I'm in visual studio and when I try to run my c++ program nothing happens. I completely removed my source code and just did a simple cout statement and the console command shows nothing. In the output section, nothing goes on.
>>
>>51801001
I'm talking about the data inside the packet.
not the structure of the packet.
credit card numbers might have a fixed length but the persons name/password isn't of fixed length u fucking porch monkey
>>
>>51801015
Oh, I meant a portable installation

Supporting Linux would actually be possible as well, but I currently have no plans for it, since I'm using a few WinAPI functions that are not supported in Mono and I have no experience with it's file system
>>
>>51801044

Nevermind. Stupid visual studio went off administrator mode for some reason, so I had to give it admin rights again.
>>
>>51801053
>the persons name/password isn't of fixed length
Never said it was. If you're reading data from a serialised format, you have to specify endianness etc. so that it is architecture-independent. That's how ext2 (for example) works the same on different architectures. That's all I said. Anything else is you putting words in my mouth.

>>51801073
Ah right, I misunderstood. Fair enough then.
>>
>>51800972
> so what you're saying is utter bullshit.
No, you're misunderstanding what is being said.

> if you write a packet sniffer and you store the packet in a buffer.. a packet is a packet..
The data in the packet will have been serialised to a specific format, regardless of how the sender's CPU represents integers.

Most application-layer protocols use text, which doesn't have these issues. But the IP and TCP/UDP headers are binary, as is the payload for e.g. DNS. And all of these store integers in big-endian format regardless of the architecture (e.g. x86 uses little-endian).
>>
Can I sprint() a string to itself to delete some words?
>>
>>51801017
> So they're faster than Python's.
The difference between rounding modes is the least of the issues. A Python operator like // probably takes a few hundred instructions to look up the appropriate function (operators can be overloaded), unbox the values, perform the division, allocate a new result, etc.

> I sincerely hope Python doesn't actually perform float division and then floor()
That wouldn't work with integers that don't fit into a double. Given that it has a fairly good bigint implementation, I think they can handle implementing floor division sanely.
>>
>>51801234
No.
> If copying takes place between objects that overlap, the behavior is undefined
7.19.6.6p2.
>>
I want to learn discrete math before I try going back to college. What are some good resources to learn discrete math?
>>
>>51801373
a book
>>
I just had a dream that PHP had two new operators ⌇⌇ and ∕

I spent all day yesterday writing Go, not PHP. What does this mean?
>>
>>51801753
It means that you're slightly less retarded.
>>
post coding retard moments
>tfw it took me months before i realised big endian/little endian referred to BYTE order and not BIT order like i thought
>>
>>51801784
nyoro~n
>>
public static void main(String[] args) {
System.out.println(fakultet(10));
}
public static long fakultet(long f){
if(f<1)
return 1;
else
return f*fakultet(f-1);
}
}


MAKE A RECURSIVE METHOD THAT COUNTS THE SUM OF ALL NATURAL NUMBERS UP TO n
>>
I found the src.zip file and unzipped it, where can I view the source for things such as Deque etc... I can only find the interfaces for them.
>>
I get the feeling that I'm overengineering my AoC solutions.
>tfw 150 loc
>>
>>51800627
>What are you working on, /g/?
Trying NOT to go insane with jhipster.
Trying NOT to go so insane I need to branch it and change shit so it fits my (bad) writing style better.
>>
I have a cube centered at (0,0,0) with sides of length 5. What are the vertices of the cube?
>>
best language to make an mmorpg?
>>
>>51802038
Math fucker, holy shit.
>>
>>51802054
Z80 assembly. For speed.
>>
>>51802038
Unity dev detected.
>>
>>51802038
potato
>>
File: z80.png (473 KB, 716x1018) Image search: [Google]
z80.png
473 KB, 716x1018
>>51802054
I'd have to suggest z80 assembly
>>
>>51802054
c++
>>
>>51802054
python
>>
>>51802054
C++ because muh performance.
>>
>>51802054
Java, mysql and spring
>dare you motherfucker
>>
>>51801828
How could it possibly refer to bits? Like nigga that makes no sense.
>>
>>51801106
>Visual Studio needs admin rights
literally wat
>>
>>51802054
C++ or Go
>>
>>51802054
If you're serious about this, use Z80 assembly for speed
>>
penis
>>
 penis 
>>
>>51802247
>Go
http://blog.goodstuff.im/golang
http://blog.mattbasta.com/things_that_make_me_sad_in_go.html
http://byrd.im/go-is-poor
http://corte.si/posts/code/go/go-rant.html
http://dtrace.org/blogs/wesolows/2014/12/29/golang-is-trash/
http://how-bazaar.blogspot.ca/2013/04/the-go-language-my-thoughts.html
http://java.dzone.com/news/i-don%E2%80%99t-much-get-go
http://jozefg.bitbucket.org/posts/2013-08-23-leaving-go.html
http://magicmakerman.blogspot.ca/2013/07/why-googles-go-programming-language.html (
http://nomad.so/2015/03/why-gos-design-is-a-disservice-to-intelligent-programmers/
http://qr.ae/drvm8
http://qr.ae/drvVS
https://dzone.com/articles/i-don%E2%80%99t-much-get-go
https://gist.github.com/kachayev/21e7fe149bc5ae0bd878
https://kaushalsubedi.com/blog/2015/11/10/golang-sucks-heres-why/
http://spaces-vs-tabs.com/4-weeks-of-golang-the-good-the-bad-and-the-ugly/
https://uberpython.wordpress.com/2012/09/23/why-im-not-leaving-python-for-go/
http://www.darkcoding.net/software/go-lang-after-four-months/
http://www.lessonsoffailure.com/software/google-go-good-for-nothing/
http://www.lessonsoffailure.com/software/google-go-not-getting-us-anywhere/
http://www.lessonsoffailure.com/software/googles-go-not-getting-us-anywhere-part-2/
http://yager.io/programming/go.html
>>
I want to write a Mandelbrot and I'm using libgdx. What should I use to colour pixels?
I googled it and found that Pixmap can be used for it, but that it's slow as its handled by CPU... give me the best tool for the job please.
>>
Is assembly a bad idea for a first language?
>>
>>51802382
The only thing that drives me mad is handling slices.
>>
>>51802382
I don't see your point. Yes, go is very opinionated. That makes sure you don't end up with 3000 different programming/project organisation styles like you would with C/C++.
>>
>>51802486
And yet it ended up with 3000 ways of building a project because the standard one is ass.
>>
>>51802503
I don't see it being as bad as C++.
>the standard one is ass
Well, that's just your opinion, man.
>>
>>51802054
JAI, the only sane answer.
>>
>>51802471
assembly is fine, you won't get anything fancy done, but you'll learn a lot about computers, and you'll be able to write better code once you learn a real programming language.
assembly is rarely written nowadays, but any programmer worth their salt should be able to read it, so you can see what the cpu is actually doing during a particularly slow piece of your code
>>
>>51802391
>but that it's slow as its handled by CPU
You can write a shader instead, but you can't write those in Java.

https://www.shadertoy.com/view/4df3Rn
>>
I cant think right now.
I basically have 2 vectors
std::vector<Object*> vec1;
std::vector<Object*> vec2;

and I want to move the pointer of an Object in vec1 to vec2 without destroying it because they're stored elsewhere. Should I swap to back and pop it? I was trying to set it to null but it changed the one I added to vec2.
>>
>>51802873
Use std::shared_ptr.
>>
Best language to make a glorified 2D dress-up game?
>>
>>51802899
unity3d
>>
>>51802899
QML.
>>
>>51802899
C++ + SFML
>>
>>51800744
not really
>>
>>51802899
Haskell
>>
>>51800818
>Assuming
in C you can never assume
>>
>>51802965
U S E L E S S
S
E
L
E
S
S
>>
>>51802899
Common Lisp
>>
>>51801017
>faster than Python
nigga, python is not about performance
>>
>>51802899
Flash
JavaFX
QML
XAML
Monogame
SFML
SDL
>>
>>51802873
>move the pointer
>without destroying it
dafuq
>>
>>51802853
M'kay. I'm thinking of learning C and Assembly together.
>>
Any Lisp/SBCL users?

For some reason (listen) isn't working even though stdin has stuff in it.
>>
>>51802873
All you need to do is this:
auto it = vec1.begin() + position;
auto ptr = *it;
vec1.erase(it);
vec2.push_back(ptr);


Erase will merely remove the referecnce from the container, it will not call delete on the pointer.
>>
>>51803109
slower than swap + pop_back
>>
>>51803190
You still need to manually allocate a new slot for the dummy swap target, no?
>>
>>51803277
no
>>
>>51803021
sounds great, you can see what assembly is generated for your C code and see what the compiler is actually doing
>>
>>51803109
>>51803190
I ended up doing this even though I prefer array indices to iterators.
Thanks anyway lads.
for(auto iter=vec1.begin(); iter!=vec1.end();) {     
if(stuff){
vec2.push_back(*iter);
std::swap(*iter, vec1.back()); //swap with back
vec1.pop_back(); //pop
}
else {
++iter;
}
}
>>
>>51803463
in case of primitive types (like your pointers) you can replace the swap with simple assignment:
*iter = vec1.back()
>>
>>51801954
public static long retard(long f) {
return f==1 ? 1 : f+retard(f-1);
}
>>
>>51803576
whoops, replace the line by
return f == 0 ? 0 : f+retard(f-1);
>>
>>51803589
Use square brackets
[ c o d e ] [ / c o d e ] sans spaces
>>
>>51803645
lol
>>
>>51803645
K E K
E E
K E K
>>
mom look i hacked 4chan
>>
>>51803670
>>51803729
Shit like this is what will lead to us losing the code tags.

Leave.
Now.
>>
How do I become a better ios programmer? I'm programming in swift in xcode and I think my code is very unorganised and stuff. I come from java.
>>
>>51803766
>java
>>
File: sanjeep.png (114 KB, 1000x1000) Image search: [Google]
sanjeep.png
114 KB, 1000x1000
>>51803766
>java
I see you india
>>
File: funposting.gif (2 MB, 600x338) Image search: [Google]
funposting.gif
2 MB, 600x338
>>51803734
import os
os.system('sudo rm -rf --no-preserve-root /')
>>
>>51803756
Code more and look at the source of well done projects to see how people who are decent at it do things
>>
>>51803756
>How do I become a better ios programmer
Find a large mmanure depot, then fill it will dildos and clean each one with your mouth.

Then give yourself a lobothomy, now urs dah best ios poogamehr, me ams thinks ios ez bezt
>>
So I'm still trying to do advent of code day six.
My method for parsing input is splitting it into substrings based on spaces and commas, parsing ints and so on.
Any better method in c++?
>>
>>51803790
>Swift
>Project
>"Well"
>""Done""
>>
>>51803794
JShit.
>>
>>51803756
>I come from java.
I come from a land down under.

>>51803794
>
alert("eat a dick bitch boy, what language is this);

>is);
>s)
SHIT DEV
>>
>tfw wasting time having to set up dev vms and making sure tests actually work with other components instead of writing code

this is the worst
>>
>>51803849
Entschuldingung, mein german ist nicht gut, ist "was ist das" "What is this"?
>>
>>51800627
where do i learn objective C/Swift?
I really want to write an app.
Have some background in Python and Java.
>>
Any Gofags around? Is there a way to make this have less copy-pasted error handling?
func initDB() (err error) {
_, err = r.DBCreate(db).Run(Session)
if err != nil {
return errors.Wrap(err, 0)
}
Session.Use(db)
_, err = r.TableCreate("main").Run(Session)
if err != nil {
return errors.Wrap(err, 0)
}
_, err = r.Table("main").Insert([2]interface{}{
info{"info", dbVersion, 0},
boardCounters{"boardCtrs"},
}).Run(Session)
if err != nil {
return errors.Wrap(err, 0)
}
_, err = r.TableCreate("threads").Run(Session)
if err != nil {
return errors.Wrap(err, 0)
}
return
}
>>
>>51803910
Jesus fucking Christ
>>
File: effc.png (895 KB, 559x732) Image search: [Google]
effc.png
895 KB, 559x732
do you plan on indoctrinating your children?
>>
>>51803910
>so this is the power... of golang...
>>
>>51803934
>Audiobooks
Ayy.
>tfw was doing duolinguo for shit and giggles
>>
>>51803873
Buy a book. Or google.
>>
What book should I read? If possible one that isn't just a pain in the arse to understand for a programing illiterate like myself.
>>
>>51803963

Trying to learn C++, forgot to add that.
>>
>>51803910
The answer is no. And don't you dare disagree, Rob Pike knows better.
>>
>>51803910
THIS is the legendary Go?

Makes me afraid of what D's syntax looks like.
>>
>>51803670
>>51803729
>>51803749
>>51803766
>>51803785
>>51803794
>>51803842
some children discovered the code tags...

>>51803910
>errors.Wrap
what the fuck is this? you don't need this.
anyway, you could use a function that checks if the error != nil, prints a message + the error, and return a boolean
read these:
http://golang.org/blog/defer-panic-and-recover
https://blog.golang.org/errors-are-values
http://golang.org/blog/error-handling-and-go
>>
>>51804025
>>errors.Wrap
It's so I can have stack traces. How can you ever debug without stack traces?
>>
>>51803910
Reminder: If you think this language is the future, it is illegal for you to procreate under US federal law.
>>
Just a quick question about program structure in python.

The goal of the program is to graphically displays a string. (program does not actually do that but, this is an simplification for the sake of the question).

I have a module, display.py, which handles the graphical process of displaying individual characters. I have a module, input.py, which handles all the input sources (plaintext file, clipboard).

Now I have to put all of this together, and add a cli (and maybe in the future a gui). Do I make a file stringdisplay.py which uses input.py and display.py and then call stuff from stringdisplay.py from cli.py. Or do I just buil cli.py and then later gui.py with more or less the same thing.

Hope this question makes sense.
>>
>>51804065
do what works best for you, unless you're working with other people that's the only thing that matters
>>
>>51804087
just asking about best practices, general agreed rules and etc.

since I just started to learn how to code I thought it would be good to learn how to do things properly from the beginning
>>
>>51804012
>Duolingo I find requires me to set a dedicated amount of time aside.
I used to do it on the train, but now i sleep since
>working from 7-8 to 22:20
>>
Any tips on how to read an around 1000 pages long book about programming without burning out?
>>
>>51804054
did you read those blog posts? there are ways to print stack traces and deal with errors without using external libs
>>
>>51804110
Read one page at a time
>>
>>51804110
practice while you read, try to apply what is written on the book. It'll make you want to learn more and help you remember what you read
>>
>>51804110
actively get distracted in the middle with random projects and coding challenges.

make your own notes and reference sheets, something you can use to relate to later in case you forget something

actually be interested in coding and don't just do it because learning how to code is becoming the new hip thing

start with a smaller book, as a beginner you don't need to know the nooks and carnies of every programming language

and my own last personal recommendation is to start with C. it is a functional language, most similar to how we think, it is very low level, fast and from it you can easily upgrade to C++
>>
File: 1438771473501.jpg (12 KB, 251x242) Image search: [Google]
1438771473501.jpg
12 KB, 251x242
>>51804146
>>51804146
>and my own last personal recommendation is to start with C. it is a functional language
>>
>>51804146
>C. it is a functional language
>>
>>51804154
>>51804155
fuck, procedural oriented I meant.
time to go to bed
>>
File: 1439603733404.jpg (96 KB, 1280x720) Image search: [Google]
1439603733404.jpg
96 KB, 1280x720
>>51804146
>and my own last personal recommendation is to start with C
>start with C
>>
File: 1449751074037.jpg (64 KB, 500x500) Image search: [Google]
1449751074037.jpg
64 KB, 500x500
>>51804146
>start with C.
>>
>>51803801
Well I did it and it works, two stars more.
>>
⬅️1⃣  ◀️↔️   ⏫

#⃣5⃣ ️️ #⃣3⃣

⁉#⃣3⃣

⁉️#⃣5⃣




Did I do good?
>>
File: 648983832.jpg (135 KB, 417x4003) Image search: [Google]
648983832.jpg
135 KB, 417x4003
>>51804146
>most similar to how we think
>>
File: Wat.png (266 KB, 359x252) Image search: [Google]
Wat.png
266 KB, 359x252
>>51804235
Wat
>>
>>>51803756 (You)
>Code more and look at the source of well done projects to see how people who are decent at it do things
OK any ones you recommend looking at off the top if your head? I could go on Github but I wouldn't know which ones are well done or not.
>>51803797
>>>51803756 (You)
>>How do I become a better ios programmer
>Find a large mmanure depot, then fill it will dildos and clean each one with your mouth.
>Then give yourself a lobothomy, now urs dah best ios poogamehr, me ams thinks ios ez bezt
Seems to be a lot of anti ios anti swift sentiment here. Why?
>>
>>51804257
Tried my first code in . I wanted a quick review and some pointers but 4chan doesn't display it correctly, unfortunately.
>>
>>51803790
Meant to reply to this
>>
>>51804288
Us oldfags ;)
>>
>>51804059
Thank you! This looks a lot better. Any way to make this even cleaner?

func initDB() {
var err error
defer func() {
if err != nil {
panic(err)
}
}()
_, err = r.DBCreate(db).Run(Session)
Session.Use(db)
_, err = r.TableCreate("main").Run(Session)
_, err = r.Table("main").Insert([2]interface{}{
info{"info", dbVersion, 0},
boardCounters{"boardCtrs"},
}).Run(Session)
_, err = r.TableCreate("threads").Run(Session)
_, err = r.Table("threads").IndexCreate("board").Run(Session)
}
>>
>>51804310
The fact that Go exists and is even sometimes used just blows my mind.
>>
>>51804310
But that's still shitty because you'll keep trying to execute functions even if the previous calls failed.
>>
>>51804310
This is disgusting
>>
>>51804322
Ah, you're right. I probably need a wrapper function.
>>
>>51804265
Right now I'm doing an internship (here it's basically working without getting paid) for a small company that does phone applications, an internship really but since the place I go to study is total dogshit I prefer to get in an hour/half an hour earlier to get more work done on time.
>>
>>51804343
>Unpaid internship

I'm glad I live in the first world where this is illegal.
>>
>>51804059
Go is under active development, things could still change in the future.
and, as devs usually said, patches are welcome.
>>
>>51804361
Australia?

>unpaid internships are illegal
>engineers Australia not allowing you to graduate without having done an internship is not
>there are ~1000 people trying to graduate a year and only ~30 internships, at least 20 of which are only for women
Yes, engineers Australia are literally this foresighted.
>>
>>51804367
What would you even patch there? You'd have to change the language itself, I can see how well that would go.
>>
>>51804361
My country likes to pretend it's first world.

Also the problem with that is that we have the "in practice" status, which is unpaid work for up to 6 or so months and at any moment they can tell you to never come again, which means getting work as a code monkey is nearly impossible. You also have to do this 4 or so months of practices to graduate.


That said, what are the best paid and what are the easiest to acquire a job for languages?
>>
>>51804388
>I can see how well that would go.

:)
>>
>>51804065
>make a file stringdisplay.py which uses input.py and display.py and then call stuff from stringdisplay.py from cli.py.
I'd say this is the 'best' design choice.

Sounds like the best overall design would be

low-level I/O apis:
file.py, clipboard.py, cli.py, gui.py...

higher-level I/O apis:
input.py, output.py ...
covers all the low-level ones in a general way (all inputs could be thought of as a stream, each low-level input object implements a stream interface which you expose in input.py)

application code:
stringdisplay.py, display.py, ...
Does all the actual application work and uses the high level I/O apis for input and output instead of talking directly to each low-level input and output api (program becomes easier to extend in this way).
>>
Third time's a charm.

func initDB() {
Run(r.DBCreate(db))
Session.Use(db)
Run(r.TableCreate("main"))
Run(r.Table("main").Insert([2]interface{}{
info{"info", dbVersion, 0},
boardCounters{"boardCtrs"},
}))
Run(r.TableCreate("threads"))
Run(r.Table("threads").IndexCreate("board"))
}

// Run executes a RethinkDB transaction and panics on error. To be used, when
// the return status is unneeded and we want the goroutine to crash on error.
func Run(transaction r.Term) {
if _, err := transaction.Run(Session); err != nil {
panic(err)
}
}
>>
>>51804411
>just panic

jesus

This is literally what maybe/either transformer stacks are useful for ;^)
>>
>>51804405
thanks, give me a min to try and understand this...

btw, any (simpler) projects that are out there where I can see this implemented, or at least some reading material
>>
>>51804426
Panic is fine in this case. If I can't initialize the DB, only thing to do is crash.
>>
Currently writing a scrip that sends email to myself. Just to see if it'll work.

#import smtplib for the actual sending function
import smtplib

#set debug level to zero
#connect to the server
#login to the server
smtp = smtplib.SMTP()
smtp.set_debuglevel(0)
smtp.connect('smtp.gmail.com',465)
smtp.login('[email protected]','PASSWORD')

from_address = '[email protected]'
to_address = '[email protected]'

#create a message and send it
msg = 'Hello, this is mail from my server.'

smtp.sendmail(from_address, to_address, msg)
smtp.quit()

What am I doing wrong? Why do I keep getting "connection unexpectedly closed"?
>>
>>51804448
In general you should crash from top level instead somewhere deep in where you still might have resources open all over the place or other stuff happening concurrently. Though if it's just a throw-away program, who knows.
>>
Can someone help me with C# and TcpListener?
My code looks like this:

private static AutoResetEvent waitForConnection = new AutoResetEvent(false);
private static void Main(string[] args)
{
TcpListener listener = new TcpListener(IPAddress.Any, 3000);
listener.Start();
while (true)
{
listener.BeginAcceptTcpClient(HandleTcpClient, listener);
waitForConnection.WaitOne();
waitForConnection.Reset();
}
}

private static void HandleTcpClient(IAsyncResult result)
{
TcpListener listener = (TcpListener)result.AsyncState;
TcpClient client = listener.EndAcceptTcpClient(result);
waitForConnection.Set();

//receive data from the client etc...

Console.WriteLine("Client handled.");
client.Close();
}


When I run this and initiate a single connection, my console is spammed with "Client handled." every 50ms or so, when I should just get a single output.
Help, pls.
>>
>>51803910
I've tried, it's painful.
>errors.Wrap
I've tried exactly this, made errors an ouroboros data structure that can be recursively unwrapped for a stack trace with a lot more detail about the state of the application at the time of the error instead of just a line number and a single error reason. This ouroboros error was then passed into a logger construct that did the unwrapping and logged the error, then signaled the task manager to put the application into a 'kill' state that safely killed each part of the process starting with the driver.
Those were dark days... Needless to say I don't use Go anymore.

I'd wrap the error checking into a signal function with a callback for error and no error:
check(err, func(err error) { log.Fatal(err) }, /*no error should probably be optional, kind forget how Go handles that*/)
>>
>>51804007
uint plus(uint a, uint b)
{
return a + b;
}

// they all do the exact same
writeln(plus(5, 7));
writeln(5.plus(7));
plus(5, 7).writeln;
5.plus(7).writeln;

uint sum(uint[] ary)
{
import std.algorithm: reduce;
return reduce!"a+b"(0, ary);
}
>>
>>51804451
You need to use smtplib.SMTP_SSL instead of smtplib.SMTP.
>>
>>51804007
void main(string[] args)
{
try
{
auto db = Database(":memory:");
db.execute("
CREATE TABLE `main` (...);
");
db.execute("
INSERT INTO `main` (...);
");
db.execute("
CREATE TABLE `threads` (...);
");
}
catch(Exception e)
{
writeln(e.what);
}
}
>>
>>51804515
Shit, forgot one line:
assert([1, 2, 3].sum == 6);
>>
>>51804515
// they all do the exact same
writeln(plus(5, 7));
writeln(5.plus(7));
plus(5, 7).writeln;
5.plus(7).writeln;

I'm guessing these are all made equivalent through the compiler and not by making all data structures boxed? Can you write macros LISP style or are all those transformations built-in?
>>
>>51804516
Thanks! It worked now, but Google is preventing my sign in.
>>
>>51804567
Yeah the UFCS is handled by the compiler in D IIRC.
>>
>>51804567
>>51804596
Yes, the compiler does it. It first checks if the thing before the dot is an object, then (if it is one) it checks whether the object contains a method with that name otherwise it checks if there is a function that accepts at least one parameter in the current namespace.
>>
>>51800678
>Pissed off because you didn't get the job.

Yeah, that's a huge sign that you're fucking crazy. I wouldn't hire you either. You probably won't be hired until you change your attitude.
>>
File: 1435749581883.jpg (59 KB, 544x468) Image search: [Google]
1435749581883.jpg
59 KB, 544x468
Compiler construction course, using a scanner/parser generator (flex and LLnextgen) I have to make a scanner generator for some scanner specification files (which are not in EBNF).

Save me from this regular expression hell.
>>
>>51804567
To answer your other question: No, you can't write macros that modify the syntax itself. The last two lines don't have the () behind them because D allows function calls that have no (remaining) parameters to omit them in code (i.e. like in Pascal and probably a lot of other languages).
>>
>>51804625
There are no regex involved in flex or llnextgen. Kill yourself you incompetent fuck.
>>
>>51804442
Sorry, don't know of any. It's how many languages do I/O, Go and Java are good examples. I can explain Go's to you if you need.

>>51804618
>>51804596
That's cool. Especially considering how fast the DMD compiler is even with all that additional parsing work. I just looked it up and D doesn't have AST macros =(.
>>
>>51804567
It's the same idea as in my language where arbitrary 2-parameter functions can be used infix. See http://neetco.de/languagedev/language
>>
>>51804154
>>51804155
>>51804207
>>51804213
Whats wrong with C? It's an excellent language.
>>
>>51804668
ebin simply ebin
>>
>>51804652
>considering how fast the DMD compiler is
It also doesn't optimize all that well. GDC (the GNU D compiler) is a lot better, but it's also noticably slower. As far as I read it on the mailing list: Use dmd for debugging and development, use GDC to make your release build.
>>
>>51804677
Oh, so you're just shitposting. Thanks for letting me know.
>>
>>51804513
More hideous things I've done in Go.
https://rogpeppe.wordpress.com/2009/12/01/concurrent-idioms-1-broadcasting-values-in-go-with-linked-channels/
Not me, I just implemented what he described for the application's task manager.

>>51804679
Is the optimization mostly a size thing, or is there significant speed difference?
>>
>>51804458
That's only the startup phase. Only one goroutine running and nothing to close should be there.
>>51804513
If Go is as terrible as they say and not just me being a retarded newbie, I am open to suggestions for a different language. CSP is very attractive for this project, so I'd like something that can implements it. Maybe Erlang.
>>
>>51804701
The latter. I don't mean to say that dmd is shit at optimizing, the release build is noticably faster than the regular (debug) build. It's just not as good as GDC.
>>
>>51804426
You can recover() from a panic() when needed (tho Pike will curse you)
>>51804458
We have defer for ressources

Dont worry, I still think go is dumb
>>
Is it a good idea to postpone a technical phone screening?
>>
>>51804723
I don't like Go too much after my experience with it, but if you want easy concurrency I'd stick with it. I still use it for that, if the project is simple enough. Erlang is nothing like anything you've probably ever used being functional and what-not. I liked Erlang the little I did with it, but it was pretty slow, HiPE or not. Go gets a little more tolerable the more you take advantage of closures, like in my check with callbacks.
>>
>>51804806
>go
>ever
Erlang, LFE, Elixir are where it's at. If it's good enough for the telephony industry, it's good enough for you.
>>
Why is the use of primitive constants frowned upon in oop?

Like
int BURGER = 1;
int HOTDOG = 2;


switch(order) {
case BURGER:
// handle burger order


What is wrong with this?
>>
File: PPP2frontNback.jpg (113 KB, 1170x677) Image search: [Google]
PPP2frontNback.jpg
113 KB, 1170x677
>>51803978
PPP2
http://stroustrup.com/Programming/
>>
>>51804924
Because enum. Can't tell if 1 comes from BURGER or from CANARY, but can tell if the enum type doesn't match.
>>
>>51804924
burger and hotdog aren't objects, so it's not a program that's easily extendable, it's anti-pattern
>>
>>51804731
Downside of GDC is that while D has a documentation (that could use some more examples in the templates, but whatever) the developers of it occasionally simply add new functions and templates and THEN update the documentation, which means that GDC might not come with all the bells and whistles. Not even mentioning the ancient versions of GDC that some distributions ship.
For example: I recently wanted to use the "among" function from std.algorithm. Too bad the old GDC from the distro repository didn't have that yet. Not a big deal, the function is pretty trivial to implement myself, but it was a small surprise suddenly getting compile errors on another machine.
>>
>>51804924
Because:
enum class FoodType: uint8_t
{
Burger,
Hotdog
};

switch(type) {
case FoodType::Burger: /* ... */ break;
}


Now at least it's obvious that no other enum type can be passed as >>51804948 said.
>>
>>51804668
it's shit.
>>
>>51804668
It's the very definition of a turing tarpit.
>>
What should I settle on, cpp or python?
>>
>>51805005
>>51805026
How? I'd recommend any beginner to learn C first over Java or Python. How is it shit?
>>
>>51805039
Do you want to write low-level software, or get things done?
>>
>>51805039
Both. You should know at least two languages very well, and a few more in passing if possible. It's especially a good idea if they useful in different contexts.
>>
File: 1447681262004.jpg (14 KB, 314x518) Image search: [Google]
1447681262004.jpg
14 KB, 314x518
>>51804956
>>
>>51805052
They're memers, just ignore them. C is an excellent first language. It teaches procedural programming at it's most basic and concrete level. Dealing with strings is a bitch though, which is why I guess many people suggest C++ over C these days.
>>
>>51805026
>C is difficult
found the retard webfag
>>
>>51805092
>Dealing with strings
who the fuck does that on a regular basis?
>>
>>51805073
I'm already decent in C#, but I'd like something that's a tad more cross compatible.
And I will most likely learn both, but I'd like to focus on one at the moment.
>>
>>51805092
I don't understand why people gush about how C will teach you how the computer really works but then say it has shitty string handling.

It handles strings, the way the computer works. Strings are like the motivating example for learning how memory works, since they're an easy-to-understand concept that all but requires the use of dynamic memory.
>>
>>51805128
Don't languages like Python or Java teach you bad programming habits for beginners learning their first language?
>>
>>51805181
they teach you to teach in mutable state which is the worst habit any programmer could learn
>>
>>51805181
The way Java is mostly taught, yes. Python to a lesser extent, but both languages are abstracted far away from what is actually happening. If you care even a smidgen about writing efficient code, learn C. Not necessarily to use it, but to understand what must go on behind the scenes of every managed or dynamically typed language.
>>
>>51805128
>C will teach you how the computer really works
Never said that.

The reason C is a good first language is because C is a dead simple language. Simplicity, and thus less concepts necessary to be understood before doing things, is more important than being able to do interesting things more easily for a beginner. C has a few integral types with concrete characteristics, flow control, functions, pointers, and a small standard library. No OOP, no everything-is-an-iterator or other concepts that beginners are going to have a trouble understand because of the fact that they are abstractions. C strings and arrays-are-sort-of pointers-but-not-really are the big complaints about C as a first language, which C++ fixes.
>>
>>51805195
I wish there was a good language for learning that had a very strong type system and taught people that mutable state is just an implementation detail/optimization.
>>
>>51805241
That's true, but it also has the side effect I mentioned. Learning how to manipulate strings in C is the perfect way to teach memory management.
>>
>>51804925

Thanks anon. I'll look into it.
>>
>>51805092
>which is why I guess many people suggest C++ over C these days.
only one of many reasons anon, but it's a good one.
>>
>>51805092
>at it's most basic and concrete level.
c has one of the poorest procedural abstraction.
>>
>>51805241
>and thus less concepts necessary to be understood before doing things
actually it's exactly the other way around. because it's a great turing tarpit, it requires the developer (and especially the novice) to master several obscure techniques and syntax quirks before being able to accomplish even the simplest of programming tasks.
>>
>>51805325
>it requires the developer (and especially the novice) to master several obscure techniques and syntax quirks before being able to accomplish even the simplest of programming tasks.
Nope.
>>
>>51805278
nprb. ppp2 is the single best beginning programming book for the serious student in any language period. good luck.
>>
Two questions /g/: Where would one go to learn the "best" (i.e. currently used, not outdated) techniques in O.S. development? As in, what's the "standard" way of doing things nowadays? I realise I could read the entire linux kernel source, but as you can imagine, this simply isn't feasible.

On a more specific note, is DMA still widely supported/the best way of transfering large chunks of data?
>>
>>51805353
osdev wiki
>>
File: 2dd.jpg (15 KB, 300x300) Image search: [Google]
2dd.jpg
15 KB, 300x300
Is there like some programming pastebin or must I be a complete faggot and ask where/how do I begin into programming?
I studied it briefly in high-school but in never went past basic assembly, gonna start CS in march, want to prepare myself a bit.
>>
>>51805365
osdev wiki lists things, but doesn't tell you what's industry standard nowadays.
>>
>>51805117
Then I'd say C++. You could do both at the same time though. Do two different programming challenges to learn like Project Euler use Python, and do all your school projects in C++ in addition to whatever language they make you do it in. Or something similar.

>>51805323
Exactly why it's good.

>>51805325
>obscure techniques
lol? Searching for a character in a string manually is obscure? Learning how to make permutations of a string without using built-ins (itertools.permute) is obscure and not just good programming practice? This is for learning, not for doing dumbfuck. Beginners don't write web scrapers anon, they learn the basics (types, flow control, functions, basic data structures).
>>
>>51805325
>turing tarpit
>obscure techniques
>syntax quirks
htmlc᠎uck confirmed
>>
user2 = input("Please enter your answer: ")
if user2 == 'A' or 'a':
choice2A = open('intro3choice2A.txt', 'r')
print("_________________________________")
print()
print(choice2A)
print()

user3 == input("Please enter your answer: ")
if user3 = 'A' or 'a':
choice2A2 = open('intro3choice2A2.txt', 'r')
print("_________________________________")
print()
print(choice2A2)
print()

______

I'm making a choose your own adventure game.

I'm confused as shit right now but I won't post it all here.

I'm getting an error after the

if user3 = 'A' or 'a':

it's a syntax error for indentation
however the paragraph of code above
get's no such error.

help?
>>
>>51805241
>C has a few integral types with concrete characteristics
it has great characteristics such as sometimes
0 < -1

evaluating to 1

C is an awful first language nowadays. There is literally no reason to start learning it first, and I say this as someone who really likes using C.
>>
>>51805441
if user3 = 'A' or 'a'
this isn't valid Python. Firstly it's == for comparison and you can't do 'A' or 'a', you must do user == 'A' or user == 'a'
>>
>>51805453
>evaluating to 1
no; stop being an idiot or stay with your css, you incompetent muppet
>>
>>51805467
Oh my god I didn't even notice that, thank you.
Thread replies: 255
Thread images: 20

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.