Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Personally I prefer callback over delegate in Swift for simple logical correlations, because it's pretty straight-forward and easy to understand. At the same time, some prefers delegate, since delegation is a popular pattern in other languages, such as C#.
There are some discussions I found online:
1. "Why you shouldn't use delegates in Swift?"
https://medium.cobeisfresh.com/why-you-shouldn-t-use-delegates-in-swift-7ef808a7f16b#.hqb7zrc1v
2. Apple is shifting its focus more on the callback pattern
https://www.reddit.com/r/swift/comments/2ces1q/closures_vs_delegates/
3. blocks or delegates?
http://blog.stablekernel.com/blocks-or-delegates/
After reading these discussions, I am still undecided on the preference.
I would like to know when is better to use closures and when is better to use delegates? and reasons?
Thanks!
(Opinion based answer for an opinion based question)
The questions shouldn't be which is better, it should be what's the best solution for the problem I'm trying to solve.
My simple rule: if something requires one function as it's interface, a callback is usually a good solution. If more than one function is required, especially when they're required for the basic function of an object, a Delegate is probably a better solution.
As always it depends on the specific situation, but absolute statements rarely work out in real-world usage.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Personally I prefer callback over delegate in Swift for simple logical correlations, because it's pretty straight-forward and easy to understand. At the same time, some prefers delegate, since delegation is a popular pattern in other languages, such as C#.
There are some discussions I found online:
1. "Why you shouldn't use delegates in Swift?"
https://medium.cobeisfresh.com/why-you-shouldn-t-use-delegates-in-swift-7ef808a7f16b#.hqb7zrc1v
2. Apple is shifting its focus more on the callback pattern
https://www.reddit.com/r/swift/comments/2ces1q/closures_vs_delegates/
3. blocks or delegates?
http://blog.stablekernel.com/blocks-or-delegates/
After reading these discussions, I am still undecided on the preference.
I would like to know when is better to use closures and when is better to use delegates? and reasons?
Thanks!
(Opinion based answer for an opinion based question)
The questions shouldn't be which is better, it should be what's the best solution for the problem I'm trying to solve.
My simple rule: if something requires one function as it's interface, a callback is usually a good solution. If more than one function is required, especially when they're required for the basic function of an object, a Delegate is probably a better solution.
As always it depends on the specific situation, but absolute statements rarely work out in real-world usage.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
This might not be the right place for this to ask, but I am interested in artificial neural networks and want to learn more.
How do you design a network and train it on source code so it can come up with programs for, for example, easy number theory problems?
What's the general name of this research field?
This is a hugely interesting, and very hard, problem area. It will probably take you months to read enough to even understand how to attack the problem. Here's a few things that might help you get started, and they are more to show the problems you will face than to provide solutions:
http://karpathy.github.io/2015/05/21/rnn-effectiveness/
Then read this, and related papers:
https://arxiv.org/pdf/1410.5401v2.pdf
Next, you probably want to read the classic papers in program synthesis and generation at the parse tree/AST level (mostly out of MIT, I think, in the early 90s.)
Best of luck. This is not trivial.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
So I've been wondering myself if it's better to use Recursion in Swift or the regular For Loops (iterations in general).
If so in which cases should I choose to use Recursion instead of Iterations.
I know that in some languages one is better/faster than the other, but I'm in doubt about Swift (maybe the same opinion as Objective-C).
If you can give me a solid, or close to, answer I'll be even more thankful.
Thanks in advance, and stay strong in code :)
Cheers.
- IC
This question is a bit general and has many answers already. Regardless, I would always stick with iteration when possible for readability's sake and the fact that it's more efficient than recursion. This is because we often end up solving the same math more than once in recursion. I've also worked with people who discourage the use of recursion in favor of iteration.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to build an iOS application where you can easily view and interact with geophysics data (well logs, seismic sections etc), which usually come as huge matrices in SEGY format or similar.
Is there any way I can do this with swift? Also I need to extract statistics and and perform mathematical operations. Is there any scientific use of swift at all?
Sorry if I'm being vague, it's a fairly new idea and I would love to do it on iOS instead of using C/matlab/python etc.
There's nothing native to Swift, but you could always use third party frameworks for anything.
Of course, science power of Matlab won't be achievable by iOS, since the language is not intended for that, so you'll have to write some math functions on your own.
For charts, I used CorePlot, but now there's a better alternative written completely in Swift, called ios-charts.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm just wondering, I'm new to this pattern subject, I started like couple of weeks ago but my main problem is, when I start writing small applications (for self purposes) I can't think where to put any pattern to use, maybe it's my thinking structure that needs to be tweaked ?
If I start a new project, how would I know if I need to use a pattern ? what questions do I ask myself ? what steps do I take before writing the actual code ?
Look at the Delphi VCL...it's basically took the Design Patterns and ran with them...
Forms are Composite Patterns.
Datasets use the Iterator Pattern.
Screen and Application are Singleton Patterns.
Components use lots of
different Patterns, the Chain of Responsibility, Decorator, Facade
to name a few...
Patterns are ways to organize your program and objects in lightly coupled objects that have jobs that you do over and over again...
Design patterns are just ways to approach solutions to common problems. As you internalize the patterns and as you understand the problem better you will sometimes see that the problem (or part of the problem) you are solving is addressed by a particular pattern.
That's when you use it. When you see it solving your problem.
Design patterns are reusable solutions for common problems.
The principles of Software Engineering cites the reusability of codes, when you use a design pattern you are using a concept previously tested that went trough several validations and is less prone to an design error than if you design your own model.
So first, you have to know the existing design patterns and what they're intended to solution. When you face a common problem you may remember the design patterns you previously studied and use them to solve the situation you're facing at the moment.