• 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

Osiris

I permanently banned my 6 year old daughter from using the PS4 for mistakenly sending grief reports as it's too hard to watch or talk to her
Anyone got tips for an experienced C/C# programmer taking up Java?

I've just found out the Software Development courses I'm taking next year are all Java based and whilst I have plenty of time to do an introductory course or two before they start I'd like to hit the ground running so any advice on pitfalls/differences to look out for would be highly appreciated.
 

Osiris

I permanently banned my 6 year old daughter from using the PS4 for mistakenly sending grief reports as it's too hard to watch or talk to her
Thanks. I'll ask my teacher which he prefers tomorrow.

Bear in mind that 2012 doesn't support XNA development either. (Although there are workarounds that involve installing both 2010 & 2012 to get around this)
 

wolfmat

Confirmed Asshole
Anyone got tips for an experienced C/C# programmer taking up Java?

I've just found out the Software Development courses I'm taking next year are all Java based and whilst I have plenty of time to do an introductory course or two before they start I'd like to hit the ground running so any advice on pitfalls/differences to look out for would be highly appreciated.

You'll be fine. There's stuff like setting stack size, but as an experienced C# programmer, you'll figure it out for sure. Google works as well. And don't forget to read the API if you can't guess at how some object works. Because Java's API is actually really good!

If you have something that weirds you out, just post about it in here.
 

Slavik81

Member
Just keep in mind that it may take a while for companies to adopt 2012.
2010 apparently had major changes to the plugin API. I'm still stuck on 2008 until plugins I need are rewritten.

If you're just on your own, you might as well ride the cutting edge. Companies may be far, far behind. Don't worry about it unless you work for them.
 

Chuckl3s

Member
I was wondering if anyone could help me out...

I am trying to get information from a text file that is in a structure. There is 10 items to the structure and within the text file they are each on a separate line. I am trying to create a report (in a list box) with the data in the text file, and in the report, each field should line up under it's appropriate heading. (In other words, each of the 10 items should be on a single line, spaced as to form nice columns). The process would then repeat to read the next 10 lines of the text file and display them just below the first set, thus creating a neatly formatted report with the data from the text file.

I have included the code that I came up with so far, as well as a screen shot of what the result of that code is.

Code:
Imports System.IO

Public Class Report
    'File Name
    Private Const strFILENAME As String = "CustomersReport.txt"

    'Create structure and variables
    Public Structure CustomerInfo
        Dim strNumber As String            'Customer number
        Dim strLast As String               'Last name
        Dim strFirst As String              'first name
        Dim strAddress As String            'Address
        Dim strCity As String               'city
        Dim strState As String              'state
        Dim strZip As String                'zip
        Dim strPhone As String              'phone number
        Dim decBalance As Decimal           'account balance
        Dim dtmPayment As Date              'date of last payment
    End Structure

    Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileExit.Click
        'Close Form
        Me.Close()
    End Sub

    Private Sub Report_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim readFile As StreamReader              'object variable
        Dim readRecord As CustomerInfo            'structure variable
        Dim strHeaderFormat As String = "{0,150}"
        Dim strDateHeaderFormat As String = "{0,240}"
        Dim strCurrent As String = String.Format(strDateHeaderFormat, Now)
        Dim strFormat As String = "{0,-10} {1,25} {2,25} {3,30} {4,25} {5,15} {6,10} {7,20} {8,15} {9,20}"
        Dim strFirstFormat As String = "{0,-10} {1,25} {2,25} {3,30} {4,25} {5,15} {6,10} {7,20}"
        Dim strLabels As String = String.Format(strFormat, "Customer ID", "Last Name", "First Name", "Address", "City", "State", "ZIP", "Telephone", "Balance", "Last Payment")
        Dim strHeading As String = String.Format(strHeaderFormat, "Customer Account Report")
        Dim strRecord As String = String.Format(strFirstFormat, readRecord.strNumber, readRecord.strLast, readRecord.strFirst, readRecord.strAddress, readRecord.strCity, readRecord.strState, readRecord.strZip, readRecord.strPhone)


        'type the report header
        lstReport.Items.Add(strHeading)
        'Current date and time
        lstReport.Items.Add(strCurrent)
        'write blank line
        lstReport.Items.Add("")
        'Write labels
        lstReport.Items.Add(strLabels)
        'open text file to read
        readFile = File.OpenText("CustomersReport.txt")
        'read through each record
        Try
            Do Until readFile.EndOfStream
                readRecord.strNumber = readFile.ReadLine()
                readRecord.strLast = readFile.ReadLine()
                readRecord.strFirst = readFile.ReadLine()
                readRecord.strAddress = readFile.ReadLine()
                readRecord.strCity = readFile.ReadLine()
                readRecord.strState = readFile.ReadLine()
                readRecord.strZip = readFile.ReadLine()
                readRecord.strPhone = readFile.ReadLine()

                'write the record
                lstReport.Items.Add(strRecord)
            Loop
        Catch ex As Exception
            MessageBox.Show("Unable to generate report.")
        End Try

    End Sub

    Private Sub mnuHelpAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHelpAbout.Click
        'Message box about this form
        MessageBox.Show("Displays report showing all customers and their data.")
    End Sub


    Private Sub pdPrint_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pdPrint.PrintPage
        Dim intYPosition As Integer = 40


        For Each customer As String In lstReport.Items
            e.Graphics.DrawString(customer, New Font("Courier New", 12, FontStyle.Regular), Brushes.Black, 10, intYPosition)
            intYPosition += 40
        Next

    End Sub

    Private Sub mnuFilePrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFilePrint.Click
        'Print the report
        pdPrint.Print()
    End Sub
End Class

JZUum.jpg
 
*sigh* I keep getting an error when trying to use cin.getline. Trying to get a string, whitespace and all, and it's saying no instance of overloaded function... Am I missing something here?
 

8byte

Banned
Can anyone help me decipher this? I'm really struggling to comprehend this.

A Push method

This method will take a single parameter whose type is the type parameter for this class, and will return nothing. It will need to add the parameter to the top of the stack. One of your private fields should tell where this element needs to be stored. You will then need to update this field to the next higher index, wrapping around to the beginning of the array if necessary. You will also need to update the number of elements, but note that this number should not change if it is the same as the array length - in this case, the bounded stack is at its capacity, so the new element replaced the bottom element.

As a part of my assignment, I need to write a push method, but I just can't make sense of this. I've created a class with a bounded stack (per the instructions for the course) but I'm finding it increasingly difficult to understand his instructions.

Here's the code I have so far...it's not much. Not posting the other class, as I don't think it's necessary (I think).

Code:
    public class BoundedStack <T>
    {
        private T[] _elements = new T[5];
        private int _stored = 0;
        private Array [] _index = new Array [0];

    public void Push (T X){
        
    }
 
The push method adds one more element to the top of the stack, in this case to your _elements array. Then you increment the size _stored by one to indicate that there's one element in the stack. I'll give you a hint. You need two "pointers" to keep track of where the stack begins and ends.
 

8byte

Banned
The push method adds one more element to the top of the stack, in this case to your _elements array. Then you increment the size _stored by one to indicate that there's one element in the stack. I'll give you a hint. You need two "pointers" to keep track of where the stack begins and ends.

Ah!

I just added a get method to get the number of elements stored in the stack.

I should be able to increment the size of _stored just by using a for loop, correct? Have a value passed to the push method, run it through a loop, and incredment _stored by one with each pass of the loop until the values match?
 

hateradio

The Most Dangerous Yes Man
I'm having a bit of an issue deciding how to go about this next project.

  • I have an object/entity that I call a Collection which can be either type Music or Film - possibly a few more later;
  • The collection contains information about itself (clearly), ratings, tags, etc.

  • I then have Formats which can be MP3/FLAC/AVC;
  • Obviously, those formats are attached to the type (Music [MP3/FLAC] or Film [AVC]).

Since these entities will be mirrored in the database, I'm having trouble getting my mind around how I'll be ordering them. I don't want to have repetition, but it seems like I'm going to have to have Types attached to both Collections and Formats. It seems a little awkward to me. Is there a better solution?

Additionally, for audio formats I want to have a quality option for either Lossless or Lossy. Would I just add that field to Formats?

Code:
Collections

id | name | type_id | format_id
1  | One  | 2       | 4
2  | Two  | 1       | 3


Types

id | name
1  | Film
2  | Audio
3  | 4D!

Formats

id | name | type_id? | lossless?
1  | FLAC | 2        | 1
2  | MP3  | 2        | 0
3  | AVC  | 1        | null
4  | AAC  | 2        | 0
 

r1chard

Member
New to python
Then I would recommend you run through the free tutorial but if you really need a book... hoo boy, actually, I can't recommend one :) There's a huge list... Programming Python seems popular. But to be honest, I've never actually bought a Python book - I've only ever referred to the standard docs. I do own Python books that've been given to me, but I've not actually read any of them...
 

mike23

Member
You can get the type via the format, so collections could be reduced to:

Code:
id | name |  format_id

At least that is what I see at the moment.

That's what I was thinking, also.

Depending on how you plan to use the formats, you could go the other way and remove type_id from the format table.

It might seem like mp3 automatically belongs to audio, but maybe you end up having a music type and an audiobook type, or something like that. In that case, the type of a format is not fixed.
 

hateradio

The Most Dangerous Yes Man
With arit's method I'd have to rely on delegation to get the format, which seems a little different than what I would want (someCollection.getFormat().getType()).

It would also be like a roundabout to get Collections by Type.

I'd have to do something like get Music Collections --> Get all music Formats -> Get all Collections where format_id in Music formats' IDs.

I'd rather have it do this: Get all Collections where type_id is Music ID.

It might seem like mp3 automatically belongs to audio, but maybe you end up having a music type and an audiobook type, or something like that. In that case, the type of a format is not fixed.
But then how would I establish a relationship between formats and types? Should I just forgo it?

The thing I do need is to have a form (when adding Collections) that would load all Audio formats as a drop down if a person is adding Music, or even an Audiobook like you said.

New music -> show MP3/FLAC/AAC
New film -> show AVC/WebM
 
But then how would I establish a relationship between formats and types? Should I just forgo it?

The thing I do need is to have a form (when adding Collections) that would load all Audio formats as a drop down if a person is adding Music, or even an Audiobook like you said.

New music -> show MP3/FLAC/AAC
New film -> show AVC/WebM

If you're using a dropdown, just have all formats listed by type; in HTML this would be an optgroup. Your processing code would then assign the type based on the choice of format.


DB/class structure:
Collections
ID
Name
Format

Formats
ID
Name
Type
Lossless

Types
ID
Name
 

hateradio

The Most Dangerous Yes Man
Yeah, that's pretty much what arit suggested. But I can still run into Mike23's problem if I have the following.

SomeCollection -> Format MP3 -> (defaults to) Type Music

But what if I have audiobooks, which are not music. :p

I think the collection would have to have a reference to both Type and Format.

If I extend classes for collections . . .

AudioBookCollection -> Format MP3 -> Type AudioBook
MusicCollection -> Format MP3 -> Type Music
FilmCollection -> Format WebM -> Type Film

I would require a reference to the Type in the DB for that collection, otherwise I wouldn't know the collection's Type -- I can't use Format because it's not indicative of a Type.

However, a Type can be indicative of a Format since a Film will not be an MP3.

That's why I was thinking of adding a type_id field to the Formats, since it has a relation to Type. It seems repetitive, but maybe I'll just have to live with it. :p
 

Zoe

Member
You could add a fourth table which gives the possible combinations of types and formats

Code:
format_id	| type_id
1		| 2
2		| 2
3		| 1
3		| 2

You'd get the format ID from their input and then query this table to get the possible choices for type.
 

wolfmat

Confirmed Asshole
You simply need to introduce a Genre. An Genre is not a Type. A Genre can indicate a Type. Genres that indicate Types have type_ids in the type_id column, ones that don't have null.

Then you need to reduce Type to Audio and Audio/Video.

Genre has Audiobook, Telenovela, Porn and so forth.

A Collection can, but does not have to have, a genre_id. A Collection also has to have a type_id. If the associated Genre indicates a Type, then the type_id is immutable from the view of the Controller. If the associated Genre does not indicate a Type, then the type_id choice is free to be picked.

You could furthermore split up Genre into MetaGenre (Music, Movie, Spoken Words, bla) and then associate Genres with MetaGenres. A MetaGenre follows from the Genre, of course. Porn is not Spoken Words.

And so on.

Media databases tend to get messy anyway. So you have multiple authors for books, leading authors for books, studios for screenplays, authors for screenplays, writer and drawing dude for comics (maybe even studio)...

Edit: Multiple genres for a collection, mixed media in a collection, container formats with mixed media collections as singular items in a Collection, lots of stuff can go crazy. You need to be ready to at least deal with "Unspecified" in a couple of tables.

You're screwed by default if you want to do it right in this particular case. It's up to you to reduce it / blow it up to get to the perfect balance between complexity and maintainability. I'd say you should let the UI indicate what you need. That makes things way easier than starting at the database design. But it also locks you down.

Never easy, man!
 
I'm seriously suffering here

I've been trying to complete a sort of simple assignment for hours now

essentially I have to write a program that will multiply a sparse matrix that has been compressed into a dense matrix with a column vector, without reverting the dense matrix to the sparse one

so for instance, the matrix

[0 2
1 0]

would become the dense matrix

[1 2 2
2 1 1]

where the first column is the row, second is column, and third is value

but I have to write a program that would multiply, say,

[2,1]

with that second matrix

very, very confusing!!!
 

hateradio

The Most Dangerous Yes Man
You simply need to introduce a Genre. . . .

Never easy, man!
That makes the whole thing sound way more complicated than I would have conceived. :p

I guess it makes sense.

The basic UI would be something like.

This would be the base Type (?)

- Create a new collection (link/drop-down/w/e)

  • Audio Collection
  • Video Collection

Let's say we pick video.

If I did create a "genre" then I'd get the following genres.

- Select category

  • Film
  • Television

We then get a drop-down for the following formats (codecs/w/e)

- Select Format

  • AVC
  • WebM
  • MPEG-4 (Xvid/Divx)

And that's about it. I'd still require Type to interact with both Formats and Genres.
 

usea

Member
I've been trying to learn Go (google's programming language). Here's something I wrote that parses english spelled-out numbers like "three thousand and sixty-five" to real numbers.
http://play.golang.org/p/ct0sLGRcZ5

There's no error checking, so it just explodes if you type something that it doesn't allow. You don't have to use commas, hyphens, or the word "and" if you don't want to. I got the idea from a daily programming challenge I saw on the web last week.

I don't really know what I'm doing in Go, so this could be super terrible. I have no idea. If anybody has any tips or criticism for how to improve it, I'm eager to learn more.


So far I like Go, although it's clearly aimed at people who write C or maybe some C++ programmers. There's tons of convenience stuff missing that might never be added, like generics (no generic containers, for example). I find myself really yearning for things like C#'s LINQ IEnumerable extensions. Still, it's pretty cool. I'm going to make some small web apps with it, since it's pretty great at that.
 

mike23

Member
I've been trying to learn Go (google's programming language). Here's something I wrote that parses english spelled-out numbers like "three thousand and sixty-five" to real numbers.
http://play.golang.org/p/ct0sLGRcZ5

There's no error checking, so it just explodes if you type something that it doesn't allow. You don't have to use commas, hyphens, or the word "and" if you don't want to. I got the idea from a daily programming challenge I saw on the web last week.

I don't really know what I'm doing in Go, so this could be super terrible. I have no idea. If anybody has any tips or criticism for how to improve it, I'm eager to learn more.


So far I like Go, although it's clearly aimed at people who write C or maybe some C++ programmers. There's tons of convenience stuff missing that might never be added, like generics (no generic containers, for example). I find myself really yearning for things like C#'s LINQ IEnumerable extensions. Still, it's pretty cool. I'm going to make some small web apps with it, since it's pretty great at that.

I know how you feel about LINQ, it has ruined me.

I don't want to be a jerk, but it think "three thousand and sixty-five" is technically incorrect. The "and" should not be there, it makes the fragment mean 3000 and 65.
 

usea

Member
I know how you feel about LINQ, it has ruined me.

I don't want to be a jerk, but it think "three thousand and sixty-five" is technically incorrect. The "and" should not be there, it makes the fragment mean 3000 and 65.
It's never rude to correct somebody! That's how people learn. :)

That being said, I included it because the requirements I read originally allowed the word, so I allowed it. But it just strips it out since it's inconsequential, so you don't have to use it.

I looked it up earlier today (my gf mentioned the same thing you did), and while it seems there are some schools in the US that teach to omit "and", others do not. I checked a manual of style and grammar girl's blog and couldn't find any mention of it. It seems to be just one of those things that some people do, and others don't. (in the US)
 

wolfmat

Confirmed Asshole
And that's about it. I'd still require Type to interact with both Formats and Genres.

In that case, the Collection name implies the type, so you might want to introduce a collection_type, which is a foreign key to Type, if there are only Audio and Video Collections.
 
New to c. For some reason I can't figure out why my program won't terminate. I have to be missing something super simple...

Code:
#include <stdio.h>

#define LINE_LEN 80 //define line length to predetermined amount.

char detab(int n, char s);

int main(void)
{
	int tab;
    char str = 0;
    
    printf("Set value to adjust tab size by: ");
    scanf("%i", &tab);
    
    printf("Enter a string: \n");
    while((str == getchar())!= LINE_LEN) //while loop controlling the character input with getchar
        detab(tab, str);
    
    return 0;
}

char detab(int n, char s)
{
    int a, b;
    a = 0;
        
    while((s = getchar())!= LINE_LEN)
    {
        if( s == '\n')
        {
            putchar(s);
            a = 0;
        }
        else if (s == '\t')
        {
            b = n - a % n;
            while(b-- != 0)
            {
                putchar(' ');
                a++;
            }
        }
        else
        {
            putchar(s);
            a++;
        }
    }
    return s;

}

It's due to the while loop, but I don't know what to use in place to get input.

and fget isn't an option.

From a problem set in ritchie's cbook.
 

arit

Member
Code:
while((str == getchar())!= LINE_LEN)

(str == getchar()) might return 0 or 1 which both are != 80.


Code:
while((s = getchar())!= LINE_LEN)

(s = getchar()) should return 1 which also is != 80.

But I might be mistaken, since my last contact with c was a little while ago (as in I do not know if they really return 1 or just anything > 0).

EDIT:

Code:
            b = n - a % n;
            while(b-- != 0)
            {
                putchar(' ');
                a++;
            }

So n is the amount of whitespaces a tab should be, a the amount of chars in a line? I do not understand why you assign n-a to b, instead of just n (or to go even further omitting b complete and just using n only, since it is only used in this case), something like

Code:
while( (a < LINE_LEN) && (n > 0) ){
  (void)putchar(' ');
  a++;  // might as well be put into the while condition
  n--;  // might as well be put into the while condition
}

And at least in this version, char detab(int n, char s) could be changed to void detab(int n, char s) since you seem to ignore the returned char of that function.

EDIT2:
Just checked it, (a=b) returns the then asigned value of a, so unless you input a 'P' while((s = getchar())!= LINE_LEN) should never terminate.
 

hateradio

The Most Dangerous Yes Man
Just read a few posts above for some related to Python. CTRL+F :p

In that case, the Collection name implies the type, so you might want to introduce a collection_type, which is a foreign key to Type, if there are only Audio and Video Collections.
Yeah, it'll basically be how I had it at the start, except I'll go with Codecs instead of Formats.

Code:
Collections
id | type | codec | name
1  | 1    | 2     | Exciting
2  | 1    | 2     | Boom
3  | 2    | 3     | BANG!

Codecs
id | name | type
1  | FLAC | 1
2  | MP3  | 1
3  | AVC  | 2

Types
id | name
1  | Audio
2  | Video

So, hopefully, when I'll be doing the following.

Code:
C = getCollectionById(3);
C.getName(); // BANG!
C.getCodec().getName(); // AVC
C.getType().getName(); // Video
 
My boyfriends friend wants to teach me to program in C# so he can hire me at the company he works for. He's the lead software developer at a company and the #2 in line behind the CEO. It's a pretty big company and this is a potentially life changing opportunity.

I've never programed anything in my life. He wants to teach me but he has difficulty verbalizing and conceptualizing the fundamentals. So where should I start? Once I get off the ground and understand fundamental concepts I'm sure I'll be able to come to him for anything, he's a prodigy.

His advice to me was to try to think of a concept for something I want or NEED to do. Something that will hold my interest and motivate me. That's how he started when he was a kid. I'm having difficulty in manufacturing a need. I also feel a lack of confidence because of my lack of advanced math skills, which he says aren't entirely necessary. He likens it more to learning a second language than learning advanced math.

Are there any books you'd recommend? Any projects you think might be good jumping off points? We created a Hello, world! application but while I can re-create this application I'm not sure I grasp the basic concepts behind what it is exactly I'm doing.

I'm using Microsoft Visual Studio Ultimate 2012. Programming in C# for the first time. Halp!
 

Kalnos

Banned
First of all, that situation seems odd. Do you really want to be programmer or are you trying this solely for the job at that company/your boyfriend's friend? How soon is he expecting to hire you?... you don't learn how to program effectively very quickly.

Programming doesn't always require a ton of 'pure' (e.g. Calculus) math per say but there's a shit ton of discrete mathematics, so I'm going to have to disagree with your friend there.

People seem to recommend the book 'Head First C#" on Stack Overflow. If you could find any sort of course with 'homework' like assignments that would be great too IMO. The best way to learn programming is by doing it.
 

amrihua

Member
My boyfriends friend wants to teach me to program in C# so he can hire me at the company he works for. He's the lead software developer at a company and the #2 in line behind the CEO. It's a pretty big company and this is a potentially life changing opportunity.

I've never programed anything in my life. He wants to teach me but he has difficulty verbalizing and conceptualizing the fundamentals. So where should I start? Once I get off the ground and understand fundamental concepts I'm sure I'll be able to come to him for anything, he's a prodigy.

His advice to me was to try to think of a concept for something I want or NEED to do. Something that will hold my interest and motivate me. That's how he started when he was a kid. I'm having difficulty in manufacturing a need. I also feel a lack of confidence because of my lack of advanced math skills, which he says aren't entirely necessary. He likens it more to learning a second language than learning advanced math.

Are there any books you'd recommend? Any projects you think might be good jumping off points? We created a Hello, world! application but while I can re-create this application I'm not sure I grasp the basic concepts behind what it is exactly I'm doing.

I'm using Microsoft Visual Studio Ultimate 2012. Programming in C# for the first time. Halp!

Start with a simpler language and work your way up. Languages like C# have way too many concepts that you need to understand and aren't easy to grasp for beginners. It took me years to finally figure out what Object Oriented Programming means and I still don't know why I should use it, and my master's thesis is on programming supercomputers [OOP is discouraged because it is a load of bull].

Perl is a simpler language than C#
http://www.perl.com/pub/2000/10/begperl1.html

Another language I recommend would be Haskell
http://www.haskell.org/haskellwiki/Tutorials

You don't have to complete the tutorial just go half way thru it and then read this:
http://en.wikipedia.org/wiki/Object-oriented_programming
If you can't understand it, try to find other sites that explains it. If you can't grasp OOP you can't learn C#.

OOP is garbage but if you want/need to use C# effectively then you must know how to use it.

"Object-oriented programming is an exceptionally bad idea which could only have originated in California." -- Edsger Dijkstra
 

Slavik81

Member
Ducky, what sort of education are you building on? A university degree? If so, in what?

Also, for some reason I thought you already were a programmer.
 

Chris R

Member
I was wondering if anyone could help me out...

I am trying to get information from a text file that is in a structure. There is 10 items to the structure and within the text file they are each on a separate line. I am trying to create a report (in a list box) with the data in the text file, and in the report, each field should line up under it's appropriate heading. (In other words, each of the 10 items should be on a single line, spaced as to form nice columns). The process would then repeat to read the next 10 lines of the text file and display them just below the first set, thus creating a neatly formatted report with the data from the text file.

I have included the code that I came up with so far, as well as a screen shot of what the result of that code is.

You have probably already fixed this since this reply is so long after your post, but look at what you are adding in your Do loop and compare that with what you WANT to add, because your current code won't do much.


Yeah, it'll basically be how I had it at the start, except I'll go with Codecs instead of Formats.

Code:
Collections
id | type | codec | name
1  | 1    | 2     | Exciting
2  | 1    | 2     | Boom
3  | 2    | 3     | BANG!

Codecs
id | name | type
1  | FLAC | 1
2  | MP3  | 1
3  | AVC  | 2

Types
id | name
1  | Audio
2  | Video

So, hopefully, when I'll be doing the following.

Code:
C = getCollectionById(3);
C.getName(); // BANG!
C.getCodec().getName(); // AVC
C.getType().getName(); // Video

Can your entry in the collections table EVER have a different "type" from it's codec? If not, then why store that information? If the type depends on the codec only store that information in the codec table. And yea, ORM is some awesome shit. I love being able to drag tables into a designer and have VS automatically set everything up properly (after setting up the tables in Sql Server that is).
 

hateradio

The Most Dangerous Yes Man
. . . It took me years to finally figure out what Object Oriented Programming means and I still don't know why I should use it, and my master's thesis is on programming supercomputers [OOP is discouraged because it is a load of bull].

. . .

OOP is garbage but if you want/need to use C# effectively then you must know how to use it.

"Object-oriented programming is an exceptionally bad idea which could only have originated in California." -- Edsger Dijkstra
Let me just say that I'm a Californian . . . and what? Oh boy, no wonder I'm not a CS major.

Can your entry in the collections table EVER have a different "type" from it's codec? If not, then why store that information? If the type depends on the codec only store that information in the codec table. And yea, ORM is some awesome shit. I love being able to drag tables into a designer and have VS automatically set everything up properly (after setting up the tables in Sql Server that is).
I forgot to include also the "Genre" or Category table, that relies on a type.

So actually the Category field would be in there instead of the Type.

Type -> Category / Codec

Video -> Documentary/AVC
Audio -> Audiobook/MP3

Thus, the following.

Code:
C.getCategory().getName(); // Documentary
C.getCategory().getType().getName(); // Video


And yeah, ORM is amazing. However, I'm actually doing it in PHP with Doctrine, so it's less automatic. :p (I'm just using dot notation because it's nicer.)
 

Zoe

Member
His advice to me was to try to think of a concept for something I want or NEED to do. Something that will hold my interest and motivate me. That's how he started when he was a kid. I'm having difficulty in manufacturing a need. I also feel a lack of confidence because of my lack of advanced math skills, which he says aren't entirely necessary. He likens it more to learning a second language than learning advanced math.

So because he was able to self-teach at a young age, he thinks everybody can do the same at any age.

(hint: it's not that easy)

Seems like he has a specific role in mind, but I can't imagine you being job ready in C# for quite a while. QA or possibly very simple DB stuff would be much more believable.
 
My boyfriends friend wants to teach me to program in C# so he can hire me at the company he works for. He's the lead software developer at a company and the #2 in line behind the CEO. It's a pretty big company and this is a potentially life changing opportunity.

I've never programed anything in my life. He wants to teach me but he has difficulty verbalizing and conceptualizing the fundamentals. So where should I start? Once I get off the ground and understand fundamental concepts I'm sure I'll be able to come to him for anything, he's a prodigy.

His advice to me was to try to think of a concept for something I want or NEED to do. Something that will hold my interest and motivate me. That's how he started when he was a kid. I'm having difficulty in manufacturing a need. I also feel a lack of confidence because of my lack of advanced math skills, which he says aren't entirely necessary. He likens it more to learning a second language than learning advanced math.

Are there any books you'd recommend? Any projects you think might be good jumping off points? We created a Hello, world! application but while I can re-create this application I'm not sure I grasp the basic concepts behind what it is exactly I'm doing.

I'm using Microsoft Visual Studio Ultimate 2012. Programming in C# for the first time. Halp!


Please don't take offense to this, because this is not your fault, but no. Do not do this. Honestly, I cannot even believe your boyfriend would consider this. In a "pretty big company," I cannot even believe anyone else there would be OK with this. The fact that the two of you are linked is already enough of an appearance of impropriety. The fact that you have no programming background at all? That just not cool.

Besides that, programming isn't just something you pick up, go 0-to-60 in a weekend or a month or just go ahead and choose your duration. His "pretty big company" presumably is looking for someone with a proven trackrecord. It defies all reason that he would be interested, absent the relationship, in someone with no background at all.

I seriously question your boyfriend's judgment on not only this course of action ethically, but also his judgment of what's necessary to be a good developer. He very much seems to not get it.

(I'm sure he's a swell guy otherwise and wish the two of you the best.)
 

hateradio

The Most Dangerous Yes Man
I'm sure that Ducky could start at an intern position and go from there. But learning the basics will take a while.
 
Alright another issue. Still toying with strings.

Code:
int main(void)
{

    char str = 0;
    char str1[80];
       
    printf("Enter a string: \n");
    
    for(int i= 0; i < 80; i++)
    {
        str = getchar();
        str1 [i] = str;
    }
    
    printf("%s", str1);
        
    return 0;
}

Whenever I use anything >70 for the ending point, I get a weird addition when I output the string...

Code:
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhH\370\277h

It's pulling the extra crap from somewhere, but why?
 

arit

Member
Whenever I use anything >70 for the ending point, I get a weird addition when I output the string...

Code:
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhH\370\277h

It's pulling the extra crap from somewhere, but why?

C-Strings are '\0' terminated and printf("%s"...) prints out the memory content until it finds '\0', or crashes the program when it doesn't since it will try to access memory not owned by the program. Unless you calloc() or initialize memory yourself, it could contain anything.
 

wolfmat

Confirmed Asshole
It's pulling the extra crap from somewhere, but why?

The extra crap is anything that's in memory after the string. Strings that are not explicitly length-limited, need to be null-terminated to be properly output with printf like that.

There is the length argument, goes like this:
Code:
printf("%.*s",80,str1);

Or, preferably, you'd simply append a \0 to your char[] after the for-loop is through (make it 1 char longer though, of course, because \0 also needs space).
 
The extra crap is anything that's in memory after the string. Strings that are not explicitly length-limited, need to be null-terminated to be properly output with printf like that.

There is the length argument, goes like this:
Code:
printf("%.*s",80,str1);

Or, preferably, you'd append a \0 to your char[] (make it 1 char longer though, of course, because \0 also needs space).

Buh. Didn't realise you could do that with printf.

I figured it was pulling some useless value out of memory, but couldn't figure out that it was due to it being an extra character in the string before \0.
 

wolfmat

Confirmed Asshole
Buh. Didn't realise you could do that with printf.
printf is rather versatile: http://www.pixelbeat.org/programming/gcc/format_specs.html

It also gobbles up escape sequences and lets the terminal handle them, among other things. And, as you've found out now, it's a great way to hack stuff in conjunction with broken getchar() code (and some tinkering).

I figured it was pulling some useless value out of memory, but couldn't figure out that it was due to it being an extra character in the string before \0.
Not sure if you got the point. Your char[] is pretty much a string that is not terminated. There is a \0 by chance behind it, that's why the printf stopped (\0 is pretty common because it's literal 0x00, a value that comes up all the time). It could've easily gone on and resulted in a segfault, printed out some decoded MP3 that you're currently listening to, whatever. Depends on the environment.

You should explicitly terminate a string with a \0 if you read it in with a getchar().

And you should also clear a fresh char[] (or any other variable or structure, for that matter, unless you really intend to not do that) before doing anything meaningful. That's what arit is saying above. Either let a function handle allocation, like calloc(), which clears memory in the process, or clear it by hand, which could mean writing \0 into each field of the char[] directly after declaration. Declaration just refers to the step of reserving space in memory. It does not get zero'd implicitly or anything.
 
Top Bottom