• 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

vypek

Member
Just had coding interview but I feel like I bombed. Feels bad man.

The one I "bombed" is the one I got hired for. A lot of times, people are looking to see how you think and approach a problem. This could be the case for you this time as well. You already did your best so try not to cause yourself anguish by mentally harping on how it went. If there is something you didn't understand or know for a fact that you missed, research and learn about it.
 

Somnid

Member
The one I "bombed" is the one I got hired for. A lot of times, people are looking to see how you think and approach a problem. This could be the case for you this time as well. You already did your best so try not to cause yourself anguish by mentally harping on how it went. If there is something you didn't understand or know for a fact that you missed, research and learn about it.

That's my hope anyway, it was with one of the big 4 so I have no idea where I stack up against other applicants. I tried to audibly talk through it as much as possible. I got stuck implementing breadth-first search which was required to solve the problem, not that I don't know what it is and how it works but deriving it in real-time under pressure "wait, which order do I stick these things in the queue again?", "should I be operating on this pre-queue add or post-queue add?" In the end I didn't finish the problem, but maybe they use the college math scale.
 

Jokab

Member
Doesn't matter if it's a list. Do not modify it under iteration. Think about what happens, if your removed index 3 then index 4 is now index 3 and when you advance to the next index you're on what you'd expect to be index 5.

Make a new list without the deleted elements. People in this thread will talk about the glories of immutability and this is what they are referring to, make new objects rather than modify. It saves your from subtle bugs like this where you accidentally change the object out from under a piece of code that reads it.

In Java I would use an iterator for this job. It can handle deletion during iteration.
 

Somnid

Member
In Java I would use an iterator for this job. It can handle deletion during iteration.

Iterators are shorthand for the same thing, you aren't modifying the original copy just the new sequence of references which typically need to be collected into a new list.
 

wwm0nkey

Member
Yeah I just fixed it by changing the i index to 0 and then removing any item containing 0 after doing what I want it to do, so the for loop now goes off just fine and it doesn't mess with positions in the List anymore and it all works like how it should now.

Here is the big block of ugly code
Code:
        if (Input.GetKeyDown(KeyCode.F)) {
            if (SecondOne.Count > 0) {
                for (int i = 0; i < drawLimit; i++) {
                    if (cardSpawns[i].GetComponent<CardScript>().isUsed == true) {
                        Instantiate(Resources.Load(SecondOne[i].ToString()) as GameObject);
                        SecondOne[i] = 0;
                        cardSpawns[i].GetComponent<CardScript>().isUsed = false;
                        if(SecondOne.Count < 5) {
                            SecondOne.Add(1);
                        }
                    }
                }
                
                Debug.Log(SecondOne.Count);
            }else {
                Debug.Log("Out of Chips!");
            }
  
        }
 

Lois_Lane

Member
Sorry to bother you guys again but I'm having a slight problem with this project I'm working on. The assignment is supposed to hide the original bitmap under a cloud of pixelation but I can't get the cloud to cover the whole image. Here's the program:

public static void startEncode(File file, Scanner key, Random rand, Bitmap work) {
int imgWidth = work.width();
int imgHeight = work.height();
System.out.println( imgHeight + "+" + imgWidth);
int x;
for (int j = 0; j < imgHeight; j++) {
for (int i = 0; i < imgHeight; i++) {
int ZeroOrOne = rand.nextInt(2);
int firstNum = rand.nextInt(256);
int SecNum = rand.nextInt(256);
if (ZeroOrOne == 0) {
x = 255;
} else {
x = 0;
}
int red = work.getRed(firstNum, SecNum);
int green = work.getGreen(firstNum, SecNum);
int blue = work.getBlue(firstNum, SecNum);
work.setBlue(firstNum, SecNum, x);
work.setGreen(firstNum, SecNum, x);
work.setRed(firstNum, SecNum, x);
}
}
File outputFile = new File("test_out.bmp");
work.write(outputFile);


}

And the shit image I keep getting.
test_out.bmp
 

Koren

Member
you've used imgheight twice... Copy-paste bug ^_^

That being said, not sure that's it (I don't see the image). Why do yo use random numbers under 256 as coordinates?
 

Armaly

Member
What's the most popular web framework to learn these days? Trying to make a website a project between a few friends. We know C, C++, Java, and a little Python. Thinking about Django to improve on Python. How is it for css stuff? We're having a graphic design friend work on the design for us and want to make it as easy as possible for him to translate his stuff over to whatever we want. He is used to adobe muse but the rest of us are very familiar with html and javascript.
 
What's the most popular web framework to learn these days? Trying to make a website a project between a few friends. We know C, C++, Java, and a little Python. Thinking about Django to improve on Python. How is it for css stuff? We're having a graphic design friend work on the design for us and want to make it as easy as possible for him to translate his stuff over to whatever we want. He is used to adobe muse but the rest of us are very familiar with html and javascript.

React.

Or go for Phoenix/Elixir for loads of nerd cred and being on the cutting edge.

*edit* Oh wait, i think that React is no longer cool, its vue.js now.
 

Makai

Member
Doing the same thing with Rust but with dx12 xD
And you got it to work? I dont't think it can because DX12 doesnt have C bindings - just C++. My plan is to switch to Rust after I finish the tutorial. I'd actually probably use DX12 over Vulkan if it was compatible with Rust
 
And you got it to work? I dont't think it can because DX12 doesnt have C bindings - just C++. My plan is to switch to Rust after I finish the tutorial. I'd actually probably use DX12 over Vulkan if it was compatible with Rust

From what i gathered you can get DX12 object by querying for COM objects. I'm not really familiar with COM.
In Rust i use a crate named winapi which has FFI bindings for the windows api.

I'm just reading the example in the book "Introduction to 3D game programming with DX12" and port them to rust while i go.
That was after read the basics of the Rust language.
 

Tater Tot

"My God... it's full of Starch!"
}
float ConvertAndRoundChange(void){
float convert = GetChange();

float RoundCents = roundf(convert*100)/100;
float CentAmount = (%.2f, RoundCents); //does not work


return CentAmount;
}

Language C, How can I get this to work?
 

Two Words

Member
A place offered me to intern over the summer. They will be working in embedded C/C++. I have experience in C/C++, but does the "embedded" part just mean working in a low-resource environment? Like, the syntax structure is all the same, but the target environment doesn't have a lot of RAM/CPU time?
 

poweld

Member
A place offered me to intern over the summer. They will be working in embedded C/C++. I have experience in C/C++, but does the "embedded" part just mean working in a low-resource environment? Like, the syntax structure is all the same, but the target environment doesn't have a lot of RAM/CPU time?

An embedded system is a "box" with a device that ships with hardware & software dedicated to a particular task. It doesn't necessarily imply limited resources. An embedded system could be a consumer-grade wireless router
header-wnr2500-3-4lft-photo-large.png
or a huge 4U rack-mounted server
RS47FL24%20L%20angle.jpg
for example
 

Slo

Member
Yeah, "embedded" just means "software that makes hardware work." Lots of opportunities in that field including medical devices, IoT, and robotics, etc.
 
From what i gathered you can get DX12 object by querying for COM objects. I'm not really familiar with COM.
In Rust i use a crate named winapi which has FFI bindings for the windows api.

I'm just reading the example in the book "Introduction to 3D game programming with DX12" and port them to rust while i go.
That was after read the basics of the Rust language.
Can't you just use the DX stuff in the crate and not go through COM? I don't think that com stuff is even in the crate anyway.
 
ProgrammingGAF, I've come up against a wall. I've been researching and looking around for tutorials but there is simply not many information about my problem so any help will be greatly appreciated.

My problem: How do I make and manipulate data in a simple linked list inside a doubly linked list? I have two node classes (GameStore and StoreInventory) with each having attributes like ID, name, etc. Only exception is that GameStore has a StoreInventory attribute (the simple liked list). Now I've been able to insert, delete, modify and show the doubly linked list (GameStore) but how do I go about initializing and inserting data in the StoreInventory list? Here is the link to my project (it's in Spanish though). Please help me GAF, you're my only hope.
 

peakish

Member
ProgrammingGAF, I've come up against a wall. I've been researching and looking around for tutorials but there is simply not many information about my problem so any help will be greatly appreciated.

My problem: How do I make and manipulate data in a simple linked list inside a doubly linked list? I have two node classes (GameStore and StoreInventory) with each having attributes like ID, name, etc. Only exception is that GameStore has a StoreInventory attribute (the simple liked list). Now I've been able to insert, delete, modify and show the doubly linked list (GameStore) but how do I go about initializing and inserting data in the StoreInventory list? Here is the link to my project (it's in Spanish though). Please help me GAF, you're my only hope.
Try writing a function that takes a pointer to a simple list and initializes it with some objects, just like you do for the double list. By breaking it into a separate, small problem you should be able to work out how the flow works. Note that your code currently has GameStore link to INVENTORY structs, while you need to link to the simple linked list instead (since this is what you will be using).
 
Try writing a function that takes a pointer to a simple list and initializes it with some objects, just like you do for the double list. By breaking it into a separate, small problem you should be able to work out how the flow works. Note that your code currently has GameStore link to INVENTORY structs, while you need to link to the simple linked list instead (since this is what you will be using).

Yeah I thought as much since I wouldn't be able to access the simple linked list functions from in the main... Alright I'll try it.

UPDATE:

I got it working! It was very simple, just as you said, I had to make the inventory attribute a list object, only problem now is making everything work with setters and getters... Thank you though!
 

Pau

Member
Working in Java and I'm trying to find if an object is an element in a linked List with a particular attribute. I'm using the get(int index) function but I get an error that I don't understand: "The type of get(int) is erroneous where E is a type-variable."
Code:
 public boolean routeInList(Station startStation, Station endStation) {
            int i = 0;
            RouteInfo currentRoute = routeList.get(i);
            while((i < routeList.size()) && (currentRoute.getStartStation() != startStation) && (currentRoute.getEndStation() != endStation)) {
                currentRoute = routeList.get(i);
                i++;
            }
            if(i < routeList.size()) {
                return true;
            }
            else
                return false;
        }
 

Somnid

Member
Working in Java and I'm trying to find if an object is an element in a linked List with a particular attribute. I'm using the get(int index) function but I get an error that I don't understand: "The type of get(int) is erroneous where E is a type-variable."
Code:
 public boolean routeInList(Station startStation, Station endStation) {
            int i = 0;
            RouteInfo currentRoute = routeList.get(i);
            while((i < routeList.size()) && (currentRoute.getStartStation() != startStation) && (currentRoute.getEndStation() != endStation)) {
                currentRoute = routeList.get(i);
                i++;
            }
            if(i < routeList.size()) {
                return true;
            }
            else
                return false;
        }

Is your routeList a LinkedList of RouteInfo? You might also want to look into iterators for traversing the list rather than getting by index.
 

Pokemaniac

Member
Working in Java and I'm trying to find if an object is an element in a linked List with a particular attribute. I'm using the get(int index) function but I get an error that I don't understand: "The type of get(int) is erroneous where E is a type-variable."
Code:
 public boolean routeInList(Station startStation, Station endStation) {
            int i = 0;
            RouteInfo currentRoute = routeList.get(i);
            while((i < routeList.size()) && (currentRoute.getStartStation() != startStation) && (currentRoute.getEndStation() != endStation)) {
                currentRoute = routeList.get(i);
                i++;
            }
            if(i < routeList.size()) {
                return true;
            }
            else
                return false;
        }

From that specific error, I'd suspect something wonky is going on with the type parameter you're passing to the LinkedList.
 

Makai

Member
From what i gathered you can get DX12 object by querying for COM objects. I'm not really familiar with COM.
In Rust i use a crate named winapi which has FFI bindings for the windows api.

I'm just reading the example in the book "Introduction to 3D game programming with DX12" and port them to rust while i go.
That was after read the basics of the Rust language.
You inspired me to just use Vulkano - the rust wrapper for Vulkan.

Yayyy

DpjSIQN.png
 

Tater Tot

"My God... it's full of Starch!"
In what way does it not work? What output do you expect and what output do you get?

I never got around to answering your questioins heh. I was suppose to take a dollar amound as a float then convert it into an Int in order to determin which cent type to use(quarters, dimes etc) then reduce that amount and count how many coins I used in total once the amount owed reached zero.

I was having trouble with floating point conversion so I was trying to cap the decimal place at the hundreths place.

It was difficult because I do not really have much exp in C i moslty programmed in java and Assembler(the worst)

I managed to find out my soultion after many hours looking at it though lol

do{
printf("Oh Hai! How much change is owed?\n");
change = GetFloat();

}
while(change<0); {
//change = change *100;
//int cents = round(change);
cents = (int)round(change*100)

I am auditing CS50 from edX(harvard) to learn the basics at C. I would definitely recommend it to learn programming from scratch.
 

Pau

Member
Is your routeList a LinkedList of RouteInfo? You might also want to look into iterators for traversing the list rather than getting by index.
Yes, it's a LinkedList of RouteInfo. I get a similar error when traversing the list with iterators. :(

Although now I remember that for some reason NetBeans doesn't acknowledge any of the classes. So I'm guessing it's that. Haven't been able to figure out that issue, but I'm not doing any compiling and it works on my supervisor's machine so. *sigh*
 

Pokemaniac

Member
Yes, it's a LinkedList of RouteInfo. I get a similar error when traversing the list with iterators. :(

Although now I remember that for some reason NetBeans doesn't acknowledge any of the classes. So I'm guessing it's that. Haven't been able to figure out that issue, but I'm not doing any compiling and it works on my supervisor's machine so. *sigh*

Sounds like there could be one of two things wrong:
  • It's possible you're trying to use a class from another package without importing it first. In Java, if you want to reference a class in another package, you have to either fully qualify the class name, or import it at the beginning of the file (preferred).
  • If the classes were given to you in a jar, you may need to add that to the class path somehow.

At least, those are the two most likely causes I can think of for why Netbeans would behave like that.
 

ferr

Member
I'm suddenly diving into creating a compiler/transpiler after reading https://medium.com/@kosamari/how-to...piler-with-javascript-4a8a13d473b4#.ey7vctkkg Highly recommend the article, but the pros of it being high level and an easy read offer up some cons in the form of not having enough info.. maybe it's time to finally buy the dragon book.. Any other good articles or (more modern than dragon) books on the subject?

Anyway. Random thought- Anyone know if "converting" from JavaScript to a language like Golang would be considered transpiling or compiling since Go seems a bit closer to the metal.. yet it's still a human-readable high level language.
 
I'm suddenly diving into creating a compiler/transpiler after reading https://medium.com/@kosamari/how-to...piler-with-javascript-4a8a13d473b4#.ey7vctkkg Highly recommend the article, but the pros of it being high level and an easy read offer up some cons in the form of not having enough info.. maybe it's time to finally buy the dragon book.. Any other good articles or (more modern than dragon) books on the subject?

Super Tiny Compiler by James M Kyle is great beginner source similar to the article: https://github.com/thejameskyle/the-super-tiny-compiler/blob/master/super-tiny-compiler.js

Line-by-line commentary, but really well done.
 

Jokab

Member
As part of a school project I'm reviewing the open source Java project Elasticsearch for null pointer exceptions. I scanned it using SonarQube and came across this method and I'd like to ask for yall's opinion on fixing it.

Code:
    @Override
    public InternalAggregation doReduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
        List<List<InternalBucket>> bucketsList = null;
        for (InternalAggregation aggregation : aggregations) {
            InternalFilters filters = (InternalFilters) aggregation;
            if (bucketsList == null) {
                bucketsList = new ArrayList<>(filters.buckets.size());
                for (InternalBucket bucket : filters.buckets) {
                    List<InternalBucket> sameRangeList = new ArrayList<>(aggregations.size());
                    sameRangeList.add(bucket);
                    bucketsList.add(sameRangeList);
                }
            } else {
                int i = 0;
                for (InternalBucket bucket : filters.buckets) {
                    bucketsList.get(i++).add(bucket);
                }
            }
        }
        
        InternalFilters reduced = new InternalFilters(name, new ArrayList<InternalBucket>(bucketsList.size()), keyed, pipelineAggregators(), getMetaData());
        for (List<InternalBucket> sameRangeList : bucketsList) {
            reduced.buckets.add((sameRangeList.get(0)).reduce(sameRangeList, reduceContext));
        }
        return reduced;
    }

The offending line is this:
Code:
InternalFilters reduced = new InternalFilters(name, new ArrayList<InternalBucket>(bucketsList.size()), keyed, pipelineAggregators(), getMetaData());
where bucketsList can be null.

A good option would have been to simply initialize the list instead of setting it to null in the first line, but this doesn't work as there is an essential nullcheck in the logic. There are a few other options here, none of which I think seem good:
1. Set a @Nonnull annotation on the first method argument.
2. Throw an exception if the first argument is null or empty, probably not a good idea since I don't want to propagate exceptions in such a huge project where there aren't any right now.
3. Return a null object (not a good idea).
4. Ignore it? Maybe it's not even a problem? (why?)

What would you do?
 

Somnid

Member
I'm suddenly diving into creating a compiler/transpiler after reading https://medium.com/@kosamari/how-to...piler-with-javascript-4a8a13d473b4#.ey7vctkkg Highly recommend the article, but the pros of it being high level and an easy read offer up some cons in the form of not having enough info.. maybe it's time to finally buy the dragon book.. Any other good articles or (more modern than dragon) books on the subject?

Anyway. Random thought- Anyone know if "converting" from JavaScript to a language like Golang would be considered transpiling or compiling since Go seems a bit closer to the metal.. yet it's still a human-readable high level language.

http://compilers.iecc.com/crenshaw/ is pretty decent but a tad old.
 

shoreu

Member
Well it depends on your entities. You need foreign keys for relational data.

Lets say for these tables i'm doing a couple querys and probably a join or two nothing major at all but the instructions are horrible.



I've pretty much created most of the tables with primary keys and all and some composite but from the syntax i've learned I haven't seen a need.

for instance at most i've done

SELECT NAME, DNAME,
FROM DEPARTMENT, EMPLOYEE,
WHERE DNO = DNUMBER;

would i need FKeys for that to work?
 

JesseZao

Member
You wouldn't "need" FKs for that query to work, but it's bad design and would cause headaches down the road when your model becomes more complex.

Using FKs helps ensure data integrity.

Think about what would happen if you deleted a department that some other table was still assigned to or added an employee and assigned them a bogus department number. Without foreign keys, these transactions would complete without error.
 

shoreu

Member
You wouldn't "need" FKs for that query to work, but it's bad design and would cause headaches down the road when your model becomes more complex.

Using FKs helps ensure data integrity.

Think about what would happen if you deleted a department that some other table was still assigned to or added an employee and assigned them a bogus department number. Without foreign keys, these transactions would complete without error.

oh ok I understand that. Thank you. for that.
 

hateradio

The Most Dangerous Yes Man
A good option would have been to simply initialize the list instead of setting it to null in the first line, but this doesn't work as there is an essential nullcheck in the logic. There are a few other options here, none of which I think seem good:

Code:
    @Override
    public InternalAggregation doReduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
        List<List<InternalBucket>> bucketsList = null;
        for (InternalAggregation aggregation : aggregations) {

1. Set a @Nonnull annotation on the first method argument.
2. Throw an exception if the first argument is null or empty, probably not a good idea since I don't want to propagate exceptions in such a huge project where there aren't any right now.
3. Return a null object (not a good idea).
4. Ignore it? Maybe it's not even a problem? (why?)

What would you do?
That's interesting.

The easiest thing would be to check that aggregations is not null or empty. You would return an empty list, since there's nothing to reduce.
 

Koren

Member
Well it depends on your entities. You need foreign keys for relational data.
Well, you don't *need* them to de actual foreign keys but it helps avoiding issues...

for instance at most i've done

SELECT NAME, DNAME,
FROM DEPARTMENT, EMPLOYEE,
WHERE DNO = DNUMBER;

would i need FKeys for that to work?
Well, yes and no... It work without bothering to declare a FK, but by declaring either DNO or DNUMBER as foreign, you add a safety check and help people understanding the structure.

Also, FROM DEPARTMENT JOIN EMPLOYEE ON DNO=DNUMBER does the same, in terms of result, as FROM DEPARTMENT, EMPLOYEE WHERE DNO=DNUMBER, but an inner join should be far more efficient than filtering a product...
 

Zoe

Member
I'm so bad about explicitly creating the foreign key links, but my databases are full of them, maybe excessively so. I'm all for joining on ID's when possible.
 

Chris R

Member
I'm so bad about explicitly creating the foreign key links, but my databases are full of them, maybe excessively so. I'm all for joining on ID's when possible.

But when everything is designed just right and you can create your ORM in seconds and have zero issues... it's just feels so good :D
 
Question for Java folks, before my sanity gives out. I'm new to programming and have hit a brick wall when trying to code across multiple classes. Basically I want to start with just having 1 or 2 member variables for class Alpha, then building on that in class Beta by adding more member variables, then for class Gamma adding more variables (and also a collection of Beta objects), and so on, building up each time. All the classes are in the same package.

I've put the problem in the most basic code I can:

Code:
public class Alpha {
    
private String letters;

public Alpha(String letters)
{
this.letters = letters;
}
 
public String toString()
{
return letters;
}
  
public static void main(String[] args) {
        
Alpha test = new Alpha("this is a test");
        
System.out.println(test);
}
}
Output: this is a test. All fine.

Code:
public class Beta {

private String moreLetters;
private Alpha useOtherClass;
  
public Beta (String moreLetters, Alpha useOtherClass)
{
this.moreLetters = moreLetters;
this.useOtherClass = useOtherClass;
}
  
@Override //removing this override makes no difference
public String toString()
{
return moreLetters + useOtherClass;
}
          
public static void main(String[] args) {
        
Beta test = new Beta("this is a test", "this is also a test"); //this is what it doesn't like
        
System.out.println(test);
}
}

The error I get is "incompatible types; String cannot be converted to Alpha". I've seen this or a similar error message (e.g. int cannot be converted to Beta) a lot at different parts of the code when I've tried different things, but I can't figure out how to get around it, even with a shit ton of google searching/reading.

I can make the error disappear by removing Alpha useOtherClass and this.useOtherClass = useOtherClass; from the constructor in Beta, and then removing the offending "this is also a test". But I don't think that's right because I don't then think I'm adding anything from Beta to Alpha.

Not sure whether adding public Alpha(){} in Alpha and then changing line 3 of Beta to private Alpha useOtherClass = new Alpha(); is along the right lines.

Apologies if I've worded this badly or overlooked something basic. Thanks to anyone who helps out.
 
For the main method, create a Alpha object and pass it to beta. Recall, your Beta constructor is expecting a string and an Alpha object.
Code:
public static void main(String[] args)
{ 
     Beta test = new Beta("this is a test", new Alpha("this is also a test"));
     System.out.println(test);
}
 
Top Bottom