- Existem diversas discussões sobre qual deve ser o tamanho de uma função.
- Mas algo mais importante é se perguntar: "Quando devemos envolver um código na sua própria função?"
- Algumas pessoas se guiam por:
- tamanho - uma função não deve ser tão grande que não caiba na tela
- reuso - qualquer código utilizado mais de uma vez deve ser colocado em uma função, caso contrário, deve ser deixado inline
- Uma abordagem interessante é separação entre intenção e implementação.
- Se você tiver que se esforçar ao olhar um fragmento de código para entender o que ele faz, o código deve ser extraído para um função e a função nomeada.
- Quando você ler o código novamente, o propósito da função ficará explícito sem a necessidade de entender o seu funcionamento internamente.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compiled source # | |
################### | |
*.com | |
*.class | |
*.dll | |
*.exe | |
*.o | |
*.so | |
# Packages # |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Rx = require('rxjs'); | |
var firebase = require('firebase'); | |
firebase.initializeApp({ | |
"databaseURL": "https://quiver-two.firebaseio.com", | |
"serviceAccount": "./service-account.json" | |
}); | |
var ref = firebase.database().ref('rxjs-demo'); | |
Rx.Observable.fromPromise(ref.remove()) | |
.map(function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.simpletablayout; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.support.design.widget.TabLayout; | |
import android.support.v4.app.Fragment; | |
import android.support.v4.app.FragmentManager; | |
import android.support.v4.app.FragmentPagerAdapter; | |
import android.support.v4.view.ViewPager; | |
import android.support.v7.app.AppCompatActivity; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface CustomItemClickListener { | |
public void onItemClick(View v, int position); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.sunshine.app; | |
import android.support.v4.app.Fragment; | |
import android.support.v4.app.LoaderManager; | |
import android.support.v4.content.CursorLoader; | |
import android.support.v4.content.Loader; | |
public class ForecastFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HelperUtil { | |
public static HelperUtilBase getInstance(Context context) { | |
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { | |
return new HelperUtilL(context); | |
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { | |
return new HelperUtilKK(context); | |
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | |
return new HelperUtilJB(context); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HelperUtil { | |
private final HelperUtilImpl mImpl; | |
public HelperUtil (Context context) { | |
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { | |
mImpl = new HelperUtilImplL(context); | |
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { | |
mImpl = new HelperUtilImplKK(context); |
You can use this class to realize a simple sectioned grid RecyclerView.Adapter
without changing your code.
The RecyclerView
has to use a GridLayoutManager
.
This is a porting of the class SimpleSectionedListAdapter
provided by Google
If you are looking for a sectioned list RecyclerView.Adapter
you can take a look here
OlderNewer