• 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

Two Words

Member
EDIT:

I’m actually getting similar distances when using lat/long calculators. I may be getting bad data to compare my answers to.




Anybody familiar with calculating distances with latitude/longitude in Swift? I'm playing with it here in this code, but I'm getting terrible results. I know that the distance between these two points is about 413.5 meters, but I'm getting results like 3.69 meters.

In the code, I calculate the distances directly from a to B, and then I try to calculate the distance by finding the latitude/longitude component distances and then doing the distance formulas. The component distances are important to my application. I get the same answer doing it directly from a to b and also doing the distance formula, but it is the same wrong answer.

Code:
import Foundation
import CoreLocation


let aLong = -96.75626029284595
let aLat = 32.978294210264075
let bLong = -96.75626029812727
let bLat = 32.97826092729531
let a = CLLocation(latitude: aLat, longitude: aLong)
let b = CLLocation(latitude: bLat, longitude: bLong)
let dx = CLLocation(latitude: aLat, longitude: bLong)
let dy = CLLocation(latitude: bLat, longitude: aLong)

let distx = a.distance(from: dx)
let disty = a.distance(from: dy)
let distCalc = pow(pow(distx, 2) + pow(disty, 2), 0.5)

let dist = a.distance(from: b) 

print("distx    = (distx)")
print("disty    = (disty)")
print("distCalc = (distCalc)")
print("dist     = (dist)n")
 

Koren

Member
OK, I try again.

I did the distance calculation by hand.

The distance between your two points IS 3.69m.

So the code is correct, it's your expectation that isn't.
 
In college we are learning bash command line basics and C programming. For whatever reason our lecturer insists that we learn to use vi and even wants us to program in C with it.

Anyone have any experience with vi? I'm not really used to it so have trouble with basic navigation but I'm very slowly getting used to it. I have to say I really hate it so far due to how unintuitive it is but I especially hate it for writing/editing code, just horrible for that IMO.

Do people actually use vi for writing code? If not is vi widely used for other things such as editing text files on Unix systems? etc..
 

peakish

Member
In college we are learning bash command line basics and C programming. For whatever reason our lecturer insists that we learn to use vi and even wants us to program in C with it.

Anyone have any experience with vi? I'm not really used to it so have trouble with basic navigation but I'm very slowly getting used to it. I have to say I really hate it so far due to how unintuitive it is but I especially hate it for writing/editing code, just horrible for that IMO.

Do people actually use vi for writing code? If not is vi widely used for other things such as editing text files on Unix systems? etc..
Just plain vi, not even vim (vi iMproved)? The latter seems to be reasonably popular in the Unix world and I'm not totally sure of what's in regular vi. I don't write code in vim itself anymore, but many larger editors have vim-like bindings that I use. It has some nice features that I've gotten used to, although not anything properly advanced that I think experienced programmers use it for.

As for tips, IDK, learn navigation, search and a few modal commands. Don't use your mouse to select text. Here are some useful commands.

Code:
ctrl+u/d # move up or down one half screen
I # move to the beginning of the line and enter insert mode
C # delete the rest of the line from your current position and enter insert mode
. # repeat last command, very useful if you're repeating some change many times
50% # or any other number, go to that relative position in your document
gg / G # go to the beginning and end of the document
ci( # vim only, delete all content within the closest matching parenthesis pair and enter insert mode. works with other types of matches, like square brackets (ci[), curly (ci{), citation marks (ci' / ci"), etc. Or with other modals, like d for just deleting the content or v for just selecting (di( / vi()

This starter guide seems to have some useful examples of how you can use it.

Demanding everyone to use a certain editor seems stupid, btw.
 
Just plain vi, not even vim (vi iMproved)? The latter seems to be reasonably popular in the Unix world and I'm not totally sure of what's in regular vi. I don't write code in vim itself anymore, but many larger editors have vim-like bindings that I use. It has some nice features that I've gotten used to, although not anything properly advanced that I think experienced programmers use it for.

As for tips, IDK, learn navigation, search and a few modal commands. Don't use your mouse to select text. Here are some useful commands.

Code:
ctrl+u/d # move up or down one half screen
I # move to the beginning of the line and enter insert mode
C # delete the rest of the line from your current position and enter insert mode
. # repeat last command, very useful if you're repeating some change many times
50% # or any other number, go to that relative position in your document
gg / G # go to the beginning and end of the document
ci( # vim only, delete all content within the closest matching parenthesis pair and enter insert mode. works with other types of matches, like square brackets (ci[), curly (ci{), citation marks (ci' / ci"), etc. Or with other modals, like d for just deleting the content or v for just selecting (di( / vi()

This starter guide seems to have some useful examples of how you can use it.

Demanding everyone to use a certain editor seems stupid, btw.

Thanks for the advice! I'll dive into that material and try to get used to it. Yeah as far as I know it's standard vi as that is included with every Linux distro I think.

And I agree it's stupid mandating a specific editor but the lecturer might think it's the only way to make people familiar with something as cumbersome as vi.
 

GaimeGuy

Volunteer Deputy Campaign Director, Obama for America '16
Update on my previous post http://www.neogaf.com/forum/showpost.php?p=248242607&postcount=19215

I noticed that Eclipse's parser log had some garbled text, which pointed to some binary data being caught. I noticed that our API directory had some compiled object files brought over. (Our project's compiler is on a different box). Excluding C object files fixed some, but not all, of the errors.

I wish there was a way to tell Eclipse "Hey, I want a verbose log of what the hell you're doing to parse all the symbols in this file." The normal parser log doesn't really say much of anything at all.
 

wwm0nkey

Member
Anyone here ever do a coding "bootcamp" before? Getting a job at a insurance company and they are footing the bill of a $5k 3week long bootcamp for Angular and React. Just wondering how those usually go. Going to try to learn them before the bootcamp though.
 

peakish

Member
Thanks for the advice! I'll dive into that material and try to get used to it. Yeah as far as I know it's standard vi as that is included with every Linux distro I think.

And I agree it's stupid mandating a specific editor but the lecturer might think it's the only way to make people familiar with something as cumbersome as vi.
No worries. To add to my previous post, I think I should give an even more basic tip: vi/m works by giving actual commands. When editing, think in terms of those rather than exact key sequences, because there's a logic to them that you can actually learn.

It largely works like do-this-on-that. "this" is an operator, like 'c' for 'change', 'd' for 'delete', 'v' for 'select'. "that" is an object (more specifically a movement command). So the command 'cl' means 'change the object directly to the right of the cursor' (since 'l' means move right). 'dl' means 'delete it' and 'vl' 'select it'. Very logical.

Now, here's the good part: there are many ways to specify "that". 'w' stands for 'word', so 'cw' will change the current whole word that you are on while 'dw' will delete it and 'vw' select it. 'W' means 'word, until next whitespace' ie. including commas, etc. '$' means 'move to end of line' so 'c$' changes everything until the end of the current line. Similarly, '0' means 'beginning of line'. Just knowing this structure gives you a lot of power in vi/m since you create your own commands on the fly.


Another basic note: if you select something, you can operate on it with 'c' or 'd' to change or delete it. 'V' selects entire lines. So to delete a lot of lines, use 'V' to select them and then press 'd'.


Extra vim credits: In vim there are some modifiers to some of these "this"'s which slightly change their meaning. 'a' means a, so 'aw' becomes 'a word': move the cursor back to the beginning of the word, then change it. Good, but here's the kicker: it can be used to specify certain blocks. 'a(' for example moves to the first preceeding '(' and then from there to the first matching ')'. So 'ca(' means 'change the entire current parenthesis block'. Super useful since these blocks are so common in programming. Also works for the other brackets '[' and '{', as well as quotation marks ' and ".

Addendum to this: 'i' means 'inner', so the block match excludes the parenthesis themselves, operating only on the inner content.
 

Antagon

Member
In college we are learning bash command line basics and C programming. For whatever reason our lecturer insists that we learn to use vi and even wants us to program in C with it.

Anyone have any experience with vi? I'm not really used to it so have trouble with basic navigation but I'm very slowly getting used to it. I have to say I really hate it so far due to how unintuitive it is but I especially hate it for writing/editing code, just horrible for that IMO.

Do people actually use vi for writing code? If not is vi widely used for other things such as editing text files on Unix systems? etc..

vim is really useful for editing text files in a terminal. Takes a while to get used to, but is very effective once you do. Especially composing commands. I actually use vim plugins in visual studio and intellij nowadays, though part of that was because I wanted to force myself to learn it.

If you simply want to learn the basic navigation, just enter vimtutor on the commandline. Opens vim with a tutorial textfile which is pretty decent.
No worries. To add to my previous post, I think I should give an even more basic tip: vi/m works by giving actual commands. When editing, think in terms of those rather than exact key sequences, because there's a logic to them that you can actually learn.

It largely works like do-this-on-that. "this" is an operator, like 'c' for 'change', 'd' for 'delete', 'v' for 'select'. "that" is an object (more specifically a movement command). So the command 'cl' means 'change the object directly to the right of the cursor' (since 'l' means move right). 'dl' means 'delete it' and 'vl' 'select it'. Very logical.

Now, here's the good part: there are many ways to specify "that". 'w' stands for 'word', so 'cw' will change the current whole word that you are on while 'dw' will delete it and 'vw' select it. 'W' means 'word, until next whitespace' ie. including commas, etc. '$' means 'move to end of line' so 'c$' changes everything until the end of the current line. Similarly, '0' means 'beginning of line'. Just knowing this structure gives you a lot of power in vi/m since you create your own commands on the fly.


Another basic note: if you select something, you can operate on it with 'c' or 'd' to change or delete it. 'V' selects entire lines. So to delete a lot of lines, use 'V' to select them and then press 'd'.


Extra vim credits: In vim there are some modifiers to some of these "this"'s which slightly change their meaning. 'a' means a, so 'aw' becomes 'a word': move the cursor back to the beginning of the word, then change it. Good, but here's the kicker: it can be used to specify certain blocks. 'a(' for example moves to the first preceeding '(' and then from there to the first matching ')'. So 'ca(' means 'change the entire current parenthesis block'. Super useful since these blocks are so common in programming. Also works for the other brackets '[' and '{', as well as quotation marks ' and ".

Addendum to this: 'i' means 'inner', so the block match excludes the parenthesis themselves, operating only on the inner content.

Some additions to this: use 't' to move to a character in the current line. (ie: 'tA' will move to the next 'A' character in the current line.). This can be used to quickly navigate to parts of the word. You can also use numbers in front of a character to do the command multiple times. Ie: '3tA' will move the cursor to the third " from where it's now. You can also compose this with commands like 'd' and 'c', so 'c3tA' will let you change all the text untill the third 'A' from where the cursor sits on the line. So c3w will change three words from where the cursor stands.

Another trick is that the c, d, v and y (and more?) commands will work on a whole line if you double them. Ie: dd will delete the current line. 5dd will delete 5 lines, starting at the line where the cursor sits. You can even compose functions with searches. Typing d/function for example, will delete everything from the cursor position until the text 'function'.
 

-KRS-

Member
In college we are learning bash command line basics and C programming. For whatever reason our lecturer insists that we learn to use vi and even wants us to program in C with it.

Anyone have any experience with vi? I'm not really used to it so have trouble with basic navigation but I'm very slowly getting used to it. I have to say I really hate it so far due to how unintuitive it is but I especially hate it for writing/editing code, just horrible for that IMO.

Do people actually use vi for writing code? If not is vi widely used for other things such as editing text files on Unix systems? etc..
Just tell him that Emacs is the only true editor and see what he says.
 

Koren

Member
VIM is a really good editor if that clicks, there's a lot of bindings/logic I would welcome in other editors.

I know a lot of devs that code in it...
 

barnone

Member
I work at a strictly non-WFH software dev shop, and i’m trying to find a way to convince my boss to allow work from home a few days a month. Other than no WFH, i really like this job. Anyone have any tips to help rationalize allowing some WFH?

Some reasons we disallow WFH are that it encourages email instead of quick in-person decision making, discourages togetherness/teamwork, and it inhibits our paired programming (which we do all day 8hrs/day 40hrs/wk)
 

Kalnos

Banned
I work at a strictly non-WFH software dev shop, and i’m trying to find a way to convince my boss to allow work from home a few days a month. Other than no WFH, i really like this job. Anyone have any tips to help rationalize allowing some WFH?

Some reasons we disallow WFH are that it encourages email instead of quick in-person decision making, discourages togetherness/teamwork, and it inhibits our paired programming (which we do all day 8hrs/day 40hrs/wk)

Sounds like this last one is where you're going to have a hard time IMO. I think the easiest way to argue for WFH is if the office is full of distractions (i.e. open office) and you can convince them that you can accomplish more from home.
 

barnone

Member
Sounds like this last one is where you're going to have a hard time IMO. I think the easiest way to argue for WFH is if the office is full of distractions (i.e. open office) and you can convince them that you can accomplish more from home.

While I think I could accomplish more solo, someone would have to review the code since it wasn't paired on. Pairing is normally our code review.

I think I either find tasks that are solo-able (my boss would probably say there are none) or prove remote-pairing works.

My boss told me to just take vacation days if I want to be out of the office, but while traveling I am going to have downtime where I'd like to work.

I think my options are limited, and my best shot is finding good remote pairing tools. Or find a job that allows WFH.
 

Kalnos

Banned
While I think I could accomplish more solo, someone would have to review the code since it wasn't paired on. Pairing is normally our code review.

That sounds dangerous to me. Lots of time when I pair program someone presents an idea that sounds good and it kinda becomes an echo chamber. I work remote now though and the idea of syncing schedules with another person 9-5 sounds terrifying haha
 

barnone

Member
That sounds dangerous to me. Lots of time when I pair program someone presents an idea that sounds good and it kinda becomes an echo chamber. I work remote now though and the idea of syncing schedules with another person 9-5 sounds terrifying haha

I won’t deny this happens. There was one guy who wouldn’t tolerate any ‘bad code’ and would always point it out everywhere he saw it when he rotated onto a project. But we’re encouraged to refactor as we go and we try to fix those design mistakes as we recognize them. Also we switch tech stacks super often between projects and that’s really grating.

For the most part it’s worked out. We have a lot of talent on the team and mostly pair with less skilled devs around the company to train them in TDD and scripting and full stack.

I’m thinking i’ll take the vacation and work on some OSS or learn some languages more in depth. i don’t have a specialization besides perhaps C#
 

Koren

Member
Some reasons we disallow WFH are that it encourages email instead of quick in-person decision making
That's just a lack of proper tools. I did power coding (one codes, the other review the code in real-time, as you type) with someone 800km from me.

You can do quick in-person decision making by audio + whiteboard conf)

I mean, there's Google teams that are split in different countries.
 
Thanks for the advice! I'll dive into that material and try to get used to it. Yeah as far as I know it's standard vi as that is included with every Linux distro I think.

Every distro I've used in the past decade or more has 'vi' bound to 'vim'; same also on the Mac. Just type :help and it should show you whether it is vi or vim. The latter is far more useful. It's the only thing I program in (web applications, shell scripts and the occasional C program).

The learning curve is huge. I've been productively using it for 15 years and I already learned one new thing in the replies you've received (the 't' command).

Two more tips:
% jumps to the matching brace/bracket/parenthesis
colorscheme desert is better than whatever was chosen for you by the package maintainer.
 

Koren

Member
I haven't seen a vanilla Vi for ages, I'm sure it's Vim. Kinda like nano/Pico.

But even if it's Vi, I can see why someone would want to push Vi (basically only editor available on all distros bases) but no reason would rule out Vim.
 
Yeah maybe I just need some time to get used to vi/vim. It seems weirdly unintuitive And the code we have to write is pretty simple so I find myself more figthing with the editor rather than having any difficulty with the actual C code.

I'll try to get better at it, who know maybe once I get the hang of it I'll be championing it around the web? One thing I can say is that the learning curve does seem pretty massive to become comfortable with.
 

Koren

Member
If you struggle that much, switch to edit mode and only use command mode for saving... You'll basically have a barebone editor (you can copy-paste with mouse)

Then try to learn commands when you really need those.

There's plenty of commands I like, but I'm not fond of Vim because I think they went too far. I prefer ctrl shortcuts/Fn keys for basic operations.

My ideal editor would be Scite-like with an added VIM control layer... But I never decided to handle the task.
 
One thing to keep in mind about vi/vim is that it's highly configurable. I keep a .vimrc on Dropbox so whenever I'm on a new system and have to use it more than once or twice I can quickly set it up just how I like it. You can even bind ctrl-s to esc:W:enter if it bothers you that much. I do remember the first time I started using it I kept hitting ctrl-s which you suspend the terminal from refreshing... Until I realised that's what was happening I kept thinking it had crashed :/

But yes people do use it. It was my main editor for the last 12 months as the (closed) system I was on had only gedit as an alternative. Which tbh is not much of an alternative. For the record I was writing data analytics tools, and a whole bunch of format converters, in Python.

I've also used it to edit html/PHP/CSS directly on the server from an Android tablet, and to write C code on an Amiga 500 (fun fact: vim originated as an Amiga clone of an Atari ST clone of vi!)

I personally know probably a dozen developers who don't use anything else.
 

Koren

Member
It's not just a matter of shortcuts... I usually don't develop in text terminal, so GUI editors have different approaches. I'm for example not fond of Vim folding.

But the availability is handy... Now, on a new system, I use an editor I developed myself that run on both Python and Python3k which is basically a souped-up Pico (with syntax enlightening, tabs, fractioned windows, basic CLI support, remote edition, encodings support/translations and a couple other tweaks)

Still a bit rough and sometimes buggy, but handy... it basically run everywhere. I should add more Vi commands in it.
 

balgajo

Member
Guys I will start to design some classes for messaging between a embedded device and lot of other service endpoints. I have the following requisites:

Being able to choose the underlying protocol(TCP/CUSTOM/HTTP/HTTPS)
Being able to serialize/deserialize data(XML,JSON, ...)
Being able to pack/unpack data(ZIP, ...)

We had a lot of code repetition in our project as each messaging class had their own implementation of the following flow even though a lot of steps are similar depending on packer, serializer and protocol.

DATA -> SERIALIZE -> PACK -> SEND -> RECEIVE -> UNPACK -> DESERIALIZE -> DATA -> DECISION


Do you guys know a good read as a starting point? Don't want to reinvent the wheel.
 
Cppcon was amazing today. I’ll post about Herb’s metaclass talk when I’m on desktop, but the best one of the day was “Postmodern C++”. The entire talk was given in Dr. Seuss rhyme, and was a parody on postmodernism. Have to watch it on YouTube once it’s uploaded.
 
Yeah maybe I just need some time to get used to vi/vim. It seems weirdly unintuitive And the code we have to write is pretty simple so I find myself more figthing with the editor rather than having any difficulty with the actual C code.

Using it to edit things you understand is probably a better way of learning it than also to be struggling with the language.

It is intuitive but not particularly discoverable; by which I mean that once you start learning its undiscoverable patterns, you can recombine commands without being told you can— you intuit them.
 
Having an issue.

I have a JSON object that has

file1.txt{
string: value
string: value
etc...
}

I'm trying to do a test to check if one of those strings has the expected value.

file1.txt.string == expectedvalue

only the .txt is throwing this off because of the .

How do I handle that?
 

Kalnos

Banned
Having an issue.

I have a JSON object that has

file1.txt{
string: value
string: value
etc...
}

I'm trying to do a test to check if one of those strings has the expected value.

file1.txt.string == expectedvalue

only the .txt is throwing this off because of the .

How do I handle that?

so it's:

Code:
file1.txt: {
string: value
string: value
etc...
}

as in file.txt is a key? It probably depends on the language but I think you'd do jsonvar["file.txt"].key_you_want
 

peakish

Member
Code:
Showing  29 changed files  with 3,187 additions and 2,692 deletions.
That feeling when you squash your commits of a large restructuring of your program ~~


I think I'm finally getting a grasp of when to use macros in Rust to generate boilerplate code and default implementations of methods. They suddenly went from, oh, convenient shorthand to oh shit, patterns.
 
Code:
Showing  29 changed files  with 3,187 additions and 2,692 deletions.
That feeling when you squash your commits of a large restructuring of your program ~~


I think I'm finally getting a grasp of when to use macros in Rust to generate boilerplate code and default implementations of methods. They suddenly went from, oh, convenient shorthand to oh shit, patterns.

Rust is pretty awesome. I'm pretty excited for the stuff that's planned to be finished by the end of the year (currently there's a big push to get new features implemented, see here). Especially excited for the new generics features (const generics, impl Trait as a return type) and generators (would make async/await possible).
 
So it turns out there is actually a logical explanation for my problems with vi/vim.

It turns out there was some kind of bug to do with key bindings so that when I was in insert mode if I tried to use the arrow keys to navigate I would get a random A, B, C, or D character with a newline.

Also backspace didn't delete characters while in insert mode.

This made trying to learn how to use it seem really difficult.

I just updated my version of vim from the terminal in Ubuntu and that has fixed the problem, now my key bindings work properly and I find it actually usable.

Really weird that such a bug existed in the first place but I feel much more positive about the whole thing now.

Again I appreciate the advice from everyone and I'll try to improve my skills/familiarity with vim now that I have an actual working installation.
 

Koren

Member
So it turns out there is actually a logical explanation for my problems with vi/vim.

It turns out there was some kind of bug to do with key bindings so that when I was in insert mode if I tried to use the arrow keys to navigate I would get a random A, B, C, or D character with a newline.

Also backspace didn't delete characters while in insert mode.

This made trying to learn how to use it seem really difficult.

I just updated my version of vim from the terminal in Ubuntu and that has fixed the problem, now my key bindings work properly and I find it actually usable.

Really weird that such a bug existed in the first place but I feel much more positive about the whole thing now.

Again I appreciate the advice from everyone and I'll try to improve my skills/familiarity with vim now that I have an actual working installation.
This is not a bug, this is the original behavior.

You're supposed to use h j k l to move and not thé arrows.

The reason is that arrows send special codes (backspace too) and it doesn't work well with terminals, especially over network. H j k l are reliable, and you don't need to leave the home row.

It's strange for newcomers, so they added support for arrows in most version, but that still isn't the Vi way.

I think having arrows on home row is great, so I remapped the arrows there on my keyboards (though in inverted T, not in line)
 
This is not a bug, this is the original behavior.

You're supposed to use h j k l to move and not thé arrows.

The reason is that arrows send special codes (backspace too) and it doesn't work well with terminals, especially over network. H j k l are reliable, and you don't need to leave the home row.

It's strange for newcomers, so they added support for arrows in most version, but that still isn't the Vi way.

I think having arrows on home row is great, so I remapped the arrows there on my keyboards (though in inverted T, not in line)

Ah I see, that makes a bit more sense. I was really confused at first and when I checked with other people in college they didn't get the behavior I did. When I looked online some people said it was a bug with the key bindings.

On the off chance I decided to update vim from the terminal and that seemed to fix it. But intended behavior is designed with h j k l in mind? Interesting, at least I have some context for it now. I had no idea why the arrow keys/backspace were causing such strange behavior.
 

Koren

Member
I had no idea why the arrow keys/backspace were causing such strange behavior.
It's not strange, it's expected. I get those on a regular basis with all king of cli apps.

You have to understand how things are transmitted on PC. ASCII is an encoding for transmissions, there's nothing to handle edition (you can check it's missing from the tables)

Thus when a computer has to transmit those to a terminal app, it has to be clever.

Arrows are transmitted by the sequence opened by escape_char, followed by [ and closed by a letter from A to D (depending on the direction)

In fact, in some cases, you can produce cursor movements by typing those quickly.

The same kind of escape codes are used to send colours (look at .bashrc prompt customization!), try a coloured shell in a console without colour support, it'll be unreadable.

Vi doesn't interpret those sequences by default, so you just get those characters in the file, which is the expected behaviour.

Now, I'm not a Vi guru, but I think that in most cases, they make arrows working just by adding a macro in config files: a esc_code-[-A sequence is just translated into esc-h-a

So it's normal mode (esc) then move left (h) then back into edit mode.

It's a trick, really. You could have solved your problem with your original Vi by editing macros. The update may just have a different default configuration.

It's the same for backspace, ^h is translated into a sequence that Vi understand.

That's the kind of trick that make Vi really reliable (most cli editors will have trouble with arrow encoding when transmitted, and you have no easy way to handle the issue)


Edit : btw, one thing I hate about Vi is that it's designed with qwerty in mind. Some things break when you use a different layout, especially the idea behind the arrow cluster. It's annoying, especially when you think that j and k will definitively move with any remotely decent layout. Not sure there was a good solution, but it'll stay half a hack.
 
Anyone use WPF before? I am trying to implement a traditional Windows File explorer with that delayed second click that allows you to edit Folder names in-line. I am using TextBlocks for my TreeView but having a hard time with it.
 

smisk

Member
Hopefully this is an OK place to ask, I have a CE bachelors and have been working at a defense contractor for 3 years. It's more of a support role and a lot of my knowledge has become specialized towards this system, doing installs, support, bug tracking, scheduling etc. I do mostly bash stuff, and occasionally get to touch Java.
I feel like I'm moving towards a role where I'm spending more and more time doing non-technical work to help the project move forward which while important I don't really enjoy.
I'd like to move to a job that does more development in the next year or so, but feel like my programming skills are pretty rusty.
 

Kickz

Member
Anyone here ever do a coding "bootcamp" before? Getting a job at a insurance company and they are footing the bill of a $5k 3week long bootcamp for Angular and React. Just wondering how those usually go. Going to try to learn them before the bootcamp though.

I did a 3 month one back in summer 2015 when I changed careers from Network Engineering to Software Engineering. The one I did was 9 to 5 everyday plus after class tutoring. How they go, depends entirely on who's teaching and the quality of the program/ its accreditation/reviews, etc.
 
This concatenation for a file path is being more trouble than I want to admit. I basically want to build a path like file explorer, with nested folders represented.

My method (in C#) looks like

Code:
private string BuildFullPath(List<Project> Children)
        {
            string path = string.Empty;
            foreach(Project project in Children)
            {
                if (this.ParentFolder == null)
                {
                    path = this.Name;
                }
                else 
                {
                    path += this.ParentFolder.Name + " > " + this.Name;
                }
            }
            return path;
        }

My structure is something like:

Code:
  Projects = new ObservableCollection<Project>();
            Project parentOne = new Project("Apple", true, null);
            Project parentTwo = new Project("Samsung", true, null);
            Project parentThree = new Project("Google", true, null);
            Project parentFour = new Project("Amazon", true, null);

            Project parentOneChildOne;
            parentOneChildOne = new Project("Mac", true, parentOne);
            Project parentOneChildTwo;
            parentOneChildTwo = new Project("iPhone", true, parentOne);
            Project parentOneChildThree;
            parentOneChildThree = new Project("iPad", true, parentOne);
            parentOne.Children.Add(parentOneChildOne);
            parentOneChildOne.Children.Add(new Project("MacBook", true, parentOneChildOne));
            parentOneChildOne.Children.Add(new Project("MacBook Pro", true, parentOneChildOne));
            parentOneChildOne.Children.Add(new Project("MacBook Air", true, parentOneChildOne));
            projects.Add(parentOne);

It's messy, the data, but the data doesn't matter. So here, Apple -> Mac and Mac - > MacBook -> MacBook Pro..The path for MacBook Pro should be Apple -> Mac -> MacBook -> MacBookPro but I can't seem to get it. Any idea?
Is BuildFullPath a member function of Project? Why are you passing it a list of children?

Maybe you want something like this?

Code:
class Project
{
  string name;
  Project parent;

  string Path()
  {
    if (parent == null)
    {
      return name;
    }
    else
    {
      return parent.Path() + " > " + name;
    }
  }
}
 

Lister

Banned
Anyone use WPF before? I am trying to implement a traditional Windows File explorer with that delayed second click that allows you to edit Folder names in-line. I am using TextBlocks for my TreeView but having a hard time with it.

It's been a while.... and I just noticed you figured it out.

WPF is a horible mess though, I would consider using something like Electron if you know js/node for desktop development, or better, if you want ot leverage .NET maybe something like positron.
 

1upsuper

Member
Hey, I've got a question I was hoping I could get some help with. I'm new to programming and I'm taking an intro CS class in Python 3.6.

I'm having trouble understanding the difference between the following two scenarios.

Code:
def f(a,b):
    sumab = a+b
    c = c + sumab

c = 1
f(1,10)

The above produces an unbound local variable error at c = c + sumab. If I instead wrote c = sumab that would be fine, as would d = c + sumab, because the latter would look in the parent frame for c. But from my understanding , doing c = c + sumab makes python think the c on the right of the = is supposed to refer to a c in the local frame which isn't defined yet, and so it gives me an error. To fix it I could add the line "nonlocal c."

My question now is why the following works:

Code:
def countup():
    count = [0]
    def resolve(request):
        if request == "up":
            count[0] = count[0]+1
        elif request == "down":
            count[0] = count[0]-1
        elif request == "currentvalue":
            return count
    return resolve

a = countup()
a("up")

Why is Python cool with me referring to the first value in the list "count" on both sides of the = in the conditionals even though the list "count" is defined in its parent frame, when it has trouble in the previous code doing something similar? I feel like I'm overlooking something really obvious but this was one of those things I thought I understood until I thought about it more.
 

phisheep

NeoGAF's Chief Barrister
My question now is why the following works:

Code:
def countup():
    count = [0]
    def resolve(request):
        if request == "up":
            count[0] = count[0]+1
        elif request == "down":
            count[0] = count[0]-1
        elif request == "currentvalue":
            return count
    return resolve

a = countup()
a("up")

Why is Python cool with me referring to the first value in the list "count" on both sides of the = in the conditionals even though the list "count" is defined in its parent frame, when it has trouble in the previous code doing something similar? I feel like I'm overlooking something really obvious but this was one of those things I thought I understood until I thought about it more.

Does it work? Or does it just not give an error?

Might be because it is never getting to the assignment statements. All this does is return the function resolve, it never executes it.
 

1upsuper

Member
Does it work? Or does it just not give an error?

Might be because it is never getting to the assignment statements. All this does is return the function resolve, it never executes it.

It actually does work. I can add, say,

example = countup()
example("up")
example("up")
example("up")
example("currentvalue")

and get [3] returned for example("currentvalue").
 

phisheep

NeoGAF's Chief Barrister
Hmmm. Interesting. I'll have a play this evening if nobody's answered it by then. Bit rusty on Python as I accidentally dived into Haskell.
 
Top Bottom