• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

What are you trying to do with temp? If it's an uninitialized variable and you don't have Option Explicit on, it will default to 0 and your comparison be true when linkcash doesn't contain 2014-04. You're essentially saying

Code:
If 0 = 0 Then
    MsgBox "April 2014"
End If

I'm just using it as a variable to hold the value of 0 or whatever it finds. Can I just do linkcash = instr(etc....?

Do I have to give a default value? I declare it as a string but then I get my error message of invalid date...
 
I'm just using it as a variable to hold the value of 0 or whatever it finds. Can I just do linkcash = instr(etc....?

Do I have to give a default value? I declare it as a string but then I get my error message of invalid date...

VBA doesn't let you assign a variable in an If statement. In fact, that's a bad idea even in languages that let you do it.

I think you probably didn't declare it as a string because if you had, you'd be getting a type mismatch error.

I'm not sure why you want to save the result of the InStr function, but if that's what you actually want to do, you would write something like this.

Code:
temp = InStr(linkcash, "2014-04")
If temp <> 0 Then
    MsgBox "April 2014"
End If
 
VBA doesn't let you assign a variable in an If statement. In fact, that's a bad idea even in languages that let you do it.

I think you probably didn't declare it as a string because if you had, you'd be getting a type mismatch error.

I'm not sure why you want to save the result of the InStr function, but if that's what you actually want to do, you would write something like this.

Code:
temp = InStr(linkcash, "2014-04")
If temp <> 0 Then
    MsgBox "April 2014"
End If

How do you write it without saving then? At most I'd save the output of "march 2014" or whatever
 
How do you write it without saving then? At most I'd save the output of "march 2014" or whatever

I think someone posted something like this already.

Code:
Dim month_id As String

If InStr(linkcash, "2014-04") <> 0 Then
    month_id = "April 2014"
ElseIf InStr(linkcash, "2014-05") <> 0 Then
    month_id = "May 2014"
ElseIf InStr(linkcash, "2014-06") <> 0 Then
    month_id = "June 2014"
' And so on...
End If

MsgBox month_id
 
I think someone posted something like this already.

Code:
Dim month_id As String

If InStr(linkcash, "2014-04") <> 0 Then
    month_id = "April 2014"
ElseIf InStr(linkcash, "2014-05") <> 0 Then
    month_id = "May 2014"
ElseIf InStr(linkcash, "2014-06") <> 0 Then
    month_id = "June 2014"
' And so on...
End If

MsgBox month_id

Awesome, that saved a colossal headache. Thank you all so much for the help.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
I assume flexibility? High programming languages usually give less flexibility in how to do things no? I'm pretty sure it also takes a lot more overhead to run because its high level and not low level that you can control more but is more time consuming to write.

It's an interpreted language, so it's not exactly lightning fast. Also while dynamic typing is a godsend in smaller programs, it makes stuff unnecessarily error prone in bigger projects.

-Python code relies a lot on libraries, and in the past Python has been more willing to change built-in library APIs in ways that break legacy code.
-More reliance on dynamic error checking and less on static analysis.
-Performance and memory use may be worse than languages that compile to native machine code.
-Attaching semantic significance to whitespace can cause problems if you are not careful.

Awesome. Thanks for the info guys.
Never knew those things about Python.
 

oxrock

Gravity is a myth, the Earth SUCKS!
-Attaching semantic significance to whitespace can cause problems if you are not careful.

I'd like to point out that due to python's spacing, code is innately neater and far easier to read as a result. Sadly it can be buggy and annoying at times, take the good with the bad I guess.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
I'd like to point out that due to python's spacing, code is innately neater and far easier to read as a result. Sadly it can be buggy and annoying at times, take the good with the bad I guess.

You may have seen this, but I came across this book on r/programming today written by a guy from EA. It's focused on design patterns related to game programming, so you might find it useful.

http://gameprogrammingpatterns.com/index.html
 
I am currently (for study purposes) transfering old C code to C++ and even though I never thought I say that but there is something I miss in C++ which was done easier/better (probably not safer) in C.

Basicly I have a few memory locations like: a register [0x00] with the mem content = 0x000A for example. In the original code I simply used:

Code:
printf("R%02X:%04X ", reg, mem[loc]);

to get an output like --> R00: 000A. In C++ however this doesn't work as easy and it took me some time until I found that I have to use setw/setfill to achieve the same result.

C++ code:

Code:
cout  << "R" << setw(2) << setfill('0') << hex  << reg << ":";
cout  << setw(4) << setfill('0') << hex << mem[loc] << " ";

Or is there a simpler way to achieve the same level of output/format? I agree it is just more code and not that hard to understand but I thought maybe someone finds it interesting aswell.
 

Minamu

Member
Does anyone in here have Unity3D experience? The Learn Unity thread is pretty much dead :/ I'm using C#. I want to make an inanimate object move along a pre-determined path (not just from x to y). In UDK I'd probably animate this in Matinee but I'm not sure if Unity have that kind of functionality? Basically, I have a train that is supposed to follow a road or railroad track, and the player is supposed to choose which crossroads track the train travels on (in real-time).
 

oxrock

Gravity is a myth, the Earth SUCKS!
Does anyone in here have Unity3D experience? The Learn Unity thread is pretty much dead :/ I'm using C#. I want to make an inanimate object move along a pre-determined path (not just from x to y). In UDK I'd probably animate this in Matinee but I'm not sure if Unity have that kind of functionality? Basically, I have a train that is supposed to follow a road or railroad track, and the player is supposed to choose which crossroads track the train travels on (in real-time).
This is definitely the place to go to ask unity related questions.
 

Water

Member
Does anyone in here have Unity3D experience? The Learn Unity thread is pretty much dead :/ I'm using C#. I want to make an inanimate object move along a pre-determined path (not just from x to y). In UDK I'd probably animate this in Matinee but I'm not sure if Unity have that kind of functionality? Basically, I have a train that is supposed to follow a road or railroad track, and the player is supposed to choose which crossroads track the train travels on (in real-time).


Unfortunately default functionality isn't great for paths, but it's not very hard to code basic spline stuff manually, and there are plenty of add-ons which also give you that functionality. I'll have to pick one myself soon. Here's two options.

http://wiki.unity3d.com/index.php/Hermite_Spline_Controller
http://itween.pixelplacement.com/index.php
 

tokkun

Member
I am currently (for study purposes) transfering old C code to C++ and even though I never thought I say that but there is something I miss in C++ which was done easier/better (probably not safer) in C.

Basicly I have a few memory locations like: a register [0x00] with the mem content = 0x000A for example. In the original code I simply used:

Code:
printf("R%02X:%04X ", reg, mem[loc]);

to get an output like --> R00: 000A. In C++ however this doesn't work as easy and it took me some time until I found that I have to use setw/setfill to achieve the same result.

C++ code:

Code:
cout  << "R" << setw(2) << setfill('0') << hex  << reg << ":";
cout  << setw(4) << setfill('0') << hex << mem[loc] << " ";

Or is there a simpler way to achieve the same level of output/format? I agree it is just more code and not that hard to understand but I thought maybe someone finds it interesting aswell.

Just keep using printf in cases where it is more convenient. Just because something is part of the C libraries does not mean it is considered deprecated in C++.

I do recommend using stringstream over sprintf/snprintf, though.
 

LaneDS

Member
So I work with a lot of developers but don't actually do any development work myself. That said, I've always wanted to (either on my own or perhaps professionally one day) and have coded in Java, C++, and Python in years past but only either for classes or really casually. I'd like to get back into it and have already started plunking away at the exercises from the "Learn Python the Hard Way" link in the OP, in addition to reading through some discussions and examples in this thread.

All that said, looking for feedback on if that's a good foundation for learning/re-learning, and if I should be doing something else in addition to that.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
So I work with a lot of developers but don't actually do any development work myself. That said, I've always wanted to (either on my own or perhaps professionally one day) and have coded in Java, C++, and Python in years past but only either for classes or really casually. I'd like to get back into it and have already started plunking away at the exercises from the "Learn Python the Hard Way" link in the OP, in addition to reading through some discussions and examples in this thread.

All that said, looking for feedback on if that's a good foundation for learning/re-learning, and if I should be doing something else in addition to that.

I've always heard that it's best to get a solid foundation in something, no matter what language, and go from there.
Once you learn the concepts and can write some good, reliable code/programs in the language of your practice you can move into another language of your choosing much quicker.

That's generally better than focusing on multiple areas or languages at once.

To answer your question though, I think Python would be a good foundation if that's where you're starting.
 

Minamu

Member
This is definitely the place to go to ask unity related questions.

Unfortunately default functionality isn't great for paths, but it's not very hard to code basic spline stuff manually, and there are plenty of add-ons which also give you that functionality. I'll have to pick one myself soon. Here's two options.

http://wiki.unity3d.com/index.php/Hermite_Spline_Controller
http://itween.pixelplacement.com/index.php
Thanks, I'll look into these soon! :)
 

LaneDS

Member
I've always heard that it's best to get a solid foundation in something, no matter what language, and go from there.
Once you learn the concepts and can write some good, reliable code/programs in the language of your practice you can move into another language of your choosing much quicker.

That's generally better than focusing on multiple areas or languages at once.

To answer your question though, I think Python would be a good foundation if that's where you're starting.

Great, thanks!
 

Woffls

Member
Sup, I'm new to this thread and haven't been coding very long, so forgive any misappropriated terminology. I've dabbled in C# recently and I just wanted to know what libraries are good for getting data from what is going to be four columns in Excel maintained by non-technical people.

I've done a fair amount in accessing XML data with Linq, so is OpenXml SDK 2 going to be suitable for that, assuming the document stays in xlsx format? Can I use Linq to query xlsx directly or do I need another library?

Essentially what I'm doing is a table lookup that drives how I need to display in an HTML table the contents of an XML file.

Thanksss
 
Almost nearing completion of my final college project and it feels good to be close to "deploying" this app. (not going to publish but gonna actually be a complete product that will be usable.
 
Almost nearing completion of my final college project and it feels good to be close to "deploying" this app. (not going to publish but gonna actually be a complete product that will be usable.

Senior projects, good times. We had to build an application to track birds. It was such a simple thing, in retrospect. But at the time, it was naturally the biggest thing anyone in our group had ever really worked on.

Well, I suppose I shouldn't speak for other members of my group, so maybe it was just me.
 
What are you building for the project if I may ask?

Essentially a mobile inventory system for Android (and if I feel up to it) possibly porting to iOS.

Senior projects, good times. We had to build an application to track birds. It was such a simple thing, in retrospect. But at the time, it was naturally the biggest thing anyone in our group had ever really worked on.

Well, I suppose I shouldn't speak for other members of my group, so maybe it was just me.

Yeah. I've done bits and pieces of the functionality we're implementing but never actually something that put everything together. It is a simple project but getting every piece working is certainly a learning experience.

Of course never really having used Java before and being thrown into an android project certainly was fun. The Java part hasn't been the issue but I do get annoyed at having to type all these long fucking names for methods and variables heh.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Why aren't you using Android Studio?

I second this. If you are developing for Android without Android Studio I would highly recommend migrating into it.

Although at this point in your project it sounds like your just about finished anyways.
 
Is there any sites that would challenge you to RegEx match harder and harder expressions? I know all the basics and bit more but I'd like to get to level where I didn't have Google a starting point first.
 
Why aren't you using Android Studio?

When I first tried it android studio didn't play nicely with my Mac so I just stuck with the eclipse ADT. This was back in February so I'm sure it's a lot better but I was too busy and preoccupied to switch.

And eclipse is, well, eclipse. No comment there but at least it was stable on my Mac.
 

iapetus

Scary Euro Man
When I first tried it android studio didn't play nicely with my Mac so I just stuck with the eclipse ADT.

Android Studio's a bit better with Macs these days - went through a patch where it was buggy. Most of the devs where I work have Macs and Android Studio works pretty well there.

That said, even Eclipse should manage autocompletion of variable and method names - if you're having to type more than a few characters of a long name then something's wrong. :)
 
So I've been doing some Haskell over the last 2 weeks and I really, really like some parts of the language. Algebraic data types are awesome and much nicer than in Scala, auto-generated functions (deriving Eq, Show or Ord) are fantastic. The syntax is also pretty nice, though I'm still getting used to the points-free style, not sure if I really like it. I generally prefer more explicit syntax. I'm not sure if I like Eta reduction either, it looks like this:
Code:
join :: [[a]] -> [a]
join xs = foldl (++) [] xs
-- With Eta reduction, this becomes
join = foldl (++) []
It just makes it harder to read for me. The biggest issue I've run into so far was IO. I have an okay intuition of what monads are and why they're useful, but I don't quite understand why I can't do the following:
Code:
main = do
	args <- getArgs
	firstArg <- head args
	putStrLn firstArg

-- Compiler error: 
    Couldn't match type `[Char]' with `IO String'
    Expected type: [IO String]
      Actual type: [String]
    In the first argument of `head', namely `args'
    In a stmt of a 'do' block: firstArg <- head args
    In the expression:
      do { args <- getArgs;
           firstArg <- head args;
           putStrLn firstArg }
 

Water

Member
The biggest issue I've run into so far was IO. I have an okay intuition of what monads are and why they're useful, but I don't quite understand why I can't do the following:
Code:
main = do
	args <- getArgs
	firstArg <- head args
	putStrLn firstArg
<- isn't for assigning new names for things, it's for taking something IO-wrapped or "unclean" and extracting a pure value. "head args" is already a pure value, so applying <- to it makes no sense. Use "let" or "where" to assign new names.
 
That said, even Eclipse should manage autocompletion of variable and method names - if you're having to type more than a few characters of a long name then something's wrong. :)

See even then it was so wildly inconsistent in whether it wanted to do that or not that I kinda gave up.
 
Hey Guys, I have a pretty complicated SQL server SQL to write that I can't get my head around. I have these two tables.

RULES_CSRP:SBM,FAMILY,MFG_ID,PRICELIST_ID,START_DATE,PERCENT,WEIGHT
PRODUCT: SBM,FAMILY,MFG_ID,PRICELIST_ID,COST

RULES_CSRP has SBM,FAMILY,MFG_ID,PRICELIST_ID as optional fields. We need to use PRODUCT's COST to calculate a discount price using RULES_CSRP's percent. These fields map to the product table. I need to select the highest weight where the product matches all of RULES_CSRP's SBM,FAMILY,MFG_ID,PRICELIST_ID, if the value is not null in the rules table. For example.

PRODUCT
SBM=EQ
FAMILY=MON_FLAT
MFG_ID=HP
PRICELIST_ID = 1-1D

RULES_CSRP:

Code:
SBM     FAMILY     MFG_ID     PRICELIST_ID     START_DT     PERCENT    WEIGHT
EQ     MON_FLAT     HP                1-1D             01/01/1900           3                15
EQ     MON_FLAT     HP                1-1D             01/01/1901           5                15
EQ     MON_FLAT     HP                                  01/01/1900           3                7
EQ     MON_FLAT                          1-1D             01/01/1900           3                11
          MON_FLAT     HP                1-1D             01/01/1900           3                14

In this case, all rows match the product, but we would pick the second row, since it is the most effective dated row with the highest weight.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
I've made three repos so far, have committed more than a few times, and yet I still have this blank stare when I open up the command line to commit a project.

Ugh, I have to read more git.
 
I think I have a handle on it so far.

SELECT * FROM RULES_CSRP R, PRODUCT P WHERE
AND (R.SBM = '' OR P.SUB_BUS_MODEL = R.SBM)
AND (R.FAMILY = '' OR R.FAMILY = P.FAMILY);

etc
 
<- isn't for assigning new names for things, it's for taking something IO-wrapped or "unclean" and extracting a pure value. "head args" is already a pure value, so applying <- to it makes no sense. Use "let" or "where" to assign new names.

That makes total sense (and it's actually the same as in Scala's for comprehensions). Thanks. By the way, this is the thing I made over the last few weeks: https://gist.github.com/GyrosOfWar/10383572
 

Slavik81

Member
I've made three repos so far, have committed more than a few times, and yet I still have this blank stare when I open up the command line to commit a project.

Ugh, I have to read more git.
There's really only a couple commands you need, if all goes well.

Code:
git add .
git status # check what you added
git commit
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
There's really only a couple commands you need, if all goes well.

Code:
git add .
git status # check what you added
git commit

Do you have any experience connecting to GitHub from the command line with an authenticator on your account? I recently added the Google authenticator step and it seemed to be giving me issues logging into origin master.
 

BreakyBoy

o_O @_@ O_o

WSZfEJq.jpg


I practically live in terminal. I love it. Everything else often seems so much slower now. Especially once I learned some zsh.

omg you guyz lern zsh is so best

For those of you using git on the command line, here's a handy alias to add to your global gitconfig:

Code:
lol = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%cr)%C(reset) %C(white)%s%C(reset) %C(bold white)&#8212; %cn%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative

You might need to switch colors around if for some inexplicable reason you're using a light color scheme in your terminal. You should get a nice concise visual view into the repo's history, like so:

 

tuffy

Member
I practically live in terminal. I love it. Everything else often seems so much slower now. Especially once I learned zsh.

omg you guyz lern zsh is so best
Now that I've got a good tmux config going, I can live in a maximized terminal all day without even touching the mouse. It's very convenient.
 

Slavik81

Member
Do you have any experience connecting to GitHub from the command line with an authenticator on your account? I recently added the Google authenticator step and it seemed to be giving me issues logging into origin master.
I didn't even know that existed. Sorry.

I use ssh. I just gave GitHub my public key, because it's far more convenient than typing my password with each push.

I practically live in terminal. I love it. Everything else often seems so much slower now. Especially once I learned some zsh.

omg you guyz lern zsh is so best
What makes you prefer it to bash?
 

Garcia

Member
Note to self: Never, ever forget that the order of operands is the most important thing in this world.

I spent the last 15 minutes trying to figure what the hell was wrong with my program. I tried drawing a heart shape with lines and arcs but the whole diagram flunked when I ran it. Turns out I had 2 vital operands inverted, nested inside a division. Instead of getting higher than X values I kept getting decimal values, which caused the whole diagram to go nuts.

Lesson learned! The program works like a charm now.
 

BreakyBoy

o_O @_@ O_o
What makes you prefer it to bash?

I was typing out something long and in-depth, and then a meeting came up, and I realized that I spent 20 minutes doing something that I'm sure someone else has already done.

http://fendrich.se/blog/2012/09/28/no/

That's a good, quick primer on the basic wins. The comments there are worth a read too, as they have a general smattering of common retorts from bash users, and some handy plugins for zsh that are wonderful. The very first comment thread mentions a plugin that does fish-like syntax highlighting in-line in your shell, which I totally recommend as well.

Overall, zsh is basically a faster bash + convenience features. This means that I can certainly live without it, but it's one of those things I miss when I'm at a terminal that doesn't have them. Sort of the same way I feel about keyboard launchers like Alfred or Quicksilver.

I also highly recommend using a community framework for zsh like oh-my-zsh to get started. If you're comfortable with bash, zsh isn't scary, as it acts exactly like bash 99% of the time. Just make sure to back up your bash config (i.e. .profile/.bashrc/etc) and you can always get back to the way you had things before if you just want to give it a try.

Edit: A co-worker linked me to another good primer.
 

Water

Member
That makes total sense (and it's actually the same as in Scala's for comprehensions). Thanks. By the way, this is the thing I made over the last few weeks: https://gist.github.com/GyrosOfWar/10383572
Nice! This motivated me to figure out how to use cabal to install the required packages so I could run your code. The Hilbert curve option only drew a single horizontal line, but the other two seemed to work as intended.

I got curious about Data.List.Stream aka stream-fusion. Googled a bit, and learned it's a faster drop-in replacement for Data.List, but hasn't been able to replace the original in the standard library due to some situation where the stream-fusion doesn't yet perform adequately. Since stream-fusion is incompatible with the list comprehension syntax, I don't see the point of using it if you don't actually need the extra perf. Are you using it out of habit?
 

Kansoku

Member
I need some help with a Java program.
I have to make a program that compresses a .PPM file and one that decompress it.
From the algorithms that my teacher showed me, I choose LZW. Now, for it I need a table with an "alphabet" and a character to represent it. So I thought of going over the file, picking char 3 by 3 (because RGB) and adding to a hashtable, but that wouldn't be great, so I was thinking of something that would read 3 chars, add it to the table and then use some kind of regular expression to remove them from the whole thing, but then I thought that it would remove things where it shouldn't. For example, tttabtttf. it would be ttt, abt, ttf, but if I use this, it would make things abf. So I don't know what to do, and I'm afraid that I'll need to put stuff in an ArrayList and compare the one that I'll add to the entire Array to stop duplicates.
 
Top Bottom