Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
JawnV6
Jul 4, 2004

So hot ...

TooMuchAbstraction posted:

Sorry, my bad: I saw "char" and leapt to thinking about strings instead of remembering that it's another term for "byte". It's Friday and I'm, evidently, more tired than I'd realized.
I, too, am at the end of a rough week and was harsher than necessary. My apologies.

If y'all are interested in a deep dive into what you could do with 4-byte floats and 8-byte doubles that only hold integers, the Underhanded C winner was recently announced with a very good writeup.

Adbot
ADBOT LOVES YOU

SurgicalOntologist
Jun 17, 2004

Can anyone suggest a resource for legal issues surrounding programming, specifically intellectual property?

My partner and I are in the very early stages of developing a kind of consultancy data analysis project. We have a "client" who's giving us data that we can use to develop our ideas, and they want us to sign something like an NDA. It's quite reasonable that we don't share their data, or the results of our analysis, but we don't want to accidentally give them rights to our actual project or be prevented from working with their competitors in the future.

As a complicating factor, this is all international and I'll be relying on translation (my partner speaks their language).

The right answer is probably to ask a lawyer, but we don't even have a budget. Is there some kind of primer out there we can read so we're at least aware of the basic issues?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I'm sure you can find several lawyers who will give you 30-60 minutes of their time to see if you want to become their client. You probably shouldn't go around to every firm in town abusing that introductory time, but if you're upfront with them I'm sure you can get some advice and maybe know who to turn to down the road.

SurgicalOntologist
Jun 17, 2004

That makes a lot of sense, don't know why we didn't consider that.

yippee cahier
Mar 28, 2005

HappyHippo posted:

Fun fact about unions: writing to one field and then reading off the other is technically "undefined behaviour," even though it'll probably work in most modern compilers. Here's some random post I found on the internet which basically concludes that the memcpy solution is the best one.

A good blog to follow if you like the subject. Lots of stuff on safety in C with a focus on using modern tools.

crunk dork
Jan 15, 2006
I'm trying to learn C in my downtime at work, and I'm doing ok with the first chapter I guess, but a lot of the exercises I get stumped on and have to look at some solutions to see what they are even looking for. Is the entire book going to be hard for me and should I maybe look at a more introductory book?

I'm not completely new to reading and writing code but the stuff I've done has been primarily HTML and CSS, really basic stuff that isn't as logically intensive.

E: I'm reading K&R C Programming Language 2nd ed.

crunk dork fucked around with this message at 17:34 on Feb 8, 2016

feedmegin
Jul 30, 2008

crunk dork posted:

I'm trying to learn C in my downtime at work, and I'm doing ok with the first chapter I guess, but a lot of the exercises I get stumped on and have to look at some solutions to see what they are even looking for. Is the entire book going to be hard for me and should I maybe look at a more introductory book?

I'm not completely new to reading and writing code but the stuff I've done has been primarily HTML and CSS, really basic stuff that isn't as logically intensive.

E: I'm reading K&R C Programming Language 2nd ed.

Why C? Going to that directly from HTML/CSS (i.e. not an actual imperative programming language) is going to be pretty rough compared to, I dunno, Python.

crunk dork
Jan 15, 2006
I had it in my head that learning a lower level language first would help me understand more of the building blocks of a higher level language but maybe I'm thinking backwards? I've got a book on Python from Oreilly as well but haven't touched it yet.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

crunk dork posted:

I had it in my head that learning a lower level language first would help me understand more of the building blocks of a higher level language but maybe I'm thinking backwards? I've got a book on Python from Oreilly as well but haven't touched it yet.

Are you familiar with JavaScript? Maybe start doing some more involved JS work, and go from there. At least with JS, you'll be able to make connections to your HTML/CSS work and see practical value, instead of it all being abstract & theoretical. If you DO have some JS experience and want to broaden from there, check out C#/Java. It's a more strongly typed language, but still does things like garbage collection and memory management for you. Jumping straight into C is a big jump, and probably won't be providing much of a benefit to your actual job for some time.

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug

crunk dork posted:

I had it in my head that learning a lower level language first would help me understand more of the building blocks of a higher level language but maybe I'm thinking backwards? I've got a book on Python from Oreilly as well but haven't touched it yet.

It will once you learn your first language first. I'd head to Javascript land if you are doing HTML/CSS. Then either K&R or the Python book. Going full C you are basically being dumped out in the middle of the Pacific ocean instead of the deep end of the pool.

EDIT: ^^^ Argh beat but yeah C is hard to get into and not very useful for most work.

crunk dork
Jan 15, 2006
Right on guys. I don't actually do HTML/CSS for work but instead used to do it as a hobby kind of. I do more IT network admin type stuff at my job and am trying to get into infosec and pentesting so that's why I'm trying to learn, if that has any bearing on suggestions.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

crunk dork posted:

Right on guys. I don't actually do HTML/CSS for work but instead used to do it as a hobby kind of. I do more IT network admin type stuff at my job and am trying to get into infosec and pentesting so that's why I'm trying to learn, if that has any bearing on suggestions.

I would suggest starting with C#/Java/Python then. Mainly C#, but that's just me. Microsoft has really turned over a new leaf and the .net framework is looking very good lately, but all three of those you should be able to jump into a lot easier than C and will be exposed to almost all important CS concepts.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

crunk dork posted:

Right on guys. I don't actually do HTML/CSS for work but instead used to do it as a hobby kind of. I do more IT network admin type stuff at my job and am trying to get into infosec and pentesting so that's why I'm trying to learn, if that has any bearing on suggestions.

Of the people that I know that do pentesting, none of them use C. They mostly use collections of python/perl scripts that have evolved to support different use cases throughout the years.

I think C# is a great language (though I'm biased because I use it everyday), but I don't know that it's going to help you much in the fields you're aiming for.

Neslepaks
Sep 3, 2003

I don't see why he shouldn't learn C if he wants to, or indeed why he couldn't learn it from K&R2. I did, and lord knows I'm not the brightest star in the night sky.

Maybe skip some of the exercises as there are a lot of difficult ones and instead keep on reading. Go back to them later when you have a better understanding if you want, but it's probably more fun to work on something of your own devising.

One tip I guess is to read very carefully and re-read parts since the book is much more terse than a lot of other programming books (my copy's chapter on pointers and arrays is noticeably more yellowed from wear than the rest of the book). :)

Fergus Mac Roich
Nov 5, 2008

Soiled Meat
K&R 2nd edition was my first programming book as well. It works just fine and, indeed, working on their exercises and mastering C concepts such as pointers will make a lot of tricky concepts seem trivial in the future("Is Java pass by reference or pass by value?"). I don't think it's the most fun or efficient way to learn a real programming language, but it totally works, even for a total beginner.

I have 2 Python books from O'Reilly. One is Learning Python, the other is Programming Python. Programming Python is an awesome book that is totally not suitable for beginners. Learning Python I have mixed feelings about. They do deep dives into every single basic Python language feature in order. That's very informative as a reference for a beginner, but it's not necessarily a book you can read cover to cover to learn Python.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

The Python thread normally recommends Think Like a Computer Scientist or Learn Python the Hard Way.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Neslepaks posted:

I don't see why he shouldn't learn C if he wants to, or indeed why he couldn't learn it from K&R2. I did, and lord knows I'm not the brightest star in the night sky.

Maybe skip some of the exercises as there are a lot of difficult ones and instead keep on reading. Go back to them later when you have a better understanding if you want, but it's probably more fun to work on something of your own devising.

One tip I guess is to read very carefully and re-read parts since the book is much more terse than a lot of other programming books (my copy's chapter on pointers and arrays is noticeably more yellowed from wear than the rest of the book). :)

No one is saying he can't, but his original post mentioned he was getting stumped and asked for suggestions on a better way. Going from almost zero programming experience to straight C without any formal CS or math background is tough, and something like C# or Python would probably be easier.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

crunk dork posted:

Right on guys. I don't actually do HTML/CSS for work but instead used to do it as a hobby kind of. I do more IT network admin type stuff at my job and am trying to get into infosec and pentesting so that's why I'm trying to learn, if that has any bearing on suggestions.

If you're looking at pentesting your best bets are python and ruby so you can write metasploit modules.

crunk dork
Jan 15, 2006
Think I'm going to put the breaks on C for now after all the input and dig into the python book I have. Thanks all for the advice

Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies
Does anyone have any knowledge of using document cameras with some command line/programming interface and not the document camera's own software (maybe using OpenCV or something of the ilk)? Our use case is getting the data from a camera and would hopefully import the png image from the camera into a python application to undergo further processing. Pretty much all of the things I've seen are for regular cameras and then document cameras only talk about their own software to use it.

fritz
Jul 26, 2003

Master_Odin posted:

Does anyone have any knowledge of using document cameras with some command line/programming interface and not the document camera's own software (maybe using OpenCV or something of the ilk)? Our use case is getting the data from a camera and would hopefully import the png image from the camera into a python application to undergo further processing. Pretty much all of the things I've seen are for regular cameras and then document cameras only talk about their own software to use it.

I've only used the c++ bindings, but reading from a camera in opencv is fairly non-terrible. You just instantiate a cv::VideoCapture object (with an integer index indicating which camera you want), and then just call the .read method to populate a cv::Mat. Depending on your camera you might need to .set() parameters on the object. It's pretty easy, just give it a go and see what happens.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Neslepaks posted:

I don't see why he shouldn't learn C if he wants to, or indeed why he couldn't learn it from K&R2.
The only 'bad' thing with C is that these days it's hard to 'make something' with just C

It's a base to go to something like C# or Objective-C if he wanted to, though.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Bob Morales posted:

The only 'bad' thing with C is that these days it's hard to 'make something' with just C

It's a base to go to something like C# or Objective-C if he wanted to, though.

I mean, if he eventually wants to do systems or embedded stuff, C is still pretty useful, but outside of that you probably want something with a strong framework built in, yeah.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
So recently me and some programmer friends were talking about the new idiotic operator font: http://www.engadget.com/2016/02/09/operator-font-hoefler-co/

To sum it up, yes that is an ugly rear end font selling for $200 marketted towards programs which uses both cursive and non-cursive fonts seemingly at random and it is loving god awful in terms of readability.

So I was wondering, does anyone have any font recommendations? I just use atom as my editor and whatever its default is I find incredibly readable.

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
Monaco and Inconsolata are my two favorites for coding, but I use Letter Gothic Powerline in the terminal

Sinestro fucked around with this message at 22:06 on Feb 11, 2016

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Source Code Pro

aerique
Jul 16, 2008
Terminus

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
comic sans.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
If on Windows then Consolas, if not on Windows then steal Consolas from an available Windows machine (or use DejaVu Sans Mono).

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

I use Consolas everywhere.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Thermopyle posted:

Source Code Pro

This is the only correct answer. If on OS X use the powerline version.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Menlo

Inconsalata

Anonymous Pro

Consolas

Lucida Console

Shaman Tank Spec
Dec 26, 2003

*blep*



I'm banging my head against Haskell's typeclasses and instances. I've read the chapters on Learn You A Haskell and Real World Haskell and I thought I understood how these things are supposed to work, but evidently I understand nothing.

Let's say I'm trying to make a typeclass for large numbers. A number is large if it's an Int with a value of over 10 000.

code:
class LargeNumber a where
  isLarge :: a -> Bool
So far so good, right? Now, I understand that every instance of LargeNumber has to implement isLarge somehow. But how do I actually do that?

Trying something like
code:
instance LargeNumber Int where
  isLarge > 10 000 = True
  isLarge _ = False
Gives all kinds of errors. For instance, "'>' is not a (visible) method of class 'LargeNumber'", so I guess I should somehow say that LargeNumber Int derives Ord? But how? I can't redefine Int as a data type and that's where I should be doing it, right?

And if I try to kludge it by saying
code:
instance LargeNumber Int where
  isLarge 10001 = True
  isLarge _ = False
(which I know is not what I want to do here, I'm just trying to figure this out step by step) it complains that there's "no instance for (Num a) arising from the literal 10001".

I must be miles away from the correct solution, but I just can't figure out how this is supposed to work.

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
You're going to want something more like

code:
instance LargeNumber Int where
  isLarge x = x > 10000
It's just like any other function definition.

Shaman Tank Spec
Dec 26, 2003

*blep*



Asymmetrikon posted:

You're going to want something more like

code:
instance LargeNumber Int where
  isLarge x = x > 10000
It's just like any other function definition.

OK, thanks! That helps some. I'm still getting the same "No instance for (Num a) arising from the literal 10001" errors when I'm trying to test this, though.

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
That's because 10001 isn't an Int (automatically), it's an Integer - the arbitrary precision number integer type (yes, this is confusing - Haskell has some baggage it can't shake off.)

Either you really want an instance of LargeNumber for Integers, or you need to make sure the numbers you're checking are Ints.

code:
instance LargeNumber Integer where
  isLarge x = x > 10000

Main> isLarge 10001
True
-- 

Shaman Tank Spec
Dec 26, 2003

*blep*



Asymmetrikon posted:

That's because 10001 isn't an Int (automatically), it's an Integer - the arbitrary precision number integer type (yes, this is confusing - Haskell has some baggage it can't shake off.)

Yeah, this poo poo keeps tripping me up constantly in Haskell and it's horribly frustrating trying to navigate a maze of similar but not replaceable types and values.

Right, so that works then. But if I try "isLarge -5" or indeed any negative number, I get a "Non-type variable argument" error, however "isLarge (-5)" produces the expected result. So I guess if I don't enclose negative Integers in brackets, Haskell interprets the - symbol as the mathematical subtraction operation? I gotta say this poo poo isn't intuitive at times :v:

E: I mean if I was REALLY GOOD at Haskell, it would probably be an incredibly powerful and elegant language, but right now it's immensely frustrating. 95% of my time seems to be spent trying to cajole types so that Haskell likes them.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Der Shovel posted:

Yeah, this poo poo keeps tripping me up constantly in Haskell and it's horribly frustrating trying to navigate a maze of similar but not replaceable types and values.

Right, so that works then. But if I try "isLarge -5" or indeed any negative number, I get a "Non-type variable argument" error, however "isLarge (-5)" produces the expected result. So I guess if I don't enclose negative Integers in brackets, Haskell interprets the - symbol as the mathematical subtraction operation? I gotta say this poo poo isn't intuitive at times :v:

E: I mean if I was REALLY GOOD at Haskell, it would probably be an incredibly powerful and elegant language, but right now it's immensely frustrating. 95% of my time seems to be spent trying to cajole types so that Haskell likes them.

Yeah the - thing is a thing that trips up a lot of people new to Haskell. It's pretty isolated though, - is the only unary operator in Haskell and the choice, while annoying, makes the rest of the syntax in the language more clear and consistent.

Back to your other problem, you can also do

code:
instance LargeNumber Int where
  isLarge x = x > 10000

isLarge (10001 :: Int)
or

code:
x :: Int
x = 10001

isLarge x
Basically as long as the code knows it's an Int it will work.

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
It's a precedence issue - if you try to execute "1 + -1", it also won't work. (-) is both the unary negation and the subtraction operator, so "-5" is really "(-) 5".

You can do something like "isLarge $ -1" (the dollar sign is a low-binding application operator - basically a left paren that stretches to the end of the expression), or the parentheses, but there's never really much call for putting literals like "-100" directly in a bigger expression, so it doesn't end up being a big problem.

Adbot
ADBOT LOVES YOU

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
If the types are tripping you up, and you aren't married to Haskell itself, you could try learning Elm. It's pretty similar in the basics, and it has a lot more sane basic types.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply