[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: 24
File: pointers.png (87 KB, 795x597) Image search: [Google]
pointers.png
87 KB, 795x597
Old Thread >>51294963

Whatcha working on, /dpt/?

Also, whats your favorite data type?
>>
first for java
>>
second for java sucks
>>
I'm transforming SQL code into pl/sql procedures.
Vim really helps with macros and regex.

My favourite data type... either dictionaries or lists. I can't really decide.
>>
>>51298891
Wow, I was struggling to get what OP's pic was until I read "give me some pointers"
10/10
>>
>>51298891
currently programming a GUI interface using Visual Basic
>favorite data type
Boolean (only Java users will get this)
>>
fifth for java sucks.
C master race.
Go loses the race.
>>
>>51298891
That joke wasn't funny the first time.
>>
why the fuck /g/ do not have id's?
>>
>>51298922
>GUI interface
>Visual Basic

Why not C#?

Also
>GUI interface
>Graphical User Interface interface
>>
I'm writing a Gameboy emulator in D and a Lisp interpreter in Go. How many meme points do I get?

And bytes are the best data type desu
>>
>>51298945
Because we legun. Expect me.
>>
>>51298945
It's too slow.
>>
>>51298959
what the fuck is legun mean dude? also expect what?
>>
>>51298945
Why would we?
>>
>>51298959
omg u don't even know our motto
it's expecto patronum
>>
>>51298891
Nullable Boolean.

Come at me.
>>
>>51299001
I prefer to call it the gender boolean.
>male
>female
>qt programmer
>>
>>51298891
I took over working on a new site for a company that deals heavily with aircraft specifications. They have an extensive database with all the specs which is the core of their business. Their old site was run off of joomla with the specifications database hookup integrated. They didn't like Joomla, so the new site I am working on is a custom CMS through codeigniter. The Indian chick who was working on the site before me was combining the cms user tables with the aircraft specification tables. Is this a good idea, or should I separate the two and use codeigniter to access the two tables through model db connection calls?
>>
>>51298891
LMFAO at that pic. That OP is making fun of people in Programming 101 class, right?
>>
>>51298966
you mean /g/ fast for id shit? too heavy for server to process?
>>51298986
to understand the samefags
>>
>>51299018
I wonder if SJWs legitimately think booleans are sexist.
>>
>>51299024
>The Indian chick who was working on the site before me was combining the cms user tables with the aircraft specification tables.
Where?

In the CMS database or what?
>>
>>51299027
/g/ isn't populated by shitheads like /b/ is
even /v/ doesn't have forced IDs and it runs almost as fast.
>>
>>51299027
>you mean /g/ fast for id shit? too heavy for server to process?
Threads last longer, which means samefag would remain samefag for 4 hours, vs 15 minutes on something like /pol/.
>>
>>51297230
>>51297276
>>51297292
arguments in Go ;)
https://golang.org/ref/spec#Passing_arguments_to_..._parameters
>>
all of you need to fuck off
>>
>>51299057
She started a new database and was combining the 2. That approach seemed pretty stupid to me. The specs tables won't change so she probably should have just been adding the new CMS tables to the one live specs database if that was the approach that she was going to take. It seems like a easier but sloppier approach to me. My initial reaction is to ditch that plan and just have 2 defined database tables in codeigniter, though I see no real reason why both types of tables can't just be in one DB.
>>
>>51299068
>>51299081
i see, its pointless.
>>
File: dynamicarguments.png (11 KB, 558x249) Image search: [Google]
dynamicarguments.png
11 KB, 558x249
>>51299093
>C#
Am I missing something, or did your link just explain how to do pic related in Go?
>>
File: 96cas2.png (90 KB, 875x625) Image search: [Google]
96cas2.png
90 KB, 875x625
Just reverse engineering youtube.
>>
>>51299272
>reverse engineering
>html
>>
>>51299294
Are you retarded?
>>
File: 1447192064189.jpg (50 KB, 552x615) Image search: [Google]
1447192064189.jpg
50 KB, 552x615
Which freelance skill out of these isn't incredibly hard, and makes OK money?

>WinAPI programming
>Linux distro development
>Linux kernel module development
>>
>>51299178
>She started a new database and was combining the 2
As in, putting those two tables as two new tables in that database?

That's fine, it's part of the advantage of having something like a data warehouse. You only have to deal with one version of the truth, instead of connecting to two separate databases.

Using multiple databases on the same display can cause issues in some BI tools, but as far as the website is concerned, it's kind of a moot point.
>>
>>51299319
>html
>programming
>>
>>51299345
>MUH DATA STRUCTURES
>MUH ALLLGGGOOORRRRITTHMMMSSSSS
>>
javascript programmer here

how goes it?
>>
>>51299334
>makes OK money
WinAPI programming desu. You try to sell a program under Linux and neckbeards start popping up calling your product literal cancer.
>>
License for this thread:

Copyright (c) 2015, Anonymous 
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
>>
>>51299373
>javascript
>programmer
pick one
>>
>>51299369

lel im the guy that always says that

sup bro

>muh binary trees
>muh allocated memories
>>
>>51299387

javascript is programming. It's just a dynamic language. But it's still programming
>>
>>51299224
yeah, nm, there are no tuples in Go

>>51299272
wat. doesn't youtube support JS map files?
>>
File: itbegins.gif (205 KB, 500x500) Image search: [Google]
itbegins.gif
205 KB, 500x500
>>51299405
sureeeee
>>
>>51299391
At work, tired. 2 hours to go. Just been doing blow in the bathroom most of the day. You?
>muh UDP
>muh gentoo
>>
>>51299405
>javascript fags thinking they're programmers.
Listen. It's called JavaSCRIPT for a reason. You're just a scripter.
>>
What the fuck is a Mutex and what do I do with it?
>>
>>51299450
Texan cows.
You tip them when they go to sleep. They spaz out and are all "muuuuuuu".
>>
>>51299339
I meant to databases instead of 2 dB tables. The spec and cms tables don't overlap at all. The spec tables are just specs and the cms tables are user permissions and such. With Joomla there were obviously 2 different databases, but now that the cms is custom all the tables can be in one database. I just don't know if there is any logical reasons to keep the cms tables in a different database than the spec tables.
>>
>>51299378
no
>>
>>51299455
I live in Texas, though, and I haven't heard of these.

Either way, is it like a "Speaking Pillow"?

Like, your at the divorce councilor and you can only talk if you're holding the pillow.

So like, the mutex is the speaking pillow, except, you put your mouth up to it and speak your data directly into the warm folds of the pillow.
>>
>>51299482
I've never been to a divorce councilor. Only to jail for domestic assault, and those guys don't care if you're bitin-- holding a pillow.
>>
>>51299482
That's...not a bad analogy for a mutex.
>>
hello guys,
i have the following problem:

i must replace single quotes with double quotes, except the single quotes are written between double quotes

currently i'm doing it with python without the exception
mystring=re.sub("'",'"',mystring)

example:
> {'hello': 'world'}
{"hello": "world"}

> {'place': "I'm here"}
{"place": "I'm here"}

someone have an idea?
>>
>>51299458
Well, you *could* have it all in one DB, but it might be better to let the CMS app have its own DB for compartmentalization purposes.
>>
>>51299540
What the fuck.

THESE are the Indians coming to steal our jobs?
>>
>>51299585
Yup. They're completely retarded.
Never outsource.
It will always cost you more to rewrite their feces-signed code than if you had just developed it inhouse.
>>
>>51299585
dey
yuk
der
JERRRRRRRRRRRRR
>>
>>51299376
What if you don't plan selling your stuff, but want to just freelance and program for someone?
Isn't Linux distro development popular and well-paid on freelance sites now?
>>
>>51299450
I'm guessing mutual exclusion.
>>
>>51299676
>>51299676
>>51299676

Posted in dead thread.
>>
>>51299450
It's used from multithreading.
http://lmgtfy.com/?q=mutex
>>
>>51299450
It works a bit like this
https://www.youtube.com/watch?v=2F89dl26wq8
>>
>>51299690
Visual Studio
>>
>>51299690
I just wrote a little bash script to create $1.c with codeeval settings so I don't need to type it every time. Could do that.
>>
>>51299615
Well that's a bit different. I think what you're talking about is System Administration. If you're planning on getting a job in a Linux environment, sure, pick the Linux route. But your choices for software development is either to go work at red hat for linux (which they barely do), or learn the WinAPI
>>
>>51298891
>16-bit addresses
>>
>>51299723
kek
>>
>>51299803
>not realizing that 0x6700 is literally the same as 0x0000000000006700
>>
>>51299690
Try JetBrains products.
>>
>>51299803
>4*16 = 16
>>
>>51298891
I'm bored and want to contribute to some opensource project for fun and to add to my public github profile. I know C, C++, Java, Ruby, and PHP.

What bugs or features do you want fixed or added in your favorite program or os?
>>
>>51299851
>impying a bit is a hexadecimal digit
>>
>>51299853
I'd really like #lang C for racket. Thx.
>>
>>51299853
You should rewrite the Linux kernel in C#
>>
>>51299556
That's what I am thinking. Thankfully she hadn't gotten very far, but this is why I don't like taking over projects. It was pretty obvious from her sloppy code that she didn't really know what she was doing. I'm glad her husband lost his green card so that they could get deported.
>>
>>51299864
>implying I implied that
>>
>>51299446

A "scripting" language is a programming language wherein the source code is the final program, rather than being ahead of time compiled into machine code or bytecode. All scripters are programmers.
>>
It's always encouraging when nobody responds to your code in /dpt/ because chances are nothing is glaringly wrong with it, but it also kinda sucks
>>
>>51299915
Or it was just so embarrassingly bad that nobody wanted to respond
>>
>>51299540
not a goddamn regular language you fucking fuck faggot fuck
>>
>>51299932
There will always be someone on /g/ to shit all over your code if it's really embarrassingly bad
>>
>>51299093
but we were discussing tuples you mong
>gotards and reading comprehension
>>
>>51299853
Fix systemd
>>
>>51299853
Would you be willing to add some bugs to something I'm working on?
>>
>>51299391
>muh red black trees
>muh djiikstra
>>
Trying to create an old-fashioned web app where the pages are rendered on the server and it's mainly about handling forms. For now I'm not going to write a single line of client-side JS and bask in the glory of how web is supposed to work.

My back-end is JS though :-)
>>
>>51299387
>>51299446
javascript is turing complete retards
>>
Learning D
>>
>>51299902
apart from shell programs like bash then there's basically no "scripting languages" left

well I guess picolisp

maybe forth depending on your autism levels
>>
fucking captcha fucked up my chance to get quints I TYPED IT CORRECTLY YOU SHIT
>>
>>51300006
>maybe forth depending on your autism levels
They're high anon. Really high.
>>
What are some good Python resources? I know the language but don't feel like I completely grok some of its more obscure syntax.
>>
How to transfer multiple types of data between Classes in Java using only one method?
>>
>>51299978
Link the repo?
>>
>>51300006
>there's basically no "scripting languages" left
JavaScript
Python
C#
F#
PHP
Ruby
SQL
>>
>>51299902
even little kids can write scripts because its so easy.
>>
>>51300046
create a new class while holds each of the data types you want to return, then make your method return that.
>>
>>51300066
was kidding but post throwaway email
>>
>>51300006

Consider the definition I just gave you for a scripting language, and tell me you really think that only Bash and Picolisp will fit the definition. Protip: Ruby, Python, and Perl all fit the bill.

>>51300091

Just because it's easy doesn't mean it's not programming.
>>
>>51300137
I don't know about ruby and perl because they're shit but python has a bytecode representation. Most languages do today.
>>
>>51300189
>python has a bytecode representation
That doesn't stop it from being a scripting language.
>>
>>51300137
>Consider the definition I just gave you for a scripting language, and tell me you really think that only Bash and Picolisp will fit the definition. Protip: Ruby, Python, and Perl all fit the bill.
Your definition unfortunately isn't the word of god.
"Scripting languages" traditionally means languages that are simple (hence interpreted) and used for small automation of tasks. Hence a "script" is a small program, usually a utility.

However, lately languages like Python and Ruby have been used for full scale applications (usually web servers) rather than just small "scripts". (Perl on the other hand...?)
>>
>>51299897
topkek

Good to hear.
>>
>>51299902
Those are called interpreted languages, skiddie.
>>
>>51300240
>interpreted languages
Interpreted programming languages, yes.
https://en.wikipedia.org/wiki/Scripting_language
>>
>>51300272
The key point about scripting languages is

>Typically scripting languages are intended to be very fast to learn and write in, either as short source code files or interactively in a read–eval–print loop (REPL, language shell).
>This generally implies relatively simple syntax and semantics; typically a "script" (code written in the scripting language) is executed from start to finish, as a "script", with no explicit entry point.

>For example, it is uncommon to use Java as a scripting language because of its lengthy syntax and rules about which classes exist in which files, and it is not directly possible to execute Java interactively, because source files can only contain definitions that must be invoked externally by a host application or application launcher
>In contrast, in Python it is possible to define some functions in a single file, or to avoid functions altogether and write in an imperative programming style, or even to use it interactively.
>>
Making an animal guessing game in python for fun
>>
>>51300203
>That doesn't stop it from being a scripting language.
it does according to the definition that the tripfag gave
>>
>>51300297
His definition was incomplete but not completely incorrect.

I'm not arguing the semantics of scripting vs interpreted languages, just that they're both still considered to be programming languages.
>>
>>51300297
The key point of "scripting language" is to use it as a term of derision. It's never seriously used in any other way since it really has no meaning.
>>
>>51300371
It's a good term though, it describes the kind of language that you'd write a quick file renamer or website scraper in
>>
python and JS are compiled languages

>>51300003
don't you love the D?
>>
>>51300381
>my interpretation of the term is good though so everyone should just listen to me
'kay
>>
>>51300406
>python and JS are compiled languages

No they're not, compiled language implies that they're compiled directly into native machine code. They're "compiled" into bytecode, which is then interpreted (and possibly JIT compiled) by a virtual machine process
>>
>>51300406
I love the D, it makes mine super hard
>>
>>51300436
>No they're not, compiled language implies that they're compiled directly into native machine code
no it doesn't
>>
>>51300455
>https://en.wikipedia.org/wiki/Compiled_language
>The term is somewhat vague; in principle any language can be implemented with a compiler or with an interpreter. A combination of both solutions is also common: a compiler can translate the source code into some intermediate form (often called bytecode), which is then passed to an interpreter which executes it.

OK yes in some sense Python and JS are compiled, but the end step is an interpreter which is required for actual execution. I'd call that interpreted
>>
>>51300436
So you're saying that Java isn't compiled, even though you clearly have to run a compiler program on your source code
>>
>>51300497
Ok fuck you've got me there. Clearly it's less black and white than one would think
>>
c# has 1k page instruction book to read
c only 250 page
still c real hard to understand
Wtf, what is this shit?
>>
sup bros
just finished my first codeacademy course and I'm bored already
what do?
>>
>>51300525
MUH. DATA STREUFCKRTERESS
>>
>>51300421
just saying that it's not always a negative term, and some people use it in a positive context. you're getting pretty up in arms anon
>>
>>51300525
to understand C, you need to understand hardware/OS features, too, not just C
>>
>>51300556
C is easy, any idiot can do it.
#include <iostream>

double main (volatile long long int dataGoesHere) {
printf("Hi, World@\t");
return;
}
>>
>>51300189

When you run a python program, say via
python foo.py


Is the input file text or binary? In nearly all cases, it is text. That it is then translated to bytecode at runtime for better performance is irrelevant. The point is that at the program start, what is being run is the source.

By the way, Ruby and Perl are the same in this respect. What is distributed is text. What is run is text, but the interpreter compiles the text and then runs it, rather than having one program to compile it ahead of time, and then another to JIT compile it to native code.
>>
>get web dev internship
>its just fixing bugs for a web app that has so many nasty lines of code my eyes hurt

what have i gotten myself into /g/?
>>
>>51300590
you are not belong to here grey gandalf, go to web developer thread
>>
>>51300488
>the term is somewhat vague
stopped reading right there since it proves the point

also
>wikipedia
>>
>>51300615

but i thought we concluded javascript is programming?
>>
>>51300575
>C is easy, any idiot can do it.
>#include <iostream>
speaking about idiots...
>>
how to code crypter?
>>
>>51300622
*gives you a good ol' pat on the bum and sends you off to school*
>>
>>51300575
I can't tell if you're actually retarded or just pretending
>>
>>51300621
we are not, if you thought we are then you talked with someone else. i said
>programmer
>javascript
pick one.
>>
>>51300651
Why? Is it because I forgot
using namespace ptsd;

?
>>
>>51300302
>python2
>break
>global
>>
>>51300660
see >>51299387


this is now a meta-joke, meta-meme thread
>>
>>51300691
yea that is me, you mad scripter ? you should talk like, i dont care what you think, im a programmer. or post your total income to convince us ^^
>>
>>51300581
>That it is then translated to bytecode at runtime for better performance is irrelevant. The point is that at the program start, what is being run is the source.
The differences you are willing to ignore are larger than the similarities you wish to accept.
>>
>>51300720
why would I be mad? I can code all my programs in bash and get all the benefit of a C program
>>
>>51300660
Nice bait.
>>
>>51300763
lol
>>
>>51300792
how can it be a bait, if its my real opinion?
>>51300763
kek, scripter is funny guy though
>>
>>51300837
Define programming then.
>>
>Argument over semantics
I'll be out for awhile, call me when it's over
>>
>>51300847
#define programming
>>
>>51300870
#define define
>>
>>51300865
why don't you start a shitstorm over syntax instead faggot coward bitch
>>
>>51300847


if (programming != javascript)
{
System.out.println("Congrats!");
}
else
System.out.println("Not a real programmer fampai");


>>
>tfw whenever i talk to programmers in real life im too embarrassed to ask if they post on /g/ too
>>
>>51300923
Nice argument, faggot.
>>
>>51300741

Tell me what it is I am overlooking then. I provided a definition for a scripting language that concerns not the structure of the programs that utilize it, but the means by which programmers utilize their programs. If the input file to python is a source file, and the output is not necessarily either an error or a bytecode interpretation of that source file, then what is being run is a script. Anything else is an optimization.
>>
>Also, what's your favorite data type?
the abstract representation of another data type
>>
Why should I use one or the other convention?
mVariable;

this.variable;
>>
>>51300923
isnt that backwards?
>>
>>51300983
I think you mean
this->variable;
>>
>>51300581
$ nuitka foo.py
$ foo.exeW the
>>
>>51300999
Checked, but why should I use it over
mVariable
?
>>
>>51300763
Enjoy your fork() overhead.
>>
>>51298922
Code a GUI interface to trace his IP!
>>
>>51301007
>foo.exeW the
typo, blaming my phone's autocorrect
>>
>>51298925
I like both :3
>>
>>51301029
I prefer mVariable (or m_variable desu senpai), just pointing out that this is a pointer.

As for why, because
x.variable()
is less shit than
x.getVariable()
and using a prefix means the names won't collide.
>>
>>51301029
if it's ambiguous

struct muhOOP {
int var;
int muh_function(int var) {
return var + this->var;
}
}
>>
Trying to debug a vim plugin that defines syntax highlighting for homoglyphs.

For whatever reason when ft is mail or markdown it highlight [kK] as well on top of the homoglyphs, it works properly when the ft is a programming language.

Confusion intensifies.
>>
>>51300622
>>51300651

>>>/reddit/
>>
>>51301092
ignore this I'm hi xD
>>
>>51298891

Learning frameworks. Not fun.
>>
>>51300954
There is no useful distinction. You already accepted "bytecode" as AOT then basically you're saying that C, C++, etc., are also "scripting" languages because the "compilers" are really compiling to an intermediate representation for an internal virtual machine. The rest is just "optimization." But this is a ridiculous viewpoint to try to maintain.

As AOT and JIT merge more and more the distinction between "scripting language" and other languages vanish. This is even more true for languages that are normally interpreted (by a virtual machine) but also have native-code compilation (e.g. java and ocaml, arguably R4RS scheme with stalin), and you have the perversion that native-code languages like lisp run on a lisp machine (or scheme run on the demo chip MIT made years ago) are somehow both a compiled language and a scripting language.

The distinction is just a matter of where someone wants to be derogatory for internet dicksizing and is of no practical value.
>>
can someone explain to me why the hell this is allowed to compile?
int main(void) {
int x = x;
}
>>
>>51301196
No idea
Can you?
>>
>>51301196
what are some reasons it wouldn't be allowed to compile?
>>
>>51301196
Declaration and assignment at the same time is just sugar.

int main(void) {
int x;
x = x;
}
>>
>>51301239
>>51301278
i understand this but i'm surprised the sugar syntax allows it since it's a possible typo and has no purpose

if it has a purpose well, that's why i'm asking "why is this allowed"
>>
When is a problem solvable?
I've found that problems are solvable when they are computable.
Something is computable when it can be represented by an algorithm.
For something to be an algorithm, it needs to consist of small and clear steps and also have a solution for every solvable problem.
Isn't this recursive?
>>
>>51301323
*For every solvable solution to the problem
>>
>>51301316
Exceptions to a rule -> clunky
This being the cause of a significant bug (i.e. one that alters the functioning of your program) -> very low

Analysis of +clunky VS -buggy = not worth it
>>
>>51301196
Compiler warnings would probably warn you about that, shame you don't enable them.
>>
File: lelfrog.jpg (78 KB, 793x794) Image search: [Google]
lelfrog.jpg
78 KB, 793x794
>mfw node tutorial on codeschool now
>>
>>51301426
i use -Wall, that's not the point
>>
>mfw there's a growing functional programing movement at work
>mfw we just added sbt (scala) to our builds
>mfw I will be leading a three day "Write yourself a Lisp" seminar
>mfw getting paid go write Haskell
Life's good bros
>>
>>51301426
-Wall -pedantic doesn't say anything.
>>
>>51298891
>16 bit
>>
>>51298891
Snake in Java
Boolean master race
>>
File: 1431361905005.jpg (419 KB, 554x2135) Image search: [Google]
1431361905005.jpg
419 KB, 554x2135
its very cool to be able to program but have no fucking use for the skill
>>
>>51301657

get a job?
>>
File: 0201734842.jpg (90 KB, 517x648) Image search: [Google]
0201734842.jpg
90 KB, 517x648
I don't use boost or STL.

What are C++ templates? How are they handled by llvm and stuff?

Are they a bad thing? What's the diff between C++ and a define in C?

What does I need to know about C++ templates before I use STL?
>>
Writing a generic packet parser in Python.
Rate my code, /dpt/

def mkpacket(name, fields):
class P(object):
_fields = fields

def __init__(self, **kwargs):
for k, v in kwargs.iteritems():
if k not in [f[0] for f in self._fields]:
raise KeyError

setattr(self, k, v)

def encode(self):
data = ''

for f, t in P._fields:
data += t.encode(getattr(self, f))

return data

@staticmethod
def decode(data):
consumed = 0
pkt = P()

for f, t in P._fields:
value, count = t.decode(data[consumed:])
consumed += count
setattr(pkt, f, value)

return pkt

P.__name__ = name

def getter(varname):
def _get(self):
return getattr(self, varname)
return _get

def setter(varname):
def _set(self, value):
setattr(self, varname, value)
return _set

for fname, field in fields:
vname = '_' + fname
setattr(P, vname, None)
setattr(P, fname, property(getter(vname), setter(vname)))

return P


EthernetPacket = mkpacket('EthernetPacket', [
('dst', MACAddressField),
('src', MACAddressField),
('ethertype', IntegerField(2)),
('payload', PacketField),
])
>>
>>51301682
yea but where?
>>
>>51301705

Pretty much anywhere.
>>
>>51301688
I won't rate so to speak but we can talk about it


Why a class inside a method? How do you plan on testing it?

How do you plan on being able to use the staticmethod decode if you can't access it?

Instead of using a getter and a setter, consider using an abstract base class for it:

https://docs.python.org/3/library/collections.abc.html

Also, it'd be helpful to see how your class is used in practice. How EthernetPacket would be used in practice.

It seems like what you're creating may be better suited for meta classes - however, I wouldn't recommend it. Metaclassing out stuff like that isn't as helpful, it's probably better off to go for readability.

If you need me to be more specific I can.
>>
>>51301687
Templates in C++ allow you to write routines for generic data types. Let's say you write a hashing algorithm that takes in a string. If you want to apply that algorithm that takes in a class of Truck you're going to have to write a new routine that has the same algorithm but it deals with only
Truck[/codes]s. You might be able to see that it's easy to get all sorts of redundant code that has the exact same algorithm applied to different data types. This is where C++ templates come in. Templates in C++ allows you to write routines that take in a generic type and then manipulate that generic type (as long as that kind of processing is logically sensible).
>>
>>51301688
>>51301752

BTW, I'd rather see you creating classes for this.

Consider creating a BasePacket class, then a BaseField class, and abstract those out.

BaseField and BasePacket can extend that ABC collection I linked to.

That will make the code a lot more readable, testable and maintainable.
>>
>>51301687
C++ templates are essentially a formalization of the macro system used in C. while they are still "text substitution," the substitutions are all formal types, and the templates are type variables

in 95% of cases this is used for type-generic programming. for example, the dynamic array class, vector, is really vector<Type>. when you declare a vector, you write vector<int> or vector<Waffle> or w/e the fuck, and the compiler does type substitution and generates code for vector<Waffle>. a more exotic case is tuple<...Types>, e.g. tuple<int,int,double>. this is all you need to know to use 95% of the standard library

templates can be used for fairly advanced library implementations. for example, you can template a functor (a type that implements operator() ) to pass templated code. this is what std::sort<Comparator> does, and is why C++ sort outperforms C's qsort (because the comparator is passed by substitution instead of a void pointer). the most advanced kind of template programming is metaprogramming, which you really shouldn't tackle if you don't know C++ well
>>
>>51301784
If I'm using these template systems, will I get autocomplete with stuff like clang_complete in vim still?

What about type safety?

What about debugging?

What about performance?
>>
>>51301784
>>51301773
>>51301687

Link me to some PDF's and tutorials on the basics of templating?

Is there such a thing as STL/Boost for C?
>>
>>51301784
a good example of simple metaprogramming is std::enable_if<bool,type>. if bool == true, then enable_if<true,type>::value == type. if bool == false, then enable_if<false,type>::value does not exist. so this lets you write code that tests for a compile-time condition, and only works if the condition is true (it's a little more complicated than that, but that's the idea)
>>
>>51301705

its 2015 theres tech companies literally everywhere
>>
>>51300615
hukd on fonikz wurkd fur mee
>>
>>51301810
C doesn't deal with templates so there is no standard template library for C. It's not idiomatic to do generic data programming in C so it's best to avoid this idiom when writing your C programs.
>>
I've been working for months on porting Space Invaders to my toaster oven in PHP. Almost done. Have a conference call with Google scheduled and I'm expecting an buyout offer.
>>
>>51301795
template programming is very standard and idk why any autocomplete would ignore it

it's type safe

it's notoriously hard to debug, except in simple generic type cases, which are frankly most cases. do not do anything more than generic types (e.g. vector<int>) unless you are very familiar with C++

performance is excellent at runtime (that's the whole point, to generate great code using static compile-time code generation instead of runtime type dispatch). however, performance is notoriously terrible at compile time

>>51301810
generic types in C are notoriously hard. you can use macro-generated code (e.g. #DECLARE_VECTOR(TYPE)) or unions for runtime polymorphism. both options suck desu

template programming beyond the simplest case is hard. the simplest case is easy, and is just:
template <typename Type>
class MyClass {
Type value;
...

Type is just a variable type
>>
>>51301726
>>51301827
So why haven't I been hired yet?
>>
>>51301894

cuz u dum as hellllllll son
>>
>>51298946
Twas a spoof, adnan.
>>
File: vb.jpg (175 KB, 1015x601) Image search: [Google]
vb.jpg
175 KB, 1015x601
How could I make it that, let's say I type dog in the textbox, it would take the first result of a google image search and show it in my picturebox?
>>
>>51301977
I'm sure thats the case

You guys literally have no proof that there are programming jobs, please post evidence that there are jobs before making these claims.
>>
IT BEGINS
namespace doric {

template <typename ...Ts>
class column_vector : {
public:
using wide_reference = std::tuple<Ts&...>;
private:
std::tuple<std::vector<Ts>...> columns_;
>>
>>51302065
The trolling is strong with this one.
>>
It sure is a lot of fun programming and not being paid to do it.
>>
>>51302115
?
>>
>>51302072

>no proof that there are programming jobs

lol wut
>>
praise based k&r
main(argc, argv)
char **argv;
{
extern puts();
puts("Hello, world!");
}
>>
File: 1429250603669.png (84 KB, 1000x1000) Image search: [Google]
1429250603669.png
84 KB, 1000x1000
why is python so shit
there's always some gotcha that I have to work around
>>
I often see a 'swap' method in the pseudocode of certain sorting algorithms. Is there a built-in method for swap in c# or do you have to define it yourself?
>>
>>51301841
>It's not idiomatic to do generic data programming in C so it's best to avoid this idiom when writing your C programs.

Good thing generics are never necessary. :^)
>>
>>51301752
>>51301782
Abstract base classes are where I came from, but it gave a lot of boilerplate code when I had to implement getters and setters for properties all the time.
Classes like the ones in SQLAlchemy are what I aimed for, but I couldn't get the properties to work that way.
It would have been better if I could make a class like this:

class EthernetPacket(LinkLayerPacket):
structure = [
('dst', MACAddressField),
('src', MACAddressField),
('ethertype', IntegerField(2)),
('payload', PacketField),
]


The order is important, so that's why I used a list.
If I make the properties and variables without this reference, I have to write an encode and a decode function for each protocol.
When it comes to using these classes, they will be used in a receive loop, eg

while True:
data = self.sock.recv(self.mtu)
pkt = EthernetPacket.decode(data)

if self.promiscuous or pkt.dst in self.addresses
rxqueue.put(pkt)


I'm still looking into descriptors (__get__ and __set__), because when the *Fields inherit that from the Field superclass.
That would pretty much give the behavior I want.
I didn't encounter any problems testing it though.
>>
>>51302248
I mean swapping of elements in an array
>>
>>51302065

Doesn't Jewgle have an API?

>>51302248
>Is there a built-in method for swap in c# or do you have to define it yourself?

There isn't one, as far as I know (and MSDN seems to confirm that.) You could implement it fairly simply as an extension method.
>>
File: 1442803817321.jpg (18 KB, 218x213) Image search: [Google]
1442803817321.jpg
18 KB, 218x213
So apparently python has type hinting now?
def greet(name: str) -> str:
return "Hello, " + name

def sum(lst: List[int]) -> int:
cunt = 0
for i in lst:
cunt += i
return cunt

Still completely worthless and a nonthing.
>>
Hey /dpt/ I'm trying to read multiple txt files with Java scanner. The issue I'm having is that Scanner requies a new scanner object everytime I need to read a different file. Isn't it highly inefficient to have 900 scanner objects in memory if I have 900 txt files? I'm trying to read 2 txt file at a time, compare, delete from main memory then load in another 2 txt file, repeat. I know I can use scanner.close() but does it also require something to flush the input stream like BufferedReader?
>>
>>51302249
There are situations when it's useful to have algorithms that work on generic data. During system analysis, if I strongly suspect that I will need to be working with generic data in a "significant" manner, I would reconsider my usage of the C language to solve the problem. Other languages that I'd consider would include Scheme, C++ and Python.
>>
>>51302284
I believe there is one but desu I'm a total noob and don't really know what I would do with an API
>>
>>51302333

As denoted by the ':^)' interpretation hint, I was joking.

Glad you're staying sharp, though.
>>
>>51295342
>that's redundant; also float is not guaranteed to be 32 bits nor double to be 64 bits
yes they are (pic)

https://en.wikipedia.org/wiki/Single-precision_floating-point_format
https://en.wikipedia.org/wiki/Double-precision_floating-point_format
>>
import qualified Data.Sequence as S

data Card = CA|C2|C3|C4|C5|C6|C7|C8|C9|C10|CJ|CQ|CK deriving (Show,Eq)

pairsWith :: Card -> Maybe Card
pairsWith CA = Just C10
pairsWith C2 = Just C9
pairsWith C3 = Just C8
pairsWith C4 = Just C7
pairsWith C5 = Just C6
pairsWith C6 = Just C5
pairsWith C7 = Just C4
pairsWith C8 = Just C3
pairsWith C9 = Just C2
pairsWith C10 = Just CA
pairsWith _ = Nothing

prop_mutualPairs :: Bool
prop_mutualPairs = all prop_mutualPairs' [CA,C2,C3,C4,C5,C6,C7,C8,C9,C10,CJ,CQ,CK]

prop_mutualPairs' :: Card -> Bool
prop_mutualPairs' c = case pairsWith c of
Just d -> Just c == pairsWith d
Nothing -> c `elem` [CJ,CQ,CK]

getTriple :: S.Seq Card -> Maybe (Int,Int,Int)
getTriple xs = do
let is = S.findIndicesL (`elem` [CJ,CQ,CK]) xs
(i1,is') <- unconsMay is
(i2,is'') <- unconsMay is'
(i3,_) <- unconsMay is''
return (i1,i2,i3)

getPair :: S.Seq Card -> Maybe (Int,Int)
getPair cs = case getFirstPair cs of
Just i -> Just (0,i)
Nothing -> do
(_,xs) <- seqUnconsMay cs
(i1,i2) <- getPair xs
return (i1+1,i2+1)

possibleMove :: S.Seq Card -> Maybe [Int]
possibleMove cs = case getTriple cs of
Just (i1,i2,i3) -> Just [i1,i2,i3]
Nothing -> case getPair cs of
Just (i1,i2) -> Just [i1,i2]
Nothing -> Nothing

makeMove :: [Int] -> ([Card], S.Seq Card) -> ([Card], S.Seq Card)
makeMove [] x = x
makeMove _ ([],x) = ([],x)
makeMove (i:is) (c:cs, x) = makeMove is (cs, S.update i c x)

solve :: [Card] -> S.Seq Card -> Maybe (S.Seq Card)
solve [] x = Just x
solve (c:cs) x | S.length x < 9 = solve cs (x S.|> c)
solve cs x = do
move <- possibleMove x
let (cs', x') = makeMove move (cs, x)
solve cs' x'

getFirstPair :: S.Seq Card -> Maybe Int
getFirstPair cs = do
(x,xs) <- seqUnconsMay cs
y <- pairsWith x
S.elemIndexL y cs


(Too long to fit definitions of unconsMay and seqUnconsMay. They do the obvious.)
>>
File: hk.png (547 KB, 256x256) Image search: [Google]
hk.png
547 KB, 256x256
Generally speaking how would one handle an app/game that uses hundreds of textures?

Read in a file containing all the info then store them in a container?
How am I supposed to know exactly which one I need to work with?
>>
>>51302176
You have to become gotcha.
>>
#include <iostream> 
using namespace std;

int main()
{
int month, year, day;

//Explanation of what inputs are valid
cout << "Please no negative numbers. Month range: 1-12 and day range: 1-30 \n";
//the day of a month
cout << "Enter a day in numeric form \n";
cin >> day;
//The month of the year
cout << "Enter a month in numeric form \n";
cin >> month;
//The last two digits of the year
cout << "Enter the last two digits of the year \n";
cin >> year;
//Choices as to month*year equals or does not equal year.
if ((month <= 0 || month > 12 ) || (day <= 0 || day >= 13))
{
cout << "Invalid entry. \n";
}
else if (year != (month*day))
{

cout << "The date is not magic \n";
}
else if (year = (month*day))
{
cout << "The date is magic \n";
}

return 0;
}


Rate code for someone who is taking a c++ introductory course.
>>
File: wojak crying.jpg (35 KB, 535x577) Image search: [Google]
wojak crying.jpg
35 KB, 535x577
>mfw Java has infected my brain to the point where it's a natural tendency to NameEverythingLikeAJavaEnterpriseProgrammmer
looking at my own code makes me want to barf
>>
>>51302518
your last else if should just be else, as if the program flow gets to the last else if, it will _always_ be true.
>>
>>51302072
do your own damn employment research faggot
>>
File: Capture.png (842 KB, 588x671) Image search: [Google]
Capture.png
842 KB, 588x671
>>51302065
C# but should be easy enough to rewrite it in VB.Net
using System;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Drawing;

namespace GoogleImages
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void searchButton_Click(object sender, EventArgs e)
{
WebClient wClient = new WebClient();
string url = "https://www.google.com/search?tbm=isch&q=" + queryTextBox.Text;
wClient.Headers.Add("User-Agent: Mozilla/5.0 (Windows NT 6.2; Win64; x64;) Gecko/20100101 Firefox/20.0");
string pageSource = wClient.DownloadString(new Uri(url));
string firstImage = pageSource
.Split(new string[] { "/imgres?imgurl=" }, StringSplitOptions.None)[1]
.Split(new char[] { '"', '&' })[0];
imageUrlTextBox.Text = firstImage;
var imageData = wClient.DownloadData(firstImage);
var imageStream = new MemoryStream(imageData);
imageBox.Image = (Bitmap)Image.FromStream(imageStream);
}

}
}
>>
>>51298891
Currently in the planning phase (10th week,getting very close to prototyping) a semi-p2p file sharing social networking esque platform. I'm very excited to begin. Other than that pushing tests. Woo
>>
>>51302565
>10th week of 'planning'
>no implementation at all
doomed to fail
>>
>>51302343
Make api calls to it :^)
>>
>>51302258

The setters and getters could be worked around for via using the abc collect I linked to.

When you say classes like in sqlalchemy, do you mean you're trying the mimic declarative?

Are you sure it wouldn't be better just to follow my original advice on how to structure it? Do you have a response to that?

Regarding order, there is an OrderedDict class,

but also, I think it may be beneficial to just rely on keyword arguments and etc. first. It may be overengineering to try to do meta classes at this point.

when sqlalchemy was being developed, they figured out the data they were dealing with and the imperative kinks first, developing the sqlalchemy core. only after did they have enough confidence in the domain to understand the need of constructing things declaratively

unless the goal of the project is to learn more about metaclasses, if you want to create something useful and leave open the option to add metaclasses correctly, i'd figure out how to get the simple things organized with a normal class/subclass hierarchy - then make factories/classmethods.

after you're solid on that, see how much taking the sqlalchemy declarative-like route makes sense.
>>
anyone with template experience know what's wrong here?
  using wide_reference = std::tuple<std::vector<Ts>::reference...>;

doric.cpp:9:66: error: type/value mismatch at argument 1 in template parameter list for ‘template<class ...> class std::tuple’
using wide_reference = std::tuple<std::vector<Ts>::reference...>;
^
doric.cpp:9:66: error: expected a type, got ‘std::vector<Ts, std::allocator<Ts> >::reference ...’

i'm confused because std::vector<Ts>::reference looks like a type to me?
>>
>>51302576
>implying there is no implementation
K babe. Go back to the car.
>>
>>51302539

thanks.
>>
>>51302471
you need a map from texture ID to texture. texture ID could be a string, or it could be some kind of enumeration. then you use the IDs in your code

there's various details you might want such a map to have, such as out-of-memory caching, but that's the basic idea
>>
File: meme.jpg (310 KB, 1280x840) Image search: [Google]
meme.jpg
310 KB, 1280x840
It's time for some maymays.
>>
>>51302660
1/10 at most.
>>
>>51302634
I see. Thanks broski.
>>
>>51302679
I didn't make it, fucklord
>>
>>51302576
Planning and analysis is fundamental to every project. It's always crucial to get this correct otherwise the code that comes afterward can be rendered meaningless when you find that the foundations need to be changed.
>>
>>51302660
objective-c sucks
>>
File: 1359063158735.jpg (315 KB, 800x1100) Image search: [Google]
1359063158735.jpg
315 KB, 800x1100
>>51302660
>>
im retard
>>
>>51302606
fixed it
std::tuple<typename std::vector<Ts>::reference...>

it's possible i may be the devil
>>
c average high school graduate learning python in codeacademy. its boring as fuck, what are some hands on resources i can use to learn python??. i know nothing about technology but would like to code of those nifty browser games some day.
>>
File: 1443313963536.png (25 KB, 958x229) Image search: [Google]
1443313963536.png
25 KB, 958x229
>>51302727
>>
>>51302765
>programming because wants to code gamez
you are the cancer
Thread replies: 255
Thread images: 24

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.